我想向Cisco webexteams机器人发送查询,以检查与Cisco设备有关的各种参数。我已经成功地编写了一些有效的代码,但是它依靠sleep
来等待响应,例如:
try:
sent_message = api.messages.create(room.id, text=MODEL)
time.sleep(3)
messages_in_room = api.messages.list(room.id)
for message in messages_in_room:
if message.markdown is not None:
returned_mes = message
break
except ApiError as e:
print(e)
我希望首先,将GeneratorContainer(messages_in_room)设置为max=2
时,仅返回最新的2条消息。没有。
我对if message.markdown is not None
进行了一些笨拙的检查,以区分send_message和消息。它们的格式分别如下:
{
"id": "abc",
"roomId": "bcd",
"roomType": "direct",
"text": "MyModel",
"personId": "cde",
"personEmail": "me@me.com",
"created": "2020-09-23T12:39:57.894Z"
}
{
"id": "xyz",
"roomId": "bcd",
"roomType": "direct",
"text": "Returned text",
"personId": "pqr",
"personEmail": "CiscoEoL@webex.bot",
"markdown": "moreblah",
"html": "<p>blah</p>",
"created": "2020-09-23T12:39:59.745Z"
}
在异步设置(如RabbitMQ)中,您会获得某种syncID,但这里的ID与您发送的内容和您检索的内容都不匹配,但roomID除外,但是使用此方法无助于区分在“匹配”的消息对之间,因为该RoomID下已经存在几条消息。我想知道其他人如何规避了这个问题。