首页 > 解决方案 > 转发消息机器人电报python

问题描述

我使用 python-telegram-bot 并且我不明白如何将用户的消息转发到电报组,我有这样的事情:

def feed(bot, update):
  bot.send_message(chat_id=update.message.chat_id, text="reply this message"
  bot.forward_message(chat_id="telegram group", from_chat_id="username bot", message_id=?)

我需要转发用户共享消息的消息,并且必须将回复发送到组。

怎么可能?

标签: pythonbotstelegram

解决方案


来自文档
chat_id - 目标聊天的唯一标识符 ...
from_chat_id -发送原始消息的聊天的唯一标识符...
message_id - 在 from_chat_id 中指定的聊天中的消息标识符。

解决方案:

def feed(bot, update):
    # send reply to the user
    bot.send_message(chat_id=update.message.chat_id,
                     text='reply this message')
    # forward user message to group
    # note: group ID with the negative sign
    bot.forward_message(chat_id='-1010101001010',
                        from_chat_id=update.message.chat_id,
                        message_id=update.message.message_id)

推荐阅读