Conversation not reopening on reopen click

Hello,
I have a requirement like on conversation reopen need to reassign the agent who is previously assigned but for only to a specific group, it should not be reassigned. To perform this I’m using reopen click and trying to update the conversation with the previously assigned agent if the condition satisfies. It’s entering into the callback function but the conversation is not reopening.
Here is the code snippet that I used

client.events.on("conversation.onReopenClick", eventCallback, { intercept: true });
 var eventCallback = function (event) {
            console.log(event.type + " event occurred");
            console.log("in reopen click event....")
            getUserProp(client, function (userData) {
                console.log(userData);
                var userprops = userData.properties;
                for (var i = 0; i < userprops.length; i++) {
                    console.log(userprops[i].name, userprops[i].value);
                    if (userprops[i].name === 'Agent Id') {
                        console.log(userprops[i].value);
                        reassignAgent(client, userprops[i].value);
                    }
                }
            });
        };
       function reassignAgent(client, agentId) {
          getAssignedAgent(client, function (data) {
               console.log(data.convId);
               if (data.groupId !== '68b1fb28-7233-439a-bb05-dbc3009cadf3') {
                var url = `https://api.freshchat.com/v2/conversations/${data.convId}`;
                 var headers = {
                      "Authorization": "Bearer <%= iparam.apiKey %>"
                 };
                 var body = JSON.stringify({
                "status": "assigned",
                "assigned_agent_id": agentId
            });
            var options = {
                headers: headers,
                body: body
            };
            client.request.put(url, options).then(function (updateData) {
                console.log("Agent assigned successfully...")
                console.log(updateData);
            }, function (error) {
                console.log(error);
            });
        } else {
            console.log("do nothing..");
        }
    })
}

Please find out the below recording URL about the issue
conversation not getting reopened? Can you let me know why it is blocking to reopen?

-Soujanya.

Hi Soujanya,

Intercept events are paused until the event listener is executed.

As mentioned in the document Events Method

// To allow the original event to continue
event.helper.done()

// To prevent the original event from completing
event.helper.fail(‘errorMessage’)

Kindly update the code snippet with event.helper.done() and revert back if the issue still persist.

Thanks,
Janani V.

4 Likes

Thanks, @Janani_V it worked fine now :slightly_smiling_face:

-Soujanya.

1 Like