Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

With twilio API in vuejs2 app I got error client.on is not a function

Hello, I want to use twilio API in my vuejs2 app looking at demo https://github.com/TwilioDevEd/sdk-starter-node:

I got client object with Twilio credentials, but next I want to assign tokenAboutToExpire with code like :

                const client = new Twilio(
                    process.env.VUE_APP_TWILIO_API_KEY,
                    process.env.VUE_APP_TWILIO_API_SECRET,
                    {
                        accountSid: process.env.VUE_APP_TWILIO_ACCOUNT_SID,
                    }
                )
                console.log('client::')
                console.log(client)
                console.log('client.chat::')
                console.log(client.chat)
                
                client.on("tokenAboutToExpire", async () => { // Error line
                // client.chat.on("tokenAboutToExpire", async () => { // If to uncomment this line 
                    const token = await this.fetchChatToken()
                    client.updateToken(token)
                })

and got error:

Uncaught (in promise) TypeError: client.on is not a function
    at _callee3$ (usersChat.vue?ec5f:264)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)

and in the console I see that I have client and client.chat : https://prnt.sc/w4frzp What is wrong? Is it invalid client object?

Thanks!

0 likes
0 replies

Please or to participate in this conversation.