![]() ![]() ![]() Now all we need is to assign these handlers to notifications and start searching for updates. # Command processing def startCommand(bot, update): bot.send_message(chat_id=_id, text='Hello, do you want to talk?') def textMessage(bot, update): response = 'Got youre message: ' + bot.send_message(chat_id=_id, text=response) Bot contains the necessary methods for interacting with the API, and update contains information about the incoming message. Two parameters are passed there as arguments: bot and update. Let’s write two such functions for the / start command and for any plain text message. These are callback functions that will be called when the update is received. Let’s import the necessary modules and register our API token: # Settings from telegram.ext import Updater, CommandHandler, MessageHandler, Filters updater = Updater(token='YOURE API TOKEN') # Telegram API Token dispatcher = updater.dispatcher Pip install python-telegram-bot - upgradeĪfter the installation, we can already write the “basics”, which for now will simply respond with the same type of messages. Open the console and go to the directory with the file, install python-telegram-bot. ![]() Let’s write the basics of our botĬreate a folder named “Bot”, in which then create the bot.py file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |