I'm using Twilio's JS client. The client requires an Access Token that I create with the following code and push to the front-end.
def generate_chat_token(self, identity, service_sid):
"""
Generate a jwt chat token.
"""
# 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()
I can then initialize the client on the front-end with:
let client = await Twilio.Chat.Client.create(token);
This works fine - however when I attempt to fetch a channel by SID:
let channel = await client.getChannelBySid('CHXXXX');
I get:
twilio-chat.min.js:171 Uncaught (in promise) Error: Forbidden
at t (twilio-chat.min.js:171)
at t (twilio-chat.min.js:171)
at new t (twilio-chat.min.js:171)
at e.<anonymous> (twilio-chat.min.js:171)
at k (twilio-chat.min.js:171)
at Generator._invoke (twilio-chat.min.js:171)
at Generator.e.<computed> [as next] (twilio-chat.min.js:171)
at n (twilio-chat.min.js:127)
at twilio-chat.min.js:127
To test this, I also created a standalone Ktor test application, and created the token using the Java SDK. This worked fine - no errors getting the channel. That's why I verified that initializing the client with a bogus token would fail, so I'm confident the error is not coming from an invalid token. The SID I'm using to try to fetch the channel is a SID returned from the following:
def get_conversations(self):
"""
Get Twilio conversations.
"""
return self.client.conversations.conversations.list()
Again, this works just fine in my Ktor application using the Java SDK, so I'm not sure what's different about the Python implementation here.
I'm not sure how to debug this further - How can I get a specific channel from the client without this error?