python-3.x - 如何在使用 python 的电报 bot api 中使用 ForceReply?
问题描述
我希望我的机器人向用户发送图像,而用户只需回复该特定图像。并将他的回复作为字符串存储在变量中。所以使用sendPhoto
的方法以及一个名为 files 的字典,其中包括photo
具有图像 URL 和reply_markup
我设置为 ForceReply 的属性。一切都很好,但我无法看到强制回复。在我(机器人)发送图像后,我无法得到用户回复的内容。
files = {'photo': open("/home/preetham/Downloads/selenium/cap.jpg", 'rb'),
'reply_markup':'ForceReply'}
status = requests.post("https://api.telegram.org/[MY BOT API HERE]/sendPhoto?chat_id=" + UserID, files=files)
上面的代码能够发送图像但不能强制回复。当用户在收到这张照片后键入回复时,如果我尝试抓取他回复的消息,我总是会收到上一条消息,但不会收到最近的消息,我使用了以下代码。
while True:
try:
js = requests.post("https://api.telegram.org/[MY BOT API HERE/getUpdates").json()
reply = js['result'][-1]['message']['text']
if len(reply) > 0:
print('Reply received')
break
else:
continue
except:
continue
如何对我发送的照片应用强制回复?我怎样才能得到那张照片的回复?
解决方案
推荐阅读
- oauth-2.0 - 谷歌云函数 REST API 身份验证
- laravel - Laravel Demo vs Live Application Site---> 从一个到另一个访问模型
- docker-compose - Docker-stack - 始终从 hub.docker.com 获取图像
- excel - 如何在列中找到相同的数据并填充颜色以显示它们?
- javascript - highcharts-angular 不渲染图表
- css - CSS 关键字被认为是“实验性的”是什么意思?
- apache-kafka - kafka_exporter 不向 prometheus 发送指标
- jquery - 如何在获取th:text中的值的同时使用jQuery增加thymeleaf标签
- regex - 如果文件存在,则使用正则表达式提取 json 日志中的字段
- ansible - 使用多个“-i”运行 ansible-playbook 时忽略第一个清单文件