Conversation
Overview
This section is dedicated to launching and managing conversations in the chat widget on certain triggers. For example, the chat widget will only appear on the website on click of a specific button. This could be useful if you wish to show support chat only on certain triggers and not all the time.
Conversations
Conversation Settings
Kommunicate provides some parameter to configure the conversation rules when it is created. These parameters can be used to override the conversation rules you have set from dashboard. These parameters can be set using the Kommunicate.updateSettings() methods.
The updated setting will be effective from the next conversation user creates by either clicking on the Start new conversation on chat widget or calling the Kommunicate.startConversation().
Below is the sample code to update the conversation setting:
var defaultSettings = {
"defaultAgentIds": ["<AGENT_ID>"],
"defaultBotIds": ["<BOT_ID>"], // Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"defaultAssignee": "<BOT_ID>", // Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"skipBotEvent": '["<EVENT_NAME>"]', // Replace <EVENT_NAME> with the AI agent platform event names which you want to skip
"skipRouting": true,
"teamId": <TEAM_ID> // Replace <TEAM_ID> with with team ID which you can find in teammates section of dashboard
};
Kommunicate.updateSettings(defaultSettings);
Below is the detail about the supported parameters:
| Parameters | Type | Default value | Descriptions |
|---|---|---|---|
| defaultAssignee | string | Configured routing rules for human agents from dashboard | You need to pass the human agent ID or AI agent ID. If nothing is passed the default human agent will automatically get selected. NOTE: You need to pass "skipRouting": true with defaultAssignee parameter if you have assigned a default assignee from the conversation rules section |
| defaultAgentIds | array | Configured routing rules for human agents from dashboard | You can pass the default human agents that you want to be present in every new conversation created. |
| defaultBotIds | array | Configured routing rules for AI agents from dashboard | You can pass the default AI agents that you want to be present in every new conversation created. |
| WELCOME_MESSAGE | string | Configured from dashboard | You can pass the default welcome message here and it will override the welcome message which you have set from dashboard. NOTE: It will not override the welcome message sent by your AI agent. |
| skipRouting | boolean | false | If you pass this value true then it will skip routing rules set from conversation rules section. |
| skipBotEvent | array | None | You can pass the AI agent event names that you want to skip in every new conversation created. Read more about AI agent events here |
| teamId | number | All conversations will be assigned to default team. | Assign conversations to a particular team by passing teamId and the conversation assignment will be based your assigned team rules. Get team ID from teammates section |
Example : Assigning conversations to a specific AI agent/human agent on certain events
Usecase: A user comes to your website and starts a conversation with support agents. When user navigates to another page you wants to start conversation with other human agents or AI agents. You can achieve this by updating the conversation rules dynamically. Set the appropriate values in above mentioned parameters and Kommunicate will use these parameters while creating the conversation. You can update the empty values when user navigate to previous page to make old conversation rules(set from dashboard) effective. Below is the sample code for the same:
// Example : Adding AI agent as a default assignee
var defaultSettings = {
"defaultAgentIds": ["<AGENT_ID>"], // Optional. Replace <AGENT_ID> with human agents email id. Include this parameter if you want to assign the conversation to a human agent.
"defaultBotIds": ["<BOT_ID>"], // Optional. Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard. Include this parameter if you want to assign the conversation to an AI agent.
"defaultAssignee": "<ASSIGNEE_ID>", // Replace <ASSIGNEE_ID> with your AI agent/human agent ID whom you're assigning the conversation.
"skipRouting": true
};
Kommunicate.updateSettings(defaultSettings);
Launch conversation List
To launch the chat widget and conversation list, use the following method.
Kommunicate.launchConversation();
How it works ?
- Initially, if there are no previous conversations, then it will create a new conversation and open it.
- If you have old/previous conversations, it will open the conversation list.
Assign different AI agent to different website pages
In order to change widget's default settings like default AI agents in conversation and default assignee, you need to create defaultSettings object with two parameters, defaultBotIds containing list of AI agent ids which you wish to add in conversation, defaultAssignee having string value to the human agent/AI agent which you wish to assign conversation by default.
(function(d, m){
/*---------------- Kommunicate settings start ----------------*/
var defaultSettings = {
"defaultBotIds": ["<BOT_ID>"], // Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"defaultAssignee": "<BOT_ID>", // Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"skipRouting":true
};
var kommunicateSettings = {
"appId":"<APP_ID>", // Replace <APP_ID> with your APP_ID which you can find in install section of dashboard
"automaticChatOpenOnNavigation":false,
"onInit": function() {
Kommunicate.updateSettings(defaultSettings);
}
};
/*----------------- Kommunicate settings end ------------------*/
var s = document.createElement("script");
s.type = "text/javascript"; s.async = true;
s.src = "https://widget.kommunicate.io/kommunicate-widget-3.0.min.js";
var h = document.getElementsByTagName("head")[0];
h.appendChild(s);
window.kommunicate = m;
m._globals = kommunicateSettings;
})(document, window.kommunicate || {});
Initiate conversation with specific team
To start a conversation with a specific team, one can create defaultSettings object with teamId parameter. These parameters can be set using the Kommunicate.updateSettings() method.
Below is the sample code to update the conversation setting:
(function(d, m){
var defaultSettings = {
"teamId": "<TEAM_ID>" // Replace <TEAM_ID> with with team ID which you can find in teammates section of dashboard
};
var kommunicateSettings = {
"appId":"<APP_ID>", // Replace <APP_ID> with your APP_ID which you can find in install section of dashboard
"automaticChatOpenOnNavigation":false,
"onInit": function() {
Kommunicate.updateSettings(defaultSettings);
}
};
var s = document.createElement("script");
s.type = "text/javascript"; s.async = true;
s.src = "https://widget.kommunicate.io/kommunicate-widget-3.0.min.js";
var h = document.getElementsByTagName("head")[0];
h.appendChild(s);
window.kommunicate = m;
m._globals = kommunicateSettings;
})(document, window.kommunicate || {});
Create a new conversation
A conversation can be created using startConversation method. Below is the example code for the same. You can choose to define certain parameters to profile this conversation and allot assignee.
// Below function will create a conversation using default conversation rules.
Kommunicate.startConversation();
Note: You have to set "automaticChatOpenOnNavigation" parameter to false as this option won't be compatible with startConversation method.
// Below function will create a conversation using parameters which you're passing in conversationDetail variable.
var conversationDetail = {
"defaultGroupName": "<DEFAULT_GROUP_NAME>", // Optional. To give a specific title to the conversation, replace "<DEFAULT_GROUP_NAME>" with the title you prefer. By default, the group title will be the name of the conversation assignee.
"agentIds": ["<AGENT_ID>"], // Optional. If you do not pass any agent ID, the default agent will automatically get selected.
"botIds": ["<BOT_ID>"], // Optional. Pass the AI agent IDs you want to add in this conversation.
"skipRouting":"true", // Optional. If this parameter is set to 'true', then routing rules will be skipped for this conversation.
"assignee":"<BOT_ID> or <AGENT_ID>" // Optional. You can assign this conversation to any human agent or AI agent. If you do not pass the ID. the conversation will assigned to the default human agent.
"conversationMetadata": {
"key1": "value1",
"key2": "value2",
}, // Optional. If any metadata needs to be add in the conversation.
};
Kommunicate.startConversation(conversationDetail, function (response) {
console.log("new conversation created");
});
Note: If called with empty parameters it will inherits the conversation rules from conversation settings object. It can be helpful to set conversation rules dynamically. Refer to below example :
var defaultSettings = {
"defaultBotIds": ["<BOT_ID>"], // Optional. Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"defaultAssignee": "<BOT_ID>", // Optional. Replace <BOT_ID> with your AI agent ID which you can find in AI agent section of dashboard
"skipRouting": true
};
Kommunicate.updateSettings(defaultSettings);
//Pass the empty parameter to use the default conversation setting.
Kommunicate.startConversation();
Open a particular conversation
If you wish to open a particular conversation, pass the group ID of that conversation by using the method mentioned below:
Kommunicate.openConversation(<GROUP_ID>);
Open chat window when a new message comes
If you want the chat window to pop open when a new conversation comes, add "openConversationOnNewMessage": true in kommunicateSettings object. This will open the chat window when a new message comes.
var kommunicateSettings = {
...
"appId": "<APP_ID>",
"openConversationOnNewMessage":true
...
};
Start a new session every time a user visits again
Kommunicate expires the user session if a user is anonymous and inactive for 30 days. If a user comes back to your website within 30 days then the old conversations of the user will be visible. If you want to start a new session every time user comes to your website then change the settings in the kommunicate dashboard where all the existing info and previous messages will be removed from the chat widget after a set period of time.
Conversation Info
Pass the conversation information as a JSON metadata, this will be displayed to the human agents on the Kommunicate dashboard.
Examples below:
A car marketplace support chat inquiry about a car model will pass the additional details about the car model.
Below is the function to update the conversation info:
var conversationInfo =
{
groupId: "<GROUP_ID>", //Replace <GROUP_ID> with your <GROUP_ID> value
metadata: {
"key1": "value1",
"key2":"value2"
}
};
Kommunicate.updateConversationMetadata(conversationInfo);
Note: "GROUP_ID" can be fetched from "KommunicateGlobal.CURRENT_GROUP_DATA.tabId".