def index(): req = request.get_json() bot = TelegramBot() bot.parse_webhook_data(req) success = bot.action() return jsonify(success=success ) # TODO: Success should reflect the success of the reply
def index(): req = request.get_json() print(json.dumps(req)) bot = TelegramBot() bot.parse_webhook_data(req) success = bot.action() return jsonify(success=success) # TODO: Success should reflect the success of the reply it is important else it will continue to send up message
def index(): req = request.get_json() #storing the data recieved by telegram server bot = TelegramBot() #creating object of telegramBot class bot.parse_webhook_data( req) #parsing the json data recieved by telegram server success = bot.action() #basic reply actions #if message recieved from user who is in chat with stranger if pairs.get(bot.chat_id): #if chat mesasge is leave if bot.incoming_message_text == "/leave": #alerting users with chat ending message. bot.send_msg(pairs.get(bot.chat_id), "Stranger left the chat.") bot.send_msg(bot.chat_id, "You left the chat.") #removing both users from the paired chat_id's x = pairs.get(bot.chat_id) del pairs[x] del pairs[bot.chat_id] else: #if it was just normal message then forward to the stranger who is in chat with the user bot.forward_message(pairs.get(bot.chat_id)) #else else: #if user requests to search if bot.incoming_message_text == '/search' and bot.chat_id not in queue: bot.send_msg(bot.chat_id, "Searching....") #add user to searching queue queue.append(bot.chat_id) print("queue=", queue) #if queue has 2 users then match their pair. if (len(queue) == 2): pairs[queue[0]] = queue[1] pairs[queue[1]] = queue[0] bot.send_msg( queue[0], "Search found,you can now start chatting with stranger.\nSharing of files and images is not allowed.\nThis is just chat.\nuse /leave to leave chat." ) bot.send_msg( queue[1], "Search found,you can now start chatting with stranger.\nSharing of files and images is not allowed.\nThis is just chat.\nuse /leave to leave chat." ) queue.clear() print(pairs) return jsonify(success=success ) # TODO: Success should reflect the success of the reply
def index(): req = request.get_json() bot = TelegramBot() bot.parse_webhook_data(req) success=bot.action() return jsonify(success=success)