Skip to content

Instantly share code, notes, and snippets.

@kaecy
Created December 5, 2020 11:42
Show Gist options
  • Save kaecy/cb2dc3c13914890f03e0c3d00165ffaf to your computer and use it in GitHub Desktop.
Save kaecy/cb2dc3c13914890f03e0c3d00165ffaf to your computer and use it in GitHub Desktop.
# A Basic Bot - ReplyBot
# Replies with "Welcome <your name>!" when you send her the command /hello.
from TelegramBotFramework import Bot
# Bot token.
bot = Bot("put your bot token here")
# Methods that beginning with __cmd__ are command callbacks. The bot picks them up automatically.
# When your bot receives a commands they land in these callbacks.
# The part after __cmd__ is the command name.
def __cmd__hello(message, chat, extras):
chat.sendMessage("Welcome, " + extras['sender'] + "!")
# Manually add a callback.
def callback(message, chat, extras):
# The command string, the first part of a command is removed and stored in
# extras. In the case of messages with just command strings the message
# variable is an empty string.
if extras['commandStr'] == "/do_something":
chat.sendMessage("Hello, " + extras['sender'] + ".")
# "on" is used to respond to messages that match a string or regex string.
bot.on('^/do_something', callback)
# Start the bot.
bot.start(globals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment