Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created March 8, 2021 19:57
Show Gist options
  • Save samirsaci/c8ba91ce244824ff538c05adfe6e6e30 to your computer and use it in GitHub Desktop.
Save samirsaci/c8ba91ce244824ff538c05adfe6e6e30 to your computer and use it in GitHub Desktop.
Telegram Bot - Main Function
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