Reputation: 41
Note: I'm using @twilio/conversations version 1.1.0 in node project. I'm transitioning from using Programmable Chat to Conversations.
I'm seeing calls to Client.getConversationByUniqueName
and Client.getConversationBySid
are not returning existing channels that were created by other users.
Example:
User 'A' (with its own unique identity and token) successfully created conversation 'myConvo1'using the following code:
client.createConversation({
uniqueName: 'myConvo1',
friendlyName: 'myConvo1',
});
User 'B' (with its own unique identity and token) cannot find that conversation using: Client.getConversationByUniqueName('myConvo1')
OR Client.getConversationBySid(sid)
(just passing in the sid I get from the initial createConversation call).
I see these errors respectively:
Not Found at Upstream.actualSend
./node_modules/@twilio/conversations/node_modules/twilsock/lib/services/upstream.js:135
Conversation with SID CHc4565e40a32f4bffaf490bae2cff45db is not found.
at conversations.syncListRead.promise.then.then.conversation ./node_modules/@twilio/conversations/lib/client.js:283
However, I can access this conversation fine with the same functions if I'm using User A's token/identity. Also, when I call this from User B's Client:
client.createConversation({
uniqueName: 'myConvo1',
friendlyName: 'myConvo1',
});
I get this error: Conversation with provided unique name already exists
. So all of this leads me to believe the conversation is out there, but it's just not available for other users to join.
Note 2: I've been referencing the docs below. I don't see any explicit examples on how to find and join channels, so I may be missing something or approaching this wrong.
https://media.twiliocdn.com/sdk/js/conversations/releases/1.1.0/docs/Client.html
https://www.twilio.com/docs/conversations
Upvotes: 4
Views: 2772
Reputation: 1026
As @mwest-cs mentioned, the issue was that participants have to be added after creating conversation. I've created conversations on backend, so that they were created by system
, not by one of participants. It's ok, just need to add all participants to the conversation. That's the code I got working for me eventually:
const Twilio = require('twilio');
const conversationUserIds = [123, 456]; // TODO: replace with real ones; those are my custom user IDs, not Twilio User SIDs.
const twilioClient = Twilio(twilioConfig.ACCOUNT_SID, twilioConfig.AUTH_TOKEN);
const newConversation = await twilioClient.conversations.conversations.create({ uniqueName });
await Promise.all(conversationUserIds.map((userId) =>
channel.participants().create({ identity: userId })
));
Please note, that as per the Twilio Documentation, creating a Participant joins them with the conversation, and the connected person will receive all subsequent messages.
Also, you can check how many participants in your conversation by going to Expore Products in Twilio Console -> Conversations, on the left sidebar: Conversations -> Manage -> Services, choose the service, then on the left sidebar: Conversation (in the bottom). Here you can see the table of all your conversations, and there is table column Participants indication participant count in each conversation.
Happy coding!
Upvotes: 0
Reputation: 173
I created multiple Service ID's and using one specific(XXXX-Chat-Dev) Chat Service ID, but application took the Default Chat Service ID which I didn't mentioned in backend.
Fixed by deleting the Default Chat Service ID in Twilio.
Cheers!
Upvotes: 1
Reputation: 10771
Could this be the reason, where Twilio Conversations only supports private channels, not public channels like Programmable Chat?
Public vs. Private Channel Use Cases with Twilio Programmable Chat
Migrating to Conversations from Programmable Chat
Upvotes: 2