Indokiwi
Indokiwi

Reputation: 13

Twilio IP Messaging API not working

I just followed the instructions to setup and test it. I used Javascript API. When I tried to message using two tabs or two windows as mentioned in the docs it is not working. It throws error at sendMessage method being "undefined". when I console log it gets the correct message typed in the html element.

As soon as I start localhost it throws following error. Any suggestions please.

Navigated to http://localhost:3000/

cds.twilio.com/v2/Streams:1 POST https://cds.twilio.com/v2/Streams 403 (Forbidden)
twilio-ip-messaging.min.js:198 IPMSG: failed to create session Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}(anonymous function) @ twilio-ip-messaging.min.js:198
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
twilio-ip-messaging.min.js:199 Twilsock connection closed by server []r._onSocketRejected @ twilio-ip-messaging.min.js:199d.create.callbacks.onsocketRejected @ twilio-ip-messaging.min.js:199e.doCallback @ twilio-ip-messaging.min.js:281e.afterThisEvent @ twilio-ip-messaging.min.js:281e.afterEvent @ twilio-ip-messaging.min.js:281transition @ twilio-ip-messaging.min.js:281(anonymous function) @ twilio-ip-messaging.min.js:281r.onmessage @ twilio-ip-messaging.min.js:199

Upvotes: 0

Views: 1240

Answers (1)

philnash
philnash

Reputation: 73055

Twilio developer evangelist here.

First of all, you will need to use your production Account Sid in order to get this to work.

Twilio test credentials only work on certain parts of the REST API.

Once you have generated your token on the server side, you need to get it to the client side and authenticate your client like this:

accessManager = new Twilio.AccessManager(token);
messagingClient = new Twilio.IPMessaging.Client(accessManager);

Take a look at the IP Messaging quick start code to see an example of how it is done. The full instructions for the quick start guide can be found here.

Let me know if that helps at all.

Upvotes: 2

Related Questions