当用户在我的机器人中按下开始时,python电报如何使用嵌入式键盘发送gif?

时间:2019-03-21 16:12:40

标签: python telegram telegram-bot

from telegram.ext import Updater
from telegram.ext import CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup

def start(bot, update):
  update.message.reply_text(main_menu_message(),
                            reply_markup=main_menu_keyboard())

def main_menu(bot, update):
  query = update.callback_query
  bot.edit_message_text(chat_id=query.message.chat_id,
                        message_id=query.message.message_id,
                        text=main_menu_message(),
                        reply_markup=main_menu_keyboard())

def first_menu(bot, update):
  query = update.callback_query
  bot.edit_message_text(chat_id=query.message.chat_id,
                        message_id=query.message.message_id,
                        text=first_menu_message(),
                        reply_markup=first_menu_keyboard())



def first_submenu(bot, update):
  pass

def second_submenu(bot, update):
  pass

def main_menu_keyboard():
  keyboard = [[InlineKeyboardButton('Option 1', callback_data='m1')],
              [InlineKeyboardButton('Option 2', callback_data='m2')],
              [InlineKeyboardButton('Option 3', callback_data='m3')],
              [InlineKeyboardButton('Option 4', callback_data='m4')],
              [InlineKeyboardButton('Option 5', callback_data='m5')],
              [InlineKeyboardButton('Option 6', callback_data='m6')],
              [InlineKeyboardButton('Option 7', callback_data='m7')],
              [InlineKeyboardButton('Option 8', callback_data='m8')]]
  return InlineKeyboardMarkup(keyboard)

def first_menu_keyboard():
  keyboard = [[InlineKeyboardButton('"\U0001F602"', callback_data='m1_1', url='https://google.com')],
              [InlineKeyboardButton('Submenu 1-2', callback_data='m1_2')],
              [InlineKeyboardButton('Main menu', callback_data='main')]]
  return InlineKeyboardMarkup(keyboard)

def second_menu_keyboard():
  keyboard = [[InlineKeyboardButton('Submenu 2-1', callback_data='m2_1')],
              [InlineKeyboardButton('Submenu 2-2', callback_data='m2_2')],
              [InlineKeyboardButton('Main menu', callback_data='main')]]
  return InlineKeyboardMarkup(keyboard)


def main_menu_message():
  return 'wow'

def first_menu_message():
  return 'Choose the submenu in first menu:'



updater = Updater('asdasdasdasd')

updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(main_menu, pattern='main'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_menu, pattern='m1'))
updater.dispatcher.add_handler(CallbackQueryHandler(second_menu, pattern='m2'))
updater.dispatcher.add_handler(CallbackQueryHandler(third_menu, pattern='m3'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_submenu, pattern='m1_1'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_submenu, pattern='m1_2'))
updater.dispatcher.add_handler(CallbackQueryHandler(second_submenu, pattern='m2_1'))
updater.dispatcher.add_handler(CallbackQueryHandler(second_submenu, pattern='m2_2'))
updater.dispatcher.add_handler(CallbackQueryHandler(third_submenu, pattern='m3_1'))
updater.dispatcher.add_handler(CallbackQueryHandler(third_submenu, pattern='m3_2'))

updater.start_polling()

我所需要的只是当我在机器人中按下启动键以使用gif进行回答时, 欢迎文本和主菜单键盘。

我尝试仅插入链接,但未成功

我了解您可以使用“发送文档”或“发送gif”选项,并添加一个消息收发器和嵌入式键盘。似乎无法理解该怎么做

一个很好的例子,谢谢

0 个答案:

没有答案