3

I created a chat client using Twilio, using their JavaScript client on the front end. I'm making the following call to get a channel by SID

let channel_promise = client.getChannelBySid(sid);

This worked fine for months, but now out of the blue I'm getting the following error:

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

I'm fetching the client library from their CDN and specifying the version, so I'm fairly confident this isn't breaking due to a change in the client code.

<script src="https://media.twiliocdn.com/sdk/js/chat/v3.3/twilio-chat.js"></script>

I confirmed the channel SID I'm using is correct by logging it to console, and then using the twilio-cli to look up existing channels. The output from the cli matches the console output, so I know that I'm using the correct SID.

Does anyone have any idea why this call is failing? How can I get the channel without an error?


The code around the getChannelBySid call is:

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){
        ...
    })

}

The SID is coming from the backend which uses the following code to fetch conversations:

from twilio.rest import Client

...

self.client = Client(self.account_sid, self.auth_token)

...

def get_conversations(self):
    return self.client.conversations.conversations.list()

The Chat token is generated with the following code:

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()
That1Guy
  • 7,075
  • 4
  • 47
  • 59
  • did you trim the `sid`? probably, it has whitespaces. – raven Sep 15 '20 at 07:48
  • @raven I just confirmed - this fails even after trimming any whitespace from the SID. – That1Guy Sep 15 '20 at 12:32
  • Hey @That1Guy, I am not sure if the stack trace is completely correct as I couldn't find any such errors thrown from the library. Would you be able to provide demo app with issue reproduced? – Dipen Shah Sep 15 '20 at 17:27
  • One more thing I would suggest is to use non-minified js library and provide full stack trace. – Dipen Shah Sep 15 '20 at 17:37
  • 1
    @DipenShah My request to make the app public was denied, but I can use the non-minified library and update the stracktrace. – That1Guy Sep 16 '20 at 12:16
  • @That1Guy seems to be a socket error with HTTP status code 404 – Dipen Shah Sep 16 '20 at 13:28
  • @DipenShah Is there anything I can do about it? – That1Guy Sep 16 '20 at 14:24
  • @That1Guy Here is what I would recommend for debugging purpose, monitor network log and see what requests are failing most likely it will be some config error and my money is on `sendWithReply` call library is making which could be failing due to missing parameters or wrong host address/path. One more thing I would suggest is to try downloading library and use offline version and debug `actualSend` function. – Dipen Shah Sep 16 '20 at 14:27
  • @DipenShah I will take a look - thank you – That1Guy Sep 16 '20 at 15:32
  • @That1Guy I recommend upgrading to the latest version of the twilio chat sdk , 4.0.0 and see if you still have issues https://media.twiliocdn.com/sdk/js/chat/releases/4.0.0/twilio-chat.js – YisraelU Sep 17 '20 at 03:28
  • @A-Developer-Has-No-Name I get the same error with the latest version. – That1Guy Sep 17 '20 at 12:18
  • @A-Developer-Has-No-Name any luck debugging or getting network trace? – Dipen Shah Sep 17 '20 at 13:37
  • @A-Developer-Has-No-Name Unfortunately, no. I'm still working on this =\ – That1Guy Sep 17 '20 at 14:38
  • i recommend analyzing the network traffic to get a better idea of whats failing and with what type of error. – YisraelU Sep 17 '20 at 14:53
  • @A-Developer-Has-No-Name All requests appear to return 200 OK – That1Guy Sep 17 '20 at 15:57
  • I noticed you used the CDN link to version `3.3` but that points to the latest version in the `3.3` series which is currently `3.3.7`. Have you tried rolling back to an older version (you link to the docs of `3.3.4`)? – philnash Sep 22 '20 at 04:49
  • @philnash Thank your for tyour suggestion - I just tried several different versions and there was no change. I'm still getting the same error. – That1Guy Sep 22 '20 at 13:40
  • Is this error reproducible every time (at least for the same SID)? Can you share the code around the call to `getChannelBySid`? – philnash Sep 23 '20 at 02:13
  • @philnash Yes, this is reproducible every time - regardless of the SID. The code around the `getChannelBySid` call is pretty basic. I just fetch the SID from an HTML attribute, and pass it into the call. I'll update the question, though. – That1Guy Sep 23 '20 at 12:43
  • My guess is that `getChannelBySid` hasn't broken, especially across a number of versions. Has anything changed about how you are setting that SID from the attribute? Is there, perhaps, whitespace that has snuck in? – philnash Sep 23 '20 at 12:46
  • @philnash I really want to agree with that, but nobody has touched this code since February when everything was working as expected. Is there anything else I can give you to help me? – That1Guy Sep 23 '20 at 13:00
  • @philnash I don't know if this is useful to you, but I tried fetching the channel using the twilio-cli, Python, PHP, and cURL. Everything works fine except the JS client. – That1Guy Sep 23 '20 at 13:11
  • How is the SID being added as a data attribute? Where is that data coming from? Also, have you changed anything around the way the chat access token is generated? Or changed any of the credentials used for it? Has the chat service Sid changed for any reason or does it differ from the one you are using in the CLI/Python? – philnash Sep 23 '20 at 13:23
  • @philnash I updated the question to show where the SID is coming from. I have not changed anything around how the chat access token is generated - I included that code in the question as well. And no, the credentials have not changed. (I would expect my call to fetch conversations would fail as well if I was using invalid credentials.) I'm looking into the Chat Service SID right now – That1Guy Sep 23 '20 at 13:57
  • @philnash It looks like its a problem with the chat service sid. Thanks for helping me diagnose this. If you want to add an answer, I'll gladly accept it. Quick question regarding best practices - should each conversation have its own chat service SID or should all conversations share the same chat service SID? – That1Guy Sep 23 '20 at 14:17
  • A service is effectively a grouping of channels and users. I would imagine that most use cases would use one service and have multiple channels within that service. Glad you figured out what changed! – philnash Sep 23 '20 at 14:23
  • That's what I thought. Thanks again! – That1Guy Sep 23 '20 at 14:28

0 Answers0