Twilio: Getting "Conflict" error while adding the participant to the Conversion

245 views Asked by At

Facing issue while adding the non chat participants using the JS SDK in twilio conversation

I have done following things to add the non chat participants in the JS SDK

    Twilio.Conversations.Client.create(token).then(client => {
        console.log(client);
        client.on("stateChanged", (state) => {
            if (state === "failed") {
                console.log("fail");
                // The client failed to initialize
                return;
            }
            if (state === "initialized") {
                console.log("init");
                // Use the client
            }
        });
        client.createConversation().then(async function(conversation) {
            console.log(conversation, 'conversation');
            await conversation.join();
            const proxyAddress = "twilio number";
            const address = "phone Number";
            const attributes = {
                identity: address
            };
            const messeges = await conversation.getMessages();
            console.log(messeges, 'messeges')
            conversation.addNonChatParticipant(proxyAddress, address, attributes).then(function(a) {
                console.log(a, 'a');
            }).catch(function(err) {
                console.log(err, 'while adding the Participant');
            });
        }).catch(function(err) {
            console.log(err, 'con');
        });
    });

It gives me following and its not that much explained anywhere. moreover I got the client object and the conversation object as well but after that I can't add Participant

Error: Conflict at e.<anonymous> (twilio-conversations.min.js:129:209472)at Qc (twilio-conversations.min.js:129:30955)at Generator._invoke (twilio-conversations.min.js:129:30737)at forEach.e.<computed> [as next] (twilio-conversations.min.js:129:31399)at t (twilio-conversations.min.js:129:117709)at o (twilio-conversations.min.js:129:117920) 'while adding the Participant'
1

There are 1 answers

0
DanGonzalez On

This Conflict error appears when you attempt to add a participant to a new conversation, but this participant is already in an active conversation with the same proxy_address (Twilio phone number).

In other words, you can’t have more than one active conversation using the same To/From pair. More info here: https://www.twilio.com/docs/conversations/inbound-autocreation#key-principle-the-tofrom-number-pair

To solve this issue, you have 2 options:

  1. you can close the old conversation by updating it, and set the state to “closed”: https://www.twilio.com/docs/conversations/api/conversation-resource#update-conversation In this case your account keeps the data.
  2. You can delete the conversation https://www.twilio.com/docs/conversations/api/conversation-resource#delete-a-conversation-resource You lose the data

If you have issues finding the conversation SID where your participant is, you could use Participant Conversation Resource, that allows you to find the conversations that a phone number has had https://www.twilio.com/docs/conversations/api/participant-conversation-resource