2

I retrieved an access token from my server and have connected the JavaScript SDk chat client like so. I have created a channel like so. The next step I'd like to invite a user like this. In that example they invite the user 'elmo'. Where do I get 'elmo' or how do I present the user with a selection of possible 'elmo's? The client sdk has no list users functionality.

Edit:
It looks like the REST API has a list users method. But can't find any examples of it used. Should the 1st person chat client be using the REST API as well to supplement gaps in the client SDK or should it get the identity from backend? Our team has different interpretations of the docs: twilio REST API is strictly for backend vs. twilio REST API can and should be used any where. Moved to twilio REST API: strictly backend?

Wilhelmina Lohan
  • 2,803
  • 2
  • 29
  • 58

1 Answers1

1

Twilio developer evangelist here.

In my opinion Twilio's Chat API should not be the central source of truth of the users in your system. I don't know anything more about your application than what you've written here, but I would expect that you have a user model within your own system that you have used to generate or create an identity that is then used by the Chat API as well as how your user logs in to your system. I would then use that user model to connect users and provide their identities so that they can join chats together.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • I simplified the issue to get a response. This is what we are doing already, we have an authenticated endpoint on our server that tells us all of the "users" that the authenticated user is can interact with. The problem with that is that if another user has never logged in, or never used the chat feature, then an access token has never been generated, thus twilio is not aware of the identity so if you try to add or invite that identity with the client sdk it errors. – Wilhelmina Lohan Dec 03 '18 at 16:38
  • So it seems somehow (client or backend) you have to know the identities twilio is aware of, yet while the docs are highly opinionated else where this is a grey area, and I can't find in any of the examples. – Wilhelmina Lohan Dec 03 '18 at 16:46
  • So, if the user doesn't exist in chat yet, you can [create a user using the REST API](https://www.twilio.com/docs/chat/rest/users#create-a-user). – philnash Dec 04 '18 at 02:44
  • 1
    That leads me back to the root of the issue is how do I know if a user has been created yet. – Wilhelmina Lohan Dec 04 '18 at 16:17
  • Also speaking of solutions that use the REST API, still not clear on were to do that https://stackoverflow.com/questions/53598372/twilio-rest-api-strictly-backend – Wilhelmina Lohan Dec 04 '18 at 16:20
  • Well, you could [retrieve the user from the API by identity](https://www.twilio.com/docs/chat/rest/users#retrieve-a-user) and if they are not there then create them. Alternatively, to avoid that many API calls, you could store a field on your user object to say whether they have joined the chat yet. Or you could add all your users to chat as soon as they are created. It all depends on what is going to work best for your use case. – philnash Dec 04 '18 at 22:57