【发布时间】:2021-03-01 21:50:34
【问题描述】:
我正在使用 Telepot 在 Python 中构建一个机器人。我可以让它响应命令,但是当我实现内联键盘时,我不知道如何调用它们。我知道它必须是回调查询,但我找不到如何实现它。 任何帮助将不胜感激。
import sys
import time
import telepot
from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print('Chat Message:', content_type, chat_type, chat_id)
if content_type == 'text':
if msg['text'] == '/start':
bot.sendMessage(chat_id, 'Welcome to @UK_Cali Teleshop\n Created by JonSnow 2021',reply_markup = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Feedback",callback_data='a'), InlineKeyboardButton(text="You",callback_data='b'),InlineKeyboardButton(text="PGP",callback_data='c'), InlineKeyboardButton(text="Cunt",callback_data='d')],
[InlineKeyboardButton(text="Products",callback_data='e')]
]
))
bot.answerCallbackQuery(callback_query_id)
bot = telepot.Bot('1646167995:AAGsOwfjcryYYkoah69QJ6XGA7koUywmuRk')
print('Listening ...')
bot.message_loop({'chat': on_chat_message}, run_forever=True)
bot = telepot.Bot('TOKEN')
【问题讨论】:
-
看看here
-
我已经通读了几遍
-
它有你问题的所有答案
-
在这种情况下,我是一个新手,现在可以理解它。你知道我可能正在阅读的任何内容吗?我永远不会声称自己在 python 方面有经验,更不用说 Telepot