Here is my code:
from telegram.ext import *
updater=Updater(token="")
dis = updater.dispatcher
def echo(update, context):
context.bot.send_message(chat_id = update.message.chat_id, text = update.message.txt)
dis.add_handler(MessageHandler(Filters.text,echo))
def main():
updater.start_polling()
updater.idle()
if __name__=="__main__":
main()
How is the echo function called and how are the arguments sent to the function. Which arguments are actually sent?
MessageHandler(Filters.text, echo)
saves a saves a reference to the echo
function in the MessageHandler
object, and dis.add_handler()
registers this handler in the updater.dispatcher
object. The Telegram module calls the function automatically when appropriate, passing the update
and context
arguments.
This is an example of a callback function .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.