我正在使用python-telegram-api写电报机器人群组管理员,我希望我的机器人以群组的形式回复邮件 like this,但我唯一能得到的类似东西是this。有没有办法像第一张图片一样回复邮件?
from telegram.ext import (Updater, CommandHandler, MessageHandler,
Filters, ConversationHandler)
import telegram
import logging
telegram_token = "BOT TOKEN"
updater = Updater(token=telegram_token, use_context=True);
dispatcher = updater.dispatcher;
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %
(message)s', level=logging.INFO);
def mesgs_hand(update, context):
if(update.message.text == "Hi"):
context.bot.forward_message(chat_id=update.effective_chat.id,
from_chat_id=update.effective_chat.id,
message_id=update.message.message_id, text="Hey there!");
#this method forwards the message but without adding 'Hey there!'
elif(update.message.text == "Hello"):
context.bot.send_message(chat_id=update.message.chat_id, text="Hello!");
#this method just replies to the message without forwarding
messages_handler = MessageHandler(Filters.text, mesgs_hand)
dispatcher.add_handler(messages_handler)
def bot():
updater.start_polling();
if __name__ == "__main__":
bot();
答案 0 :(得分:1)
您可以在reply_to_message_id
函数中使用send_message
参数:
def mesgs_hand(update, context):
if(update.message.text == "Hi"):
context.bot.send_message(
chat_id=update.message.chat_id,
reply_to_message_id=update.message.message_id,
text="Hey there!")