0

I am new to reactjs - and looking to gain access to the Twilio chat feature.

I've done an npm install on this module. https://www.npmjs.com/package/twilio-chat


The documentation says:

Client instantiation looks as follows:

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

or, using async/await syntax:

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


/// Old code I am reconfiguring javascript that was sitting on a codeignitor base. This function worked.

"chatClient = new Twilio.Chat.Client(data.token)"

/// New code

import Chat from 'twilio-chat'

-- so I've tried something like this first

chatClient = new Chat.Client(data.token)

then something like

chatClient = Chat.Client(data.token)

When I do these console logs..I get the following

    console.log('Twilio>', Chat)

it shows

 Twilio>  function Client(token, options) {
            (0, _classCallCheck3.default)(this, Client);

           var _this = (0, _possibleConstructorReturn3.default)(this, (Client.__proto__ || (0, _getPrototypeOf2.default)(Cl…
  • if I delve into this

    console.log('Twilio-->Client', Chat.Client)
    

it shows

Twilio-->Client undefined

1 Answer 1

0

twilio-chat exports the client and as you can see from your first console.log it is indeed the Client constructor function (class). You have to invoke it like this:

chatClient = new Chat(data.token)

Note that import X from 'module' uses the default export of the module and assigns it to the name X, it is no indication of which export is used and is just like any other name you'd use for a variable. See MDN - import for the syntax.

Sign up to request clarification or add additional context in comments.

6 Comments

that got me past the first issue -- but then this "getUserChannels()" is not found chatClient.getUserChannels().then(createOrJoinChannel)
There is no getUserChannels function on Client. You linked outdated docs (0.12.0). The latest published version is 1.0.2 (documentation).
right -- yeah the code from the old base is out of date
Ok so @Michael Jungo --- would I just call chatClient.channels and do the then -- chatClient.channels.then(createOrJoinChannel)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.