Automatically close abandoned chats
Last Update: Sep 2024 • Est. Read Time: 13 MINChat offers a quick and easy way for customers to get in touch with your support agents. Sometimes, customers may abandon a chat mid-conversation and stop responding to agents, which can negatively impact your Total Open Conversation times.
You can use the volume control settings to close out conversations that get abandoned while a customer is interacting with a conversational assistant. This article outlines how to set up an automation that will automatically close out abandoned conversations that are assigned to an agent, and send a message to the customer letting them know their chat was ended due to inactivity. The workflow is triggered on an outbound message sent by an agent, and will only run on open conversations.
Who can access this feature? | |
User types | Admins and users with permissions to access workflows and API keys. |
In this article
- Create an API key
- Create a callable workflow
- Set up the workflow variable
- Customize the callable workflow
- Create an initialization workflow
Create an API key
First, you'll need to create an API to use with these workflows.
- Create an API key.
- Name the API key to help you remember it will be associated with the Chat Auto Close workflow.
- When setting up your new API key, assign the roles
org.permission.draft.create
,org.user.draft.read
, andorg.user.draft.write
. - Then, keep the token in a secure location to use later in this guide.
Create a callable workflow
To set up this automation, two workflows will need to be created:
- A callable workflow, and
- An initialization workflow that schedules the callable workflow.
Next, we'll set up the callable workflow.
To create the first workflow:
- Go to Settings and select Platform > Workflows.
- Select Add Workflow, and choose Custom Workflow.
- Name the new workflow Chat Auto Close Pt 2, and add a description to help you remember what this workflow does in the future.
- Turn on the Callable Workflow toggle.
- Select Create. The workflow editor will open.
- Open the Workflow Options menu in the toolbar and select Edit Workflow JSON.
- A modal appears where you can edit the code for this workflow. Select and delete all the current JSON code.
- Copy the below code block, and paste it into the JSON text field in your Workflow Editor.
- If your instance is hosted on our EU server, click on the Send a Message workflow step and replace what is in the URI field with
https://api.prod2.kustomerapp.com
. - Then, select Update to save the changes to the workflow and dismiss the JSON editor.
{ "description": "", "name": "chat-auto-close-pt-2", "steps": [ { "transitions": [ { "target": "zStY5mfO2", "condition": { "op": "true", "values": [ true ] }, "meta": { "name": "No New Messages" } } ], "errorCases": [], "id": "Qz3ioLdLD" }, { "transitions": [ { "target": "ryBHW-SFD", "condition": { "op": "true", "values": [ true ] }, "meta": { "name": "Conversation is Still Open" } } ], "errorCases": [], "id": "zStY5mfO2" }, { "transitions": [ { "target": "ON2ifnbPX", "condition": { "op": "true", "values": [ true ] } } ], "errorCases": [], "id": "ryBHW-SFD", "action": "kustomer.conversation.update", "params": { "id": "/#steps.1.conversationId", "status": "done" }, "appVersion": "kustomer-^1.9.2", "meta": { "displayName": "Close the Conversation" } }, { "transitions": [], "errorCases": [], "id": "ON2ifnbPX", "action": "kustomer.rest-api.json", "params": { "uri": "https://api.kustomerapp.com/v1/customers/{{steps.eK7TtTl6J.customer}}/drafts", "method": "POST", "data": { "auto": true, "sendAt": "{{{date 'day' count=0}}}", "conversation": "/#steps.eK7TtTl6J.id", "body": "INSERT BODY HERE", "channel": "chat" }, "headers": { "Authorization": "Bearer INSERT KEY HERE", "Content-Type": "application/json" } }, "appVersion": "kustomer-^1.9.2", "meta": { "displayName": "Send a Message" } }, { "transitions": [ { "target": "Qz3ioLdLD", "condition": { "op": "eq", "values": [ "/#steps.1.messageCount", "/#steps.eK7TtTl6J.messageCount" ] }, "meta": { "name": "Still same inbound/outbound message" } } ], "errorCases": [], "id": "eK7TtTl6J", "action": "kustomer.conversation.find-by-id", "params": { "id": "/#steps.1.conversationId" }, "appVersion": "kustomer-^1.9.2" } ], "trigger": { "transitions": [ { "target": "eK7TtTl6J", "condition": { "op": "true", "values": [ true ] } } ], "id": "1", "callable": true, "schema": { "properties": { "conversationId": { "type": "string" }, "messageCount": { "type": "string" } }, "required": [ "conversationId", "messageCount" ] }, "eventName": "kustomer.workflow.637552f101c4e5801f2f45d9.call" } }
Set up the workflow variable
Now you'll add the API key created earlier to the callable workflow using a workflow variable. Workflow variables allow you to store API keys securely and access them from within your workflow.
To set up the workflow variable:
- Open the Workflow Options menu in the toolbar and select Workflow Variables.
- Give the variable a name, and paste the API key created earlier in the Value field, and select Save.
- Select the Send a Message workflow step.
- Scroll down to the Headers section, and select the Variables key icon.
- Select the variable you just created.
- Delete the INSERT KEY HERE text, and replace it with the copied workflow variable.
- Save your changes.
Customize the callable workflow
Next, you'll edit the body of the message that gets sent to customers and add any attributes that would be required to mark the conversation done.
- In the workflow editor, select the Send a Message workflow step and scroll down to the Data field.
- In the code block, remove the
INSERT BODY HERE
text and replace it with your preferred messaging. Make sure your entire message remains within quotation marks. - If you have any attributes that are required to mark a conversation done, select the Close the Conversation step and fill in the blank attributes under Required Fields.
- Save your workflow.
Note: To add a line break between any two sentences in the body, add \r\n\r\n
between them.
Create an initialization workflow
With the callable workflow created and customized, you will now need to create a workflow that schedules the callable workflow.
To create the second workflow:
- Go to Settings and select Platform > Workflows.
- Select Add Workflow, and choose Custom Workflow.
- Name the new workflow Chat Auto Close Pt 1, and add a description to help you remember what this workflow does in the future.
- Leave off the Callable Workflow toggle.
- Select Create. The workflow editor will open.
- Open the Workflow Options menu in the toolbar and select Edit Workflow JSON.
- A modal appears where you can edit the code for this workflow. Select and delete all the current JSON code.
- Copy the below code block, and paste it into the JSON text field in your Workflow Editor.
- Then, select Update to save the changes to the workflow and dismiss the JSON editor.
- Select the final step in the workflow, and use the drop-down menu to select Chat Auto Close Pt 2 under Workflow Title.
- Set a timer to however long you want to wait before chats are automatically closed. The default setting is 5 minutes.
{ "description": "", "name": "chat-auto-close-pt-1", "steps": [ { "transitions": [ { "target": "CKFeO2SgM", "condition": { "op": "eq", "values": [ "/#steps.ZhrZRw_EH.status", "open" ] }, "meta": { "name": "Conversation is Open" } } ], "errorCases": [], "id": "ZhrZRw_EH", "action": "kustomer.conversation.find-by-id", "params": { "id": "/#steps.1.conversation" }, "appVersion": "kustomer-^1.9.2" }, { "transitions": [ { "target": "-MsOdSJrY", "condition": { "op": "true", "values": [ true ] } } ], "errorCases": [], "id": "CKFeO2SgM" }, { "transitions": [ { "target": "SC5a5GJIP", "condition": { "op": "eq", "values": [ "/#steps.-MsOdSJrY.userType", "user" ] }, "meta": { "name": "Skip over messages with the Assistant" } } ], "errorCases": [], "id": "-MsOdSJrY", "action": "kustomer.user.find-by-id", "params": { "id": "/#steps.ZhrZRw_EH.assignedUsers" }, "appVersion": "kustomer-^1.9.2" }, { "transitions": [ { "target": "fQBPmRRRD", "condition": { "op": "true", "values": [ true ] } } ], "errorCases": [], "id": "SC5a5GJIP" }, { "transitions": [ { "target": "WqsaGso0t", "condition": { "op": "true", "values": [ true ] } } ], "errorCases": [], "id": "fQBPmRRRD" }, { "transitions": [], "errorCases": [], "id": "WqsaGso0t", "action": "kustomer.app.scheduler.schedule-workflow", "params": { "runAt": { "value": 300, "type": "relative" }, "workflowId": "637552f101c4e5801f2f45d9", "inputs": { "conversationId": "/#steps.1.conversation", "messageCount": "/#steps.ZhrZRw_EH.messageCount" } }, "appVersion": "scheduler-^1.0.1" } ], "trigger": { "transitions": [ { "target": "ZhrZRw_EH", "condition": { "op": "and", "values": [ { "op": "eq", "values": [ "/#steps.1.direction", "out" ] }, { "op": "eq", "values": [ "/#steps.1.channel", "chat" ] } ] }, "meta": { "name": "Outbound Chat Message Only" } } ], "eventName": "kustomer.message.create", "id": "1", "appVersion": "kustomer-^1.9.2" } }
Now that both workflows have been created and saved, toggle on both workflows in the Workflows settings to begin automatically closing abandoned chats.