0

我正在尝试将消息批量插入 Twilio 聊天频道,这是 Twilio Flex 的频道上下文。到目前为止,我还没有找到任何支持这一点的 api。

当然可以与创建消息端点并行插入,但是由于无法通过 api 控制的 index-property,消息的顺序最终变得随机。即使将 DateCreated 和 DateUpdated 设置为正确的时间(已验证),订单也是随机的。

到目前为止,我发现的唯一可证明正确的方法是依次插入一条消息,花费很长时间。(每条消息大约 0.5 秒)。

任何帮助将非常感激 :)


我使用的是 python SDK,但也直接使用了 REST 端点,结果相同。

如果重要的话,这是我当前上传逻辑的简化版本:

messages: List[InteralMessageFormat] = fetch_messages()
client = twilio.rest.Client("my account", "my access token")
display_name = "Some Friendly Name"

channel = client.flex_api.channel.create(
  flex_flow_sid=flex_flow_sid,
  identity=identity,
  chat_user_friendly_name=display_name,
  chat_friendly_name=display_name,
)

for m in messages: # this works, but takes a very long time.
  # I have also tried this in parallel with aiohttp as suggested by their own blog-post: https://www.twilio.com/blog/asynchronous-http-requests-in-python-with-httpx-and-asyncio
  # However, doing so results in out-of-order messages.
  channel.messages.create(
    body=m.body,
    from_=m.from,
    date_created=m.correctly_formatted_isoformat_date_created, 
    date_updated=m.correctly_formatted_isoformat_date_updated,
  )

4

0 回答 0