Skip to content

Instantly share code, notes, and snippets.

@MarcoBuster
Created August 2, 2019 19:20
Show Gist options
  • Save MarcoBuster/8f9e7661006436af39c797f02a3d48cc to your computer and use it in GitHub Desktop.
Save MarcoBuster/8f9e7661006436af39c797f02a3d48cc to your computer and use it in GitHub Desktop.
Small example for botogram "normal" keyboards
import botogram
import json
bot = botogram.create(...)
@bot.command("start")
def start_command(chat, message):
bot.api.call('sendMessage', {
'chat_id': chat.id,
'text': 'Welcome in the bot! What do you want to do?',
'reply_markup': json.dumps({
'keyboard': [
[
{'text': 'Action A'},
{'text': 'Action B'},
],
[
{
'text': 'Send location',
'request_location': True,
},
{
'text': 'Share your phone number',
'request_contact': True,
},
],
],
# These 3 parameters below are optional
# See https://core.telegram.org/bots/api#replykeyboardmarkup
'resize_keyboard': True,
'one_time_keyboard': True,
'selective': True,
}),
})
@bot.message_matches('Action A')
def action_a_clicked(chat):
chat.send('Processing Action A... This won\'t trigger @bot.process_message')
@bot.process_message
def button_messages_are_like_normal_messages(chat, message):
if message.text:
chat.send('You choose %s' % message.text)
elif message.location:
chat.send('You choose to send your location: %s %s' % (message.location.latitude, message.location.longitude))
elif message.contact:
chat.send('You choose to send your contact: %s' % message.contact.phone_number)
chat.send('Press /remove to remove the annoying keyboard')
@bot.command("remove")
def remove_keyboard_command(chat, message):
bot.api.call('sendMessage', {
'chat_id': chat.id,
'reply_to_message': message.id,
'text': 'This message removes the keyboard',
'reply_markup': json.dumps({
'remove_keyboard': True,
# This 1 parameter below is optional
# See https://core.telegram.org/bots/api#replykeyboardremove
'selective': True,
})
})
if __name__ == '__main__':
bot.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment