twilio / twilio-conversations-demo-react

Twilio Conversations Demo Web Application
MIT License
97 stars 306 forks source link

Cannot create a new conversation #144

Closed AbdullahQureshi1080 closed 6 months ago

AbdullahQureshi1080 commented 10 months ago

I was trying to test the demo out, after having done the initial steps and setting up the serverless functions. I can log in and build the app successfully. However, I cannot create a new conversation.

Error: Cannot read properties of undefined (reading 'then')

  "react": "17.0.2",
  "@twilio/conversations": "2.4.1",

It's this function

  async createConversation(options) {    
        await this._ensureReady;
        options = options || {};
        return this._conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
    }

Note: I am using the serverless functions for the backend.

Node: v18

Use the steps here to set up the service.

Screenshot 2023-12-06 at 10 51 07 AM

I have gone through the other issues, not that helpful. Anyone who's been able to get throught this, I'd appreciate the support.

AbdullahQureshi1080 commented 10 months ago

makzpatel, camr1993, esquive Any help here. I have the project cloned locally and running. If it'll help I can set up a repo and share that.

jmozzart commented 10 months ago

Check the variables in the functions. I had the same problem before and found out that I mispelled the variables.

AbdullahQureshi1080 commented 10 months ago

Check the variables in the functions. I had the same problem before and found out that I mispelled the variables.

@jmozzart For the serverless function? And in the Twilio console?

jmozzart commented 10 months ago

Check both.

AbdullahQureshi1080 commented 10 months ago

In the serverless function

let token = new AccessToken(
      context.ACCOUNT_SID,
      context.TWILIO_API_KEY_SID,
      context.TWILIO_API_KEY_SECRET, {
        identity: event.identity,
        ttl: 3600
      });

    let grant = new AccessToken.ChatGrant({ serviceSid: context.SERVICE_SID });

Variables (ENV)

Screenshot 2023-12-07 at 12 49 09 PM

Add my Twilio Credentials (ACCOUNT_SID) and (AUTH_TOKEN) to ENV -> This is also checked to be true.

So this is in the serverless config!

Do I have to add these variables in the demo project on the front end as well?

berkus commented 10 months ago

Since you're still offline, this means the connection did not finalize yet, you cannot create conversations while offline in the current implementation.

AbdullahQureshi1080 commented 10 months ago

Since you're still offline, this means the connection did not finalize yet, you cannot create conversations while offline in the current implementation.

Understood. But how do I validate that I am alive?

The token is valid. Because the login call gives a valid token.

It's the preset demo, haven't changed anything. I thought it should work with the steps.

Can you share the quick flow and then I can try to see if there are missing things, I can then update after tweaking things at my end.

AbdullahQureshi1080 commented 10 months ago

@berkus I just logged the connecting state, it starts from connecting to denied. I think that's the issue.

What could be the possible reason?

Screenshot 2023-12-07 at 3 31 47 PM

Do I have to add these variables in the demo project on the front end as well?

berkus commented 10 months ago

denied means your token is invalid. Enable trace logging and check the error response in the logs.

You do not need to add any env variables to the frontend except the token function URL.

lesquive commented 9 months ago

@berkus maybe we can change Error: Cannot read properties of undefined (reading 'then') to a different message so it doesn't confuse anyone.

berkus commented 9 months ago

@lesquive sure, we have almost non-existing error handling in the app, there are many places where we could improve error messages and handle them gentler.

GomezFabio commented 9 months ago

I had the same problem and this is how I have solved it. I was using wrong credentials for TWILIO_API_KEY_SID and TWILIO_API_KEY_SECRET variables. You must create a new API Key and get the right variables from it. Check it at https://console.twilio.com/us1/account/keys-credentials/api-keys and use [Create API key] button.

AbdullahQureshi1080 commented 9 months ago

@GomezFabio Thanks.

I already did this. I am able to use auth but cannot create room/channel for testing the whole thing out.

And I was not able to find anything in the demo, example or the docs on how to trace my steps for the setup.

Currently putting twilio on hold, exploring other options.

Fabryz commented 8 months ago

I've just deployed to Vercel, followed the guide in the github readme of the demo, I also get this error when creating a new conversation:

Cannot read properties of undefined (reading 'then')

Any news on this? @AbdullahQureshi1080

edit: My app is deployed on Vercel, I saw "offline" on the top bar under my username. What do I have to do?

AbdullahQureshi1080 commented 8 months ago

No update, we moved to another sdk as their solution did not fulfill our use case. Although I did try to fix these error but no luck. The documentation can be made more assistive to help. At the moment it's not. @Fabryz

On Fri, 23 Feb 2024, 3:22 am Fabrizio Codello, @.***> wrote:

I've just deployed to Vercel, followed the guide in the github readme of the demo, I also get this error when creating a new conversation:

Cannot read properties of undefined (reading 'then')

Any news on this? @AbdullahQureshi1080 https://github.com/AbdullahQureshi1080

— Reply to this email directly, view it on GitHub https://github.com/twilio/twilio-conversations-demo-react/issues/144#issuecomment-1960423732, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANJLWWQ6PC477NY7XM6PZUDYU7AJPAVCNFSM6AAAAABAI2MC6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRQGQZDGNZTGI . You are receiving this because you were mentioned.Message ID: @.***>

berkus commented 8 months ago

My app is deployed on Vercel, I saw "offline" on the top bar under my username.

Did you set up the token generator?

Fabryz commented 8 months ago

My app is deployed on Vercel, I saw "offline" on the top bar under my username.

Did you set up the token generator? I've setup the two TWILIO API KEYS

Could you please tell me what I'd need to do in particular?

berkus commented 8 months ago

Could you please tell me what I'd need to do in particular?

You need to deploy a function as descibed in the README that will generate and provide you with access tokens. When deploying to vercel it shall ask you about the token generator url - you need to provide that function's url there.

alorian commented 7 months ago

@GomezFabio gave a right answer. Thank you. My problem was in the existing API key which is actually not an API key at all.

https://console.twilio.com/us1/account/keys-credentials/api-keys This page has two sections.

  1. API keys
  2. Auth Tokens

There was a live auth token which I already used before this demo application and this auth token didn't work.

Now I've created a new API key. I've updated my env variables in the cloud function and everything works now. The status is set to "online" after the initial sign in.

@Fabryz FYI

berkus commented 6 months ago

I guess we're all sorted here. Closing.