python - 转发消息机器人电报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=?)
我需要转发用户共享消息的消息,并且必须将回复发送到组。
怎么可能?
解决方案
来自文档:
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)
推荐阅读
- r - 调整单选按钮和滑块后如何刷新绘图?
- c# - 您如何在 xunit 中看到来自控制器的错误
- microsoft-graph-api - 如何在 OpenAPI 中指定将用户添加到组?
- reactjs - 我应该在 useCallback 的依赖数组中包含 setState 吗?
- winapi - 有没有一种简单的方法来获取用于擦除窗口背景的画笔的 RGB?
- intern - 从 Grunt 运行时,如何设置 Intern 的内存大小?
- javascript - javascript image base64 和 php image base64_encode 是不同的
- php - 无法通过传递的输入深度扩展 Laravel Artisan Command
- javascript - 在图表中显示 xrange x 和 x2 值
- python - 如何根据三列从 DataFrame 中提取?