Conversation
Launch conversation
Kommunicate provides buildConversation function to create and launch conversation directly saving you the extra steps of authentication, creation, initialization and launch. You can customize the process by building the conversationObject according to your requirements.
To launch the conversation you need to create a conversation object. This object is passed to the buildConversation
function and based on the parameters of the object the conversation is created/launched.
Below are some examples to launch conversation in different scenarios:
Launch conversation for visitor
If you would like to launch the conversation directly without the visiting user entering any details, then use the method as below:
dynamic conversationObject = {
'appId': '<APP_ID>',// The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from kommunicate dashboard.
};
KommunicateFlutterPlugin.buildConversation(conversationObject)
.then((clientConversationId) {
print("Conversation builder success : " + clientConversationId.toString());
}).catchError((error) {
print("Conversation builder error : " + error.toString());
});
Launch conversation for visitor with lead collection
If you need the user to fill in details like phone number, emailId and name before starting the support chat then launch the conversation with withPreChat
flag as true. In this case you wouldn't need to pass the kmUser. By this, A screen would open up for the user asking for details like emailId, phone number and name. Once the user fills the valid details (atleast emailId or phone number is required), the conversation would be launched. Use the function as below:
dynamic conversationObject = {
'appId': '<APP_ID>',// The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from kommunicate dashboard.
'withPreChat': true
};
KommunicateFlutterPlugin.buildConversation(conversationObject)
.then((clientConversationId) {
print("Conversation builder success : " + clientConversationId.toString());
}).catchError((error) {
print("Conversation builder error : " + error.toString());
});
Launch conversation with existing user
If you already have the user details then create a kmUser
object using the details and launch the conversation. Use the method as below to create kmUser
with already existing details:
dynamic user = {
'userId' : '<USER_ID>', //Replace it with the userId of the logged in user
'password' : '<PASSWORD>' //Put password here if user has password, ignore otherwise
};
dynamic conversationObject = {
'appId': '<APP_ID>',// The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from Kommunicate dashboard.
'kmUser': jsonEncode(user)
};
KommunicateFlutterPlugin.buildConversation(conversationObject)
.then((clientConversationId) {
print("Conversation builder success : " + clientConversationId.toString());
}).catchError((error) {
print("Conversation builder error : " + error.toString());
});
Note:
jsonEncode
requires the dart packagedart:convert
. Make sure you have imported the package at the top of the dart file asimport 'dart:convert';
Launching chat screen
Open the chat screen by calling the below function:
KommunicateFlutterPlugin.openConversations();
Launching individual chat thread
Open an individual chat thread by calling the below function and passing the clientChannelKey
the clientChannelKey is retrieved from the buildConversation
method "Success"
response message object.
KommunicateFlutterPlugin.openParticularConversation(<CLIENT_CHANNEL_KEY>);
Start a new Conversation
Start a new conversation by using the below function:
dynamic conversationObject = {
'appId': <APP_ID>,
'isSingleConversation' : false
};
KommunicateFlutterPlugin.buildConversation(conversationObject)
.then((result) {
print("Conversation builder success: " + result.toString()); //result.toString() will be the clientChannelKey
}).catchError((error) {
print("Conversation builder error occurred : " + error.toString());
});
Having the list of agentIds and botIds, one can pass it in the below conversation object to create the conversation use the below method:
dynamic conversationObject = {
'appId': <APP_ID>,
'isSingleConversation' : false,
'agentIds':['<AGENT_ID>'], //List of agentIds. AGENT_ID is the emailID used to signup on Kommunicate
'botIds': ['<BOT_ID>'], //List of botIds. Go to Manage Bots(https://dashboard.kommunicate.io/bots/manage-bots) -> Copy botID
'conversationAssignee':'<AGENT_ID/BOT_ID>' /// To set the conversation assignee, pass AgentId or BotId.
};
KommunicateFlutterPlugin.buildConversation(conversationObject)
.then((result) {
print("Conversation builder success: " + result.toString()); //result.toString() will be the clientChannelKey
}).catchError((error) {
print("Conversation builder error occurred : " + error.toString());
});
Note: Refer this to use other paramters for creating the converstion, like metadata etc
Conversation Object
Below are all the parameters that can be used to customize the conversation according to requirements:
Parameters | Type | Description |
---|---|---|
appId | String | The APP_ID obtained from Kommunicate dashboard |
kmUser | kmUser | Optional, Pass the details if you have the user details, ignore otherwise. The details you pass here are used only the first time, to login the user. These login details persist until the app is uninstalled or you call logout. |
withPreChat | boolean | Optional, Pass true if you would like the user to fill the details before starting the conversation. If you have user details then you can pass false or ignore. |
skipConversationList | boolean | Optional: Pass true if you want to skip the conversation list screen and directly open the conversation page. |
isSingleConversation | boolean | Optional, Pass true if you would like to create only one conversation for every user. The next time user starts the conversation the same conversation would open. Pass false if you would like to create a new conversation every time the user starts the conversation. True is recommended for single-threaded conversation. |
messageMetadata | dynamic | Optional. This metadata if set will be sent with all the messages sent from that device. Also, this metadata will be set to all the conversations created from that device. |
agentIds | Array of String | Optional, Pass the list of agents you want to add in this conversation. The agent ID is the email ID with which your agent is registered on Kommunicate. You may use this to add agents to the conversation while creating the conversation. Note that, conversation assignment will be done on the basis of the routing rules set in the Conversation Rules section. Adding agent ID here will only add the agents to the conversation and will not alter the routing rules. |
botIds | Array of String | Optional, Pass the list of bots you want to add in this conversation. Go to bots -> Manage Bots -> Copy botID . Ignore if you haven't integrated any bots. You may use this to add any number of bots to the conversation while creating the conversation. Note that this has no effect on the conversation assignee, as the Conversation Rules set forth in the Dashboard will prevail. |
conversationAssignee | String | Optional, Pass either the agentId or botId. The conversation created will skip the routing rules and will be assigned to this agent or bot. You also need to pass the agentId in agentIds array or botId in the botIds array, if you are using the conversationAssignee parameter. |
clientConversationId | String | Optional, Pass the unique id using which you can recognize the conversation. For e.g If you have a shopping app and each order has its specific conversation, the orderId of the order can be used as a clientConversationId. In this case everyId will have its specific conversation. |
conversationTitle | String | Optional, Pass the custom title for a conversation. Use this if you would like to display a custom title instead of the conversation assignee name. |
launchAndCreateIfEmpty | boolean | Optional, Pass true if you need to create the conversation and launch it. You will receive the clientChannelKey of the created conversation in the success callback function. |
createOnly | boolean | Optional, Pass true if you need to create the conversation and not launch it. In this case you will receive the clientChannelKey of the created conversation in the success callback function. |
Update TeamId
To update the teamId of a conversation, use the below method:
KommunicateFlutterPlugin.updateTeamId({
//'conversationId': <conversation id>,
'clientConversationId': '<client conversation id>',
'teamId': '<team id>'
})
We can pass either conversationID (integer) or clientConversationID (string) in the object. Once team is updated, conversation will be assigned to that team.
Send data to bot platform
You can set the data you want to send to the bot platform by calling the updateChatContext
method as below:
dynamic chatContext = {
'key': 'value',
'objKey': {
'objKey1' : 'objValue1',
'objKey2' : 'objValue2'
}
};
KommunicateFlutterPlugin.updateChatContext(chatContext);
Get Unread Count
To get unreadCount of a user, use this method after the user has been logged in:
KommunicateFlutterPlugin.unreadCount()
.then((result) {
print("Unread count is : " + result.toString());})
Rich Message
Rich message provide a better overall conversational experience to the users, make the interface look pretty, they also drive more actions from your users and provide a good conversational experience. There are a variety of response types to choose from. For example, you can show images, play videos, provide buttons, list, forms, or card carousels.
Refer the following link to use rich messages in Kommunicate.