Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

304
Visualizações
Error calling "updateToken" on client denied state change, using Twilio Conversations JS SDK

I am using the Twilio conversations JS SDK, and I need to refresh my connection token if it is expired or invalid. The issue is that, if I call the updateToken() function when the connection state change to "denied", I get the following error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'updateToken')

I am using it like this:

let conversationsClient = new Twilio.Conversations.Client('SOME_EXPIRED_OR_INVALID_TOKEN')
conversationsClient.on("connectionStateChanged", (state) => {
  switch (state) {
    case "denied":
      conversationsClient.updateToken(getConversationsToken());
      break
  }
});

For some reason my conversationsClient object is undefined when it enters the denied state.

According the SDK documentation (https://media.twiliocdn.com/sdk/js/conversations/releases/2.0.0/docs/modules.html#ConnectionState), I can update the token when the state is changed to denied.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

My guess here is that your getConversationsToken function is asynchronous as it presumably makes a request to your server. But you are passing the result of the function, not the result of the asynchronous action.

I assume that getConversationsToken returns a promise, so you might be able to fix this by updating the token in the then callback:

let conversationsClient = new Twilio.Conversations.Client('SOME_EXPIRED_OR_INVALID_TOKEN')
conversationsClient.on("connectionStateChanged", (state) => {
  switch (state) {
    case "denied":
      getConversationsToken().then(token => {
        conversationsClient.updateToken(token);
      }).catch(error => console.error(error));
      break
  }
});

Or, you could use async/await like this:

let conversationsClient = new Twilio.Conversations.Client('SOME_EXPIRED_OR_INVALID_TOKEN')
conversationsClient.on("connectionStateChanged", async (state) => {
  switch (state) {
    case "denied":
      conversationsClient.updateToken(await getConversationsToken());
      break
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda