Skip to content

Instantly share code, notes, and snippets.

@trialan
Created May 21, 2022 11:12
Show Gist options
  • Save trialan/d1de59baaec1c9365c14601fe22bb471 to your computer and use it in GitHub Desktop.
Save trialan/d1de59baaec1c9365c14601fe22bb471 to your computer and use it in GitHub Desktop.
from telegram.ext.callbackcontext import CallbackContext
from telegram.ext.commandhandler import CommandHandler
from telegram.ext.filters import Filters
from telegram.ext.messagehandler import MessageHandler
from telegram.ext.updater import Updater
from telegram.update import Update
BOT_KEY = "<YOUR_BOT_TOKEN_HERE>"
def start(update: Update, context: CallbackContext):
welcome_message = "Welcome to this bot!"
update.message.reply_text(welcome_message, parse_mode="html")
def uid(update: Update, context: CallbackContext):
uid = update.message.chat.username
update.message.reply_text(f"Your uid is {uid}", parse_mode="html")
def unknown_text(update: Update, context: CallbackContext):
update.message.reply_text(f"If you need support please contact [email protected].")
def _add_handlers(updater):
updater.dispatcher.add_handler(CommandHandler("start", start))
updater.dispatcher.add_handler(CommandHandler("uid", uid))
updater.dispatcher.add_handler(MessageHandler(Filters.text, unknown_text))
if __name__ == "__main__":
updater = Updater(BOT_KEY, use_context=True)
_add_handlers(updater)
print("starting to poll...")
updater.start_polling()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment