我希望解析执行Telegram API调用得到的JSON响应:https://api.telegram.org/bot<token>/getUpdates
根据该响应,我希望将所有chat_IDs存储在某个地方。我想循环通过所有这些I,通过机器人发送消息到每个群聊中。
import requests
def telegram_bot_sendtext(bot_message):
bot_token = ''
bot_chatID = ''
bot_message = ''
get_updates = 'https://api.telegram.org/bot' + bot_chatID + '/getUpdates'
response = requests.get(get_updates)
final = json.loads(response.text)
Dict = {final['result']['update_id']}
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()我知道我没有根据响应正确地创建这个字典。如何正确创建这个字典或数组,然后遍历对象以发送每个组中bot_message?
发布于 2020-04-14 10:51:11
result是一个对象数组,您可以使用这种代码遍历它
Dict = final['result']
for obj in Dict:
print(obj['update_id'])我测试了这个,如果你想阅读message
obj['message']['text']https://stackoverflow.com/questions/61199555
复制相似问题