javascript - Twilio JS - Client.getChannelBySid 引发错误:未找到
问题描述
我使用 Twilio 创建了一个聊天客户端,在前端使用了他们的 JavaScript客户端。我正在拨打以下电话以通过 SID获取频道
let channel_promise = client.getChannelBySid(sid);
这工作了几个月,但现在突然出现以下错误:
twilio-chat.js:28610 Uncaught (in promise) Error: Not Found
at TwilsockUpstreamError.ExtendableBuiltin (twilio-chat.js:28610)
at TwilsockUpstreamError.TwilsockError (twilio-chat.js:28640)
at new TwilsockUpstreamError (twilio-chat.js:28719)
at Upstream._callee$ (twilio-chat.js:30068)
at tryCatch (twilio-chat.js:14232)
at Generator.invoke [as _invoke] (twilio-chat.js:14466)
at Generator.prototype.<computed> [as next] (twilio-chat.js:14284)
at step (twilio-chat.js:8227)
at twilio-chat.js:8238
ExtendableBuiltin @ twilio-chat.js:28610
TwilsockError @ twilio-chat.js:28640
TwilsockUpstreamError @ twilio-chat.js:28719
_callee$ @ twilio-chat.js:30068
tryCatch @ twilio-chat.js:14232
invoke @ twilio-chat.js:14466
prototype.<computed> @ twilio-chat.js:14284
step @ twilio-chat.js:8227
(anonymous) @ twilio-chat.js:8238
Promise.then (async)
success @ conversations.js:653
j @ jquery-1.11.0.min.js:2
fireWith @ jquery-1.11.0.min.js:2
x @ jquery-1.11.0.min.js:4
b @ jquery-1.11.0.min.js:4
XMLHttpRequest.send (async)
(anonymous) @ VM11:1
send @ jquery-1.11.0.min.js:4
ajax @ jquery-1.11.0.min.js:4
join_conversation @ conversations.js:617
dispatch @ jquery-1.11.0.min.js:3
r.handle @ jquery-1.11.0.min.js:3
我从他们的 CDN 获取客户端库并指定版本,所以我相当有信心这不会因为客户端代码的更改而中断。
<script src="https://media.twiliocdn.com/sdk/js/chat/v3.3/twilio-chat.js"></script>
我确认我正在使用的频道 SID 是正确的,方法是将其记录到控制台,然后使用 twilio-cli 查找现有频道。cli 的输出与控制台输出相匹配,因此我知道我使用了正确的 SID。
有谁知道为什么这个电话失败了?我怎样才能在没有错误的情况下获得频道?
调用周围的代码getChannelBySid
是:
function join_conversation(){
// Get the SID
const sid = $(this).attr('data-sid');
// Log the SID for debugging purposes.
console.log(sid);
// Get the channel.
let channel_promise = client.getChannelBySid(sid);
channel_promise.then(async function(channel){
...
})
}
SID 来自使用以下代码获取对话的后端:
from twilio.rest import Client
...
self.client = Client(self.account_sid, self.auth_token)
...
def get_conversations(self):
return self.client.conversations.conversations.list()
使用以下代码生成聊天令牌:
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import ChatGrant
...
def generate_chat_token(self, identity, service_sid):
# Get a token.
token = AccessToken(self.account_sid, self.api_key, self.api_secret, identity=identity)
# Add a chat grant to the token.
grant = ChatGrant(service_sid=service_sid)
token.add_grant(grant)
return token.to_jwt()
解决方案
推荐阅读
- oracle - 当我通过 emplid 它运行但是当我通过 Campus_id 它需要无限时间
- modelica - 使用组件的内部变量时出错
- c - 从 sscanf 读取的数字为 0
- c++ - 有没有办法避免为 std::variant 类成员中的所有类型编写构造函数?
- drupal - 如何更新 hook_presave 上的实体翻译?
- python - 如何正确使用带有 C++ 的 tensorflow 从 YOLO 模型中获取输出?
- jquery - 使用 jQuery 删除和附加视口
- angular - 在材料表中搜索不适用于管道
- google-chrome - 如何在 gitlab-ci 中的 chrome 中执行角度飞镖测试
- eclipse - 在构建路径中找到多个 Scala 库