Created
March 8, 2021 19:57
-
-
Save samirsaci/c8ba91ce244824ff538c05adfe6e6e30 to your computer and use it in GitHub Desktop.
Telegram Bot - Main Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
'''Start Bot''' | |
# Launch Updater | |
updater = Updater("{}".format(TOKEN), use_context=True) | |
# Get the dispatcher to register handlers | |
dispatcher = updater.dispatcher | |
# conversions handled by command | |
dispatcher.add_handler(CommandHandler("start", start)) | |
# conversation handler | |
loc_handler = ConversationHandler( | |
entry_points = [CommandHandler('start_tracking', start_tracking)], | |
states = { | |
LOC: [ | |
MessageHandler(Filters.location, location)], | |
PHOTO: [ | |
MessageHandler(Filters.photo, photo)], | |
DN:[MessageHandler(Filters.text & ~Filters.command, delivery_number)] | |
}, | |
fallbacks = [CommandHandler('cancel', cancel)] | |
) | |
dispatcher.add_handler(loc_handler) | |
# log all errors | |
dispatcher.add_error_handler(error) | |
# Start the Bot | |
updater.start_webhook(listen="0.0.0.0", | |
port=PORT, | |
url_path="{}".format(TOKEN)) | |
# updater.bot.set_webhook(url=settings.WEBHOOK_URL) | |
updater.bot.set_webhook("{}".format(APP_NAME) + "{}".format(TOKEN)) | |
# start_polling() is non-blocking and will stop the bot gracefully. | |
updater.start_polling() | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment