Twilio 对话 API - 无法获取记录

Twilio Conversations API - unable to fetch record

我正在尝试逐字获取 Twilio 文档后的对话 here

import os
from twilio.rest import Client


# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

conversation = client.conversations \
                     .conversations('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                     .fetch()

这 return 是 :

HTTP 404 error: Unable to fetch record: The requested resource /Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX was not found

但是,如果我像这样提供对话服务 ID:

import os
from twilio.rest import Client


# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

conversation = client.conversations \
                     .services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                     .conversations('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                     .fetch()

我正确获取了对话对象。在我的例子中,我使用 webhooks 来捕捉参与者何时加入对话,因为事件没有 return 服务 sid,只有对话 sid,这使我想做的事情变得复杂。我错过了什么?

此处为 Twilio 开发人员布道师。

简短的对话API,像这样:

conversation = client.conversations \
                     .conversations('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                     .fetch()

只有 using the default service 才有效。否则您确实需要提供服务 SID。

如果我是你,我会将对话服务 SID 作为配置参数存储在你的应用程序中,也许设置为环境变量,这样你就可以在像这样向 API 发出请求时引用它.