> For the complete documentation index, see [llms.txt](https://docs.flexmoney.uk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flexmoney.uk/documentation/docs/conversation.md).

# 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": [""],
    "defaultBotIds": [""], 
    "defaultAssignee": "", 
    "skipBotEvent": '[""]', 
    "skipRouting": true,
    "teamId": <TEAM_ID> 
};    
Kommunicate.updateSettings(defaultSettings);  

```

Below is the detail about the supported parameters:

| Parameters       | Type    | Default value                                       | Descriptions                                                                                                                                                                                                                                                                                                                                            |
| ---------------- | ------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| defaultAssignee  | string  | Configured routing rules for agents from dashboard  | <p>You need to pass the agentId/botId. If nothing is passed the default agent will automatically get selected.<br> NOTE: You need to pass "skipRouting": true with defaultAssignee parameter if you have assigned a default assignee from the <a href="https://dashboard.kommunicate.io/settings/conversation-rules">conversation rules</a> section</p> |
| defaultAgentIds  | array   | Configured routing rules for agents from dashboard  | You can pass the default agents that you want to be present in every new conversation created.                                                                                                                                                                                                                                                          |
| defaultBotIds    | array   | Configured routing rules for bots from dashboard    | You can pass the default bots that you want to be present in every new conversation created.                                                                                                                                                                                                                                                            |
| WELCOME\_MESSAGE | string  | Configured from dashboard                           | <p>You can pass the default welcome message here and it will override the welcome message which you have set from dashboard.<br> NOTE: It will not override the welcome message sent by your bot.</p>                                                                                                                                                   |
| skipRouting      | boolean | false                                               | If you pass this value true then it will skip routing rules set from [conversation rules](https://dashboard.kommunicate.io/settings/conversation-rules) section.                                                                                                                                                                                        |
| skipBotEvent     | array   | None                                                | You can pass the bot event names that you want to skip in every new conversation created. Read more about bot events [here](https://docs.kommunicate.io/docs/bot-configration#bot-events)                                                                                                                                                               |
| teamId           | number  | All conversations will be assigned to default team. | <p>Assign conversations to a particular team by passing teamId and the conversation assignment will be based your assigned team rules.<br>Get team ID from <a href="https://dashboard.kommunicate.io/settings/team">teammates section</a></p>                                                                                                           |

#### Example : Assigning conversations to a specific bot/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 another agents or bots. 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:

```


var defaultSettings = {
    "defaultAgentIds": [""], 
    "defaultBotIds": [""], 
    "defaultAssignee": "", 
    "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 ?

1. Initially, if there are no previous conversations, then it will create a new conversation and open it.
2. If you have old/previous conversations, it will open the conversation list.

### Assign different bot to different website pages

In order to change widget's default settings like default bots in conversation and default assignee, you need to create `defaultSettings` object with two parameters, `defaultBotIds` containing `list of bot ids` which you wish to add in conversation, `defaultAssignee` having `string` value to the agent/bot which you wish to assign conversation by default.

```
(function(d, m){
    
    var defaultSettings = {
    "defaultBotIds": [""], 
    "defaultAssignee": "", 
    "skipRouting":true
    };
    var kommunicateSettings = {
        "appId":"",  
        "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/v2/kommunicate.app";
    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": "" 
    };
    var kommunicateSettings = {
        "appId":"",  
        "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/v2/kommunicate.app";
    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.

```

Kommunicate.startConversation(); 
```

> Note: You have to set "automaticChatOpenOnNavigation" parameter to false as this option won't be compatible with startConversation method.

```

var conversationDetail = {
    "defaultGroupName": "", 
    "agentIds": [""], 
    "botIds": [""], 
    "skipRouting":"true", 
    "assignee":" or " 
};
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](/documentation/docs/conversation.md#conversation-settings) object. It can be helpful to set conversation rules dynamically. Refer to below example :

```
var defaultSettings = {
    "defaultBotIds": [""], 
    "defaultAssignee": "", 
    "skipRouting": true
};
Kommunicate.updateSettings(defaultSettings); 


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();
```

### 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": "",
        "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](https://dashboard.kommunicate.io/settings/chat-widget-customization#chat-widget-security) where all the existing info and previous messages will be removed from the chat widget after a set period of time.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flexmoney.uk/documentation/docs/conversation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
