Conversation
Launch Conversation List screen
You can open the Conversation List screen by calling the below function:
RNKommunicateChat.openConversation((response, message) => {
if(response == 'Error') {
console.log(message);
} else {
//chat screen launched successfully
}
});
Launch particular conversation
You can open a particular conversation by calling the below function and passing the clientChannelKey
the clientChannelKey is which you got from the buildConversation
method "Success"
response message object.
let clientChannelKey = "clientChannelKey" //pass the clientChannelKey here
let takeOrder = true //skip chat screen on back press, pass false if you want to show chat screen on back press
RNKommunicateChat.openParticularConversation(clientChannelKey, takeOrder, (response, responseMessage) => {
if(response == 'Error') {
console.log(message);
} else {
//conversation launched successfully
}
});
Start a new Conversation
You can start a new conversation by using the below function:
let conversationObject = {
'isSingleConversation' : true //passing true will start the same conversation everytime
};
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Kommunicate create conversation successful the clientChannelKey is : " + responseMessage);
} else {
console.log("Kommunicate create conversation failed : " + responseMessage);
}
});
If you have the list of agentIds and botIds, you can pass it in the below conversation object for create the conversation use the below method:
var conversationObject = {
'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': '<AGENI_ID / BOT_ID> ' //Should be either an agent Id or a botId. If set, will assign the conversation to the agent or bot thus skipping the routing rules set in the dashboard.
};
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Kommunicate create conversation successful the clientChannelKey is : " + responseMessage);
} else {
console.log("Kommunicate create conversation failed : " + responseMessage);
}
});
Start a Unique Conversation
You can create a unique conversation using the below method. A unique conversation is identified by the list of agentIds and botIds used to create the conversation. If the same set of Ids are passed to the below method, then the already created conversation would be returned instead of creating a new conversation:
var conversationObject = {
'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
};
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Kommunicate create conversation successful the clientChannelKey is : " + responseMessage);
} else {
console.log("Kommunicate create conversation failed : " + responseMessage);
}
});
Note: Refer this if you want to use other paramters for creating the converstion, like metadata etc
Launch Conversation
Following functions are to create and launch conversation directly saving you the extra steps of authentication, creation, initialization and launch
Launch Conversation for visitor
If you would like to launch the chat directly without the visiting user entering any details, then use the method as below:
let conversationObject = {
'appId' : '<APP_ID>' // The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from kommunicate dashboard.
}
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Conversation Successfully with id:" + responseMessage);
}
});
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 chat with withPreChat
flag as true. In this case you wouldn't need to pass the kmUser. 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 chat would be launched. Use the function as below:
let conversationObject = {
'appId' : '<APP_ID>', // The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from kommunicate dashboard.
'withPreChat' : true
}
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Conversation Successfully with id:" + responseMessage);
}
});
Launch Conversation with existing user
If you already have the user details then create a KMUser object using the details and launch the chat. Use the method as below to create KMUser with already existing details:
let 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
}
let conversationObject = {
'appId' : '<APP_ID>', // The [APP_ID](https://dashboard.kommunicate.io/settings/install) obtained from kommunicate dashboard.
'kmUser' : JSON.stringify(user)
}
RNKommunicateChat.buildConversation(conversationObject, (response, responseMessage) => {
if(response == "Success") {
console.log("Conversation Successfully with id:" + responseMessage);
}
});
Note: If login is not made already, you can use this function to login & open the conversation.
If you have a different use-case and would like to customize the chat creation, user creation and chat launch, you can use more parameters in the conversationObject.
Below are all the parameters you can use to customize the conversation according to your requirements:
Parameter | 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 persists 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 chat. If you have user details then you can pass false or ignore. |
isSingleConversation | boolean | Optional, Pass true if you would like to create only one conversation for every user. The next time user starts the chat the same conversation would open, false if you would like to create a new conversation everytime the user starts the chat. True is recommended for single chat |
messageMetadata | Any | Optional. This metadata if set will be sent with all the messages sent from that device. Also this metadata will be set to 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 |
teamId | String | Optional, Pass this teamId so that the conversation created will skip the routing rules and will be assigned to this team. |
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. |
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. |
Conversation Default Settings
Kommunicate provides some parameters to configure the conversation rules when it is created. These parameters can be used to override the conversation rules you have set from the dashboard. You can set it by following codes. The setting will be effective from the next conversation user created by clicking "Create New Conversation" Button on Conversation List Screen.
let settingsObject = {
'defaultAssignee': '<>',
'teamId':'<>',
'defaultAgentIds':'<List of Agent IDs>',
'defaultBotIds':'<List Of bot ids>',
'skipRouting':true
}
RNKommunicateChat.updateDefaultSetting(settingsObject, (response: string, responseMessage: string) => {
console.log(response + responseMessage);
});
Note: skipRouting
should be set to true for this settings to override the routing rules set on dashboard.
Send Message
Send Text Message
You can send a message programatically using the send message function. Use the below code to send a simple text message to a user.
The message object should include the channel_ID and message properties as mandatory, with an optional messageMetadata field.
var messageObject = {
'channelID': '<CHANNEL_ID>',
'message': 'Hi, this is a sample message',
'messageMetadata': JSON.stringify({
'MOBILE_NUMBER': '00000000',
'<KEY>': '<VALUE>'
})
};
Function to execute the sendMessage action.
RNKommunicateChat.sendMessage(msg, (response: string, responseMessage: string) => {
if (response === "Success") {
console.log("Message sent successfully, clientChannelKey: " + responseMessage);
} else {
console.log("Message send failed: " + responseMessage);
}
});
Update TeamId
You can update the Team Id of the conversation by using below function.
RNKommunicateChat.updateTeamId({
'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.
Update Conversation Info
You can update the conversation info by using below function.
let conversationObject = {
'clientConversationId' : '<Client Conversation id>',
'conversationInfo': {
"test1": "value1",
"test2": "value2"
}
}
RNKommunicateChat.updateConversationInfo(conversationObject, (response: string, responseMessage: string) => {
console.log(response + responseMessage);
});
This updated conversation info can be seen by agent on Kommunicate Dashboard.
Update Conversation Assignee
You can update the conversation assignee by using below function. You need assigne id, client conversation id to use this function.
let assigneeObject = {
'clientConversationId' : '<Client Conversation id>',
'conversationAssignee' : '<assignee id>'
}
RNKommunicateChat.updateConversationAssignee(assigneeObject, (response: string, responseMessage: string) => {
console.log(response + responseMessage);
});
Fetch Unread Count
You can get the unread count for the user by using the below function.
RNKommunicateChat.fetchUnreadCount((response: string, responseMessage: String) => {
console.log("unread count: ",responseMessage);
});
Note: This function will return unread count value for the user. If user has multiple conversations, it will consider all the conversations unread count value.
Fetch Conversation Info
You can fetch the conversation information by using conversation id(numerical) or client conversation id(String) in the below function.
If you have conversation id then map it with conversationID
key and pass it to the below function.
If you have client conversation id then map it with clientConversationID
key and pass it to the below function.
let conversationObject = {
'conversationID' : '<Conversation ID(Numerical Value)>'
}
RNKommunicateChat.fetchConversationInformation(conversationObject, (response: string, responseMessage: string) => {
if(response == "Success") {
console.log("Fetched conversation info Successfully!. Details: " + responseMessage);
} else {
console.log(response,responseMessage);
}
});
Fetch Assignee Details
You can fetch the conversation assignee information by using conversation id(numerical) or client conversation id(String) in the below function.
If you have conversation id then map it with conversationID
key and pass it to the below function.
If you have client conversation id then map it with clientConversationID
key and pass it to the below function.
let conversationObject = {
'conversationID' : '<Conversation ID(Numerical Value)>'
}
RNKommunicateChat.fetchConversationAssigneeInfo(conversationObject, (response: string, responseMessage: string) => {
if(response == "Success") {
console.log("Fetched Assignee info Successfully!. Details: " + responseMessage);
}
});
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.