Chatterbot Flask Telegram Code Example
Example: telegram chat bot using flask import re from flask import Flask , request import telegram from telebot . credentials import bot_token , bot_user_name , URL global bot global TOKEN TOKEN = bot_token bot = telegram . Bot ( token = TOKEN ) app = Flask ( __name__ ) @app . route ( '/{}' . format ( TOKEN ) , methods = [ 'POST' ] ) def respond ( ) : # retrieve the message in JSON and then transform it to Telegram object update = telegram . Update . de_json ( request . get_json ( force = True ) , bot ) chat_id = update . message . chat . id msg_id = update . message . message_id # Telegram understands UTF-8, so encode text for unicode compatibility text = update . message . text . encode ( 'utf-8' ) . decode ( ) # for debugging purposes only print ( "got text message :" , text ) # the first time you chat with the bot AKA the welcoming message if text == "/start" : ...