Tuesday, August 21, 2018

Not able to get public channels

Leave a Comment

I am creating a small app using javascript SDK provided by twilio programmable chat , And I want to get the list of all the channels , To achieve this I am using getPublicChannelDescriptors() method.

below is the code:

$.getJSON(     '/getToken?identity=' + identity + '&endpointId=' + endpointId,      function (data) {          console.log(data);         chatClient = new Twilio.Chat.Client(data.token);      chatClient.getPublicChannelDescriptors().then(function(channels) {          //do something     });    }  ); 

the error I am getting is below:

twilio-chat.min.js:149 Uncaught TypeError: Cannot read property 'getChannels' of null 

I am getting data in response of ajax call and able to create chatClient succesfuly and also I am able to fetch all the channels subscribed by the user by using method getSubscribedChannels() but not able to get public channels.

Any help will be appreciated.

1 Answers

Answers 1

Twilio changed client constructor from v2.0. So need to change like:

Twilio.Chat.Client.create(token).then(client => { // Use client }); 

or

let client = await Twilio.Chat.Client.create(token); 

This would fix above problem.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment