【发布时间】:2021-11-09 09:50:56
【问题描述】:
我必须制作一个机器人,它将在组中发布消息和 InlineKeyboardButton,组成员将响应这些 InlineKeyboardButton。因此,在回调查询中,我向他们显示了一条警报消息,
现在我想向每个响应者直接发送私人消息到他们的收件箱,而不是在组中。
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
def start(update: Update, context: CallbackContext) -> None:
"""Sends a message with three inline buttons attached."""
keyboard = [
[InlineKeyboardButton("opt_a", callback_data='A')],
[InlineKeyboardButton("opt_b", callback_data='B')],
[InlineKeyboardButton("opt_c", callback_data='C')],
]
reply_markup = InlineKeyboardMarkup(keyboard, resize_keyboard=False)
update.message.reply_text("Question: Please Select an Option", reply_markup=reply_markup)
def button(update: Update, context: CallbackContext) -> None:
"""Parses the CallbackQuery and show the alert."""
query = update.callback_query
query.answer(text=f"Thanks for responding", show_alert=True)
#############################################################
Chat_id = query.message.chat.id
我需要做的是在下面的代码行中
# Send_Private_Message(chat_id=Chat_id, message_text = "Text of the message will b here...")
现在我想在这里给回复的用户发送一条私人消息 要内联键盘,我在上面的变量“Chat_id”中得到了他的聊天 ID, 但无法找到通过他的“Chat_id”向该人发送私人消息的方法
updater = Updater("TOKEN")
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
# Start the Bot
updater.start_polling()
# Bot in Idle Position
updater.idle()
【问题讨论】:
标签: python-3.x telegram telegram-bot message python-telegram-bot