2

When I'm trying to use the programmatic chat I'm constantly getting this error

Error: Can't connect to twilsock
at t (twilio-chat.min.js:204)
at t (twilio-chat.min.js:204)
at new t (twilio-chat.min.js:204)
at e.value (twilio-chat.min.js:204)
at t.value (twilio-chat.min.js:204)
at twilio-chat.min.js:204
at t.<anonymous> (twilio-chat.min.js:204)
at twilio-chat.min.js:168
at t.a.emit (twilio-chat.min.js:168)
at t.value (twilio-chat.min.js:175)

I followed all the instruction for the repo I'm testing on. I generate the token. So not sure what is wrong. I understand something is wrong when generating the token. Can anyone tell me what identity needs to be passed? I created the test user in the service from the Twilio console but still it's not working.

Jinal Shah
  • 325
  • 3
  • 15
  • Are you using your real credentials or the test credentials (which won't work)? Are you able to test your generated token in https://jwt.io/ ? – philnash Feb 03 '19 at 22:14
  • I'm using real credentials. I'm able to test the generated token and validate it as well. – Jinal Shah Feb 03 '19 at 22:15

4 Answers4

5

Twilio developer evangelist here.

I believe you might be using test credentials to generate your access token. With Programmable Chat you cannot use test credentials, they are only to be used to fake sending messages, buying numbers and making phone calls.

Please try generating your access token again but with live credentials available in your Twilio console.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 1
    Thanks @philnash. that helps. I used test keys and got the errors. – Dat TT Feb 26 '20 at 07:52
  • Hi @philnash. I have been getting the same error on React Native. I get the token, then call client.create(token) which returns this error: Can't connect to twilsock I use the same token on Twilio sample Android app like this: ChatClient.create(context, token, props, this); This completes and calls onSuccess(ChatClient chatClient) So why it doesn't return the chatClient on React Native. Please help. – varun Mar 22 '20 at 15:59
  • I am very sure I am using live API credentials. – varun Mar 22 '20 at 18:29
  • @varun I don't know what's going on there I'm afraid. Are you using the JavaScript library in the React Native environment or do you have a React Native wrapper for the native libraries? – philnash Mar 23 '20 at 04:10
  • @philnash I am trying to run this sample project from Twilio: https://github.com/twilio/TwilioChatJsReactNative Here is the code for building client: import { Client as TwilioChatClient } from "twilio-chat"; return TwilioChatClient.create(token).then((chatClient) => { } – varun Mar 23 '20 at 13:47
  • @varun Ah, I'm afraid I don't know much about that project. I'd raise an issue on the repo and see if you can get support from the team that wrote it. – philnash Mar 24 '20 at 03:06
1

I'd just like to add I ran into this error and while my problem turned out to be when generating the token, it wasn't clear that was the problem (it was generating a valid JWT token, with valid, live credentials).

I didn't realize I was using an object instead of a string (ObjectId) for the identity, and so just adding a .toString() for it made the error go away (something like token.identity = user._id.toString(); in my case).

Very obscure, so hopefully this will help someone else.

Also, note the Chat.create(token) or Twilio.Chat.Client.create(token) will expect token to be the output of token.toJwt() from the backend, as sending the JSON token doesn't throw an error or work.

Bruno Bernardino
  • 476
  • 2
  • 5
  • 12
0

I had this problem as well.

The SIDs were not spelled correctly in my case. Double check to make sure that you are passing the right parameters when getting the token through the rest api.

Silly mistake but i did spend some time figuring it out.

0

Make sure to use all the corrret ones

   $TWILIO_CHAT_SERVICE_SID = 'IS7XXXXXXXXXXXXXXXXXXXXX';
   $accountSid = 'ACXXXXXXXXXXXXXXX';
   $apiKeySid = 'SKXXXXXXXXXXXXXXX';
   $apiKeySecret = 'F5XXXXXXXXXXXXXXX';

That casusethe Error