Get Message API
The purpose of the GetMessageAPI is to give clients a way to monitor the status of the engagement and to fetch new agent messages.
GetMessageAPI is a singleton class, Get the instance of getMessageAPI by using the code shown here.
NuanMessaging nuanMessaging = NuanMessaging.getInstance();
GetMessageAPI getMessageAPI = nuanMessaging.getMessageAPIInstance();
Public Methods
-
public void getMessages(final OnSuccessListener<GetMessageResponse> success, OnErrorListener errorListener)
Initiate the getMesasge pooling request to the Nuance Messaging System. The OnSuccessListener.onResponse value is invoked each time there is a new message from the Nuance Messaging Servers.
-
public void cancelGetMessages()
Cancels the getMessage pooling request when activity goes into the background, such as for the In Activity onStop lifecycle method. This is required for optimizing battery usage.
-
public void restartGetMessages()
Invoking this method restarts the getMesasge pooling request to the Nuance Message Servers. This method must be called inside the onRestart Activity life cycle method. This is to let the SDK GetMessageAPI module know that activity is returning to a visible state from onStop.
-
public void getMessageInBackground()
This method must be called when activity is about to shut down, such as in the onDestroy method. This way the agent continue to remain in the conversation and the app can receive messages in the background. SDK will start a service that will continue to fetch agent messages. This service fires a broadcase for every new message it receives.
-
public void restartGetMessages(boolean needPreviousTranscript, OnSuccessListener
success, OnErrorListener errorListener) This method must be called when messaging activity is recreated, such as when messaging Activity is launched from a pending Intent(Notification). By passing True for needPreviousTranscript arguments ensures that all the previous transcript messages are retreived.
GetMessageResponse
Public Methods
-
public MessageTypes getMessageType()
Possible Message Types are.
MessageTypes.TYPE_CHATLINE
MessageTypes.TYPE_STATECHANGE
MessageTypes.TYPE_CHATAUTHORIZED
MessageTypes.TYPE_AUTOMATION_REQUEST
MessageTypes.TYPE_MEMBER_CONNECTED
MessageTypes.TYPE_COMMAND
MessageTypes.TYPE_MEMEBER_LOST
-
public Object getProperty(String name)
Below table list the properties that can be present in a GetMessageResponse. Pass the property name to retreive its value.
Name Value Type Description agentName Name of agent assigned to this engagement string Agent name agentIsTyping-state true/false boolean Indicates the agent is currently typing a response. agentID Numeric ID of the agent assigned string The unique identifier of the agent (same as agent login ID) command pushURL string A pushURL command is sent from Message sender string This field contains the recommended customer facing agent name (typically presented something like “Jim: How can I help you?” where Jim is the agent name presented to the customer message Tag to wrap the content of each message Indicates a new agent message is included messageText Chat line text string The actual agent text/message messageType chatLine | command | stateChange | chatroom.member_connected | chatroom.member_lost string Type of message that is being returned. When the “stateChange” message type is received, you will also receive the “state” field indicating what state was changed. When the “command” message type is received, you will also receive the “command” field indicating what command was sent. queueDepth Number of customers ahead of you in queue number Queue depth is provided when state is queued. sequenceNumber Sequence number of this message number The client application can use the sequence number to ensure that messages are displayed in the correct order state queued | assigned | closed | agentIsTyping| transfer | conference string The current status of the engagement. This field presents only if messageType = stateChange url URL of page sent string When messageType is command this field will be included and contain the URL to be pushed in the customer’s browser waitTime Estimated wait time in seconds number Estimated wait time is provided when state is queued. Other parameters what returns from CR Name Example Message types where this parameter appears agent.alias
<agent.alias>Agent</agent.alias>
<messageType
>stateChange</messageType>
<state>assigned</state>, <messageType>chatLine</messageType>,<messageType
>chatroom.member_connected</messageType>
business_unit.id
<business_unit.id>22</business_unit.id>
<messageType
>stateChange</messageType>
<state>assigned</state>,<messageType
>chatroom.member_connected</messageType>
chatroom.chat_id
<chatroom.chat_id>7657620082880181644</chatroom.chat_id
>
<messageType
>chatroom.member_connected</messageType>, <messageType>chatroom.member_lost</messageType>
chatroom.member.name
<chatroom.member.name>1</chatroom.member.name>
<messageType
>chatroom.member_connected</messageType>
chatroom.member.id
<chatroom.member.id>1</chatroom.member.id>
<messageType
>chatroom.member_connected</messageType>, <messageType>chatroom.member lost</messageType>
chatroom.member
.type
<chatroom.member
.type>agent</chatroom.member.type>
<messageType
>chatroom.member_connected</messageType>, <messageType>chatroom.member_lost</messageType>
chatrouter
.address
<chatrouter
.address>192.168.0.20</chatrouter.address>
<messageType
>stateChange</messageType>
<state>assigned</state>client.display.text
<client.display.text>Agent has left the chat&nl;You are being
transferred, please hold...</client.display.text>
<messageType
>stateChange</messageType>
<state>transfer</state>,<messageType
>chatroom.member_connected</messageType>
cobrowse.enabled
<cobrowse.enabled>true</cobrowse.enabled>
<messageType
>stateChange</messageType>
<state>assigned</state>display.text
<display.text>Agent is typing...</display.text> <messageType
>stateChange</messageType>
<state>agentIsTyping</state>,<messageType
>chatroom.member_connected</messageType>, <messageType>chatroom.member_lost</messageType>,
<messageType
>stateChange</messageType>
<state>closed</state>escalate
<escalate>false</escalate>
<messageType
>stateChange</messageType>
<state>closed</state>event.agent_first_name
<event.agent_first_name>User First Name</event.agent_first_name>
<messageType
>stateChange</messageType>
<state>assigned</state>,<messageType
>chatroom.member_connected</messageType>
event.agent_last_name
<event.agent_last_name>User Last Name</event.agent_last_name
>
<messageType
>stateChange</messageType>
<state>assigned</state>,<messageType
>chatroom.member_connected</messageType>
exit
<exit>true</exit>
<messageType>chatroom.member_lost</messageType> host.node.id
<host.node.id>192.168.0.20
</host.node.id>
<messageType
>stateChange</messageType>
<state>assigned</state>,<messageType
>stateChange</messageType>
<state>transfer</state>msg.originalrequest.id
<msg.originalrequest.id>5722840798275623
</msg.originalrequest.id>
<messageType
>stateChange</messageType>
<state>assigned</state>,<messageType
>stateChange</messageType>
<state>transfer</state>owner
<owner>true</owner>
<messageType
>chatroom.member_connected</messageType>
reason
<reason>Transfer accepted and sent to 1</reason>
<messageType
>stateChange</messageType>
<state>transfer</state>screening
<screening>true</screening>
<messageType
>chatroom.member_connected</messageType>
script.id
<script.id>200023</script.id>
<messageType>chatLine</messageType> tc.mode <tc.mode>transfer</tc.mode>
<messageType
>chatroom.member_connected</messageType>,
<messageType>chatroom.member_lost</messageType>,<messageType
>stateChange</messageType>
<state>closed</state>type
<type>2</type>
<messageType
>stateChange</messageType>
<state>agentIsTyping</state>user.id
<user.id>2</user.id>
<messageType
>stateChange</messageType>
<state>agentIsTyping</state>
Response
OnErrorListener.onErrorResponse method receives an instance of Response class.
Public Methods
-
public int getStatusCode()
getStatusCode method returns following values which denotes the status of this request.
400: Request has incorrect parameters.
401: There is no such chat on server,chat should be started anew.
403: The user does not have sufficient privileges to use the API or to access the requested site.
500: Server error.
Agent New Message BroadCast
If App is coded to receive messages in background by calling getMessageInBackground() method in onDestroy. SDK notfies the app with the following broadcast action when ever there is a new agent message.
Action: com.nuance.chat.NEW_MESSAGE
Message payload can be retrieved by calling getStringExtra("message").
NuanMessaging nuanMessaging;
GetMessageAPI getMessageAPI;
protected void onCreate(Bundle savedInstanceState){
nuanMessaging = NuanMessaging.getInstance();
getMessageAPI = nuanMessaging.getMessageAPIInstance();
if(!nuanMessaging.isChatInProgress()) {
//create engagement
//After successfull create engagement
getMessageAPI.getMessages(getMessageListener, getMessageListener);
} else {
if(savedInstanceState != null){
//during orientation change you can reuse the fragment instance by saving it.
//so there is no need to get full transcript
getMessageAPI.restartGetMessages(false, getMessageListener, getMessageListener);
} else {
getMessageAPI.restartGetMessages(true, getMessageListener, getMessageListener);
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "messageListFrag", transcriptFragment);
}
@Override
protected void onRestart() {
super.onRestart();
if(nuanMessaging.isChatInProgress()){
getMessageAPI.restartGetMessages();
}
}
@Override
protected void onStop() {
super.onStop();
getMessageAPI.cancelGetMessages();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(nuanMessaging.isChatInProgress() && isChangingConfigurations() == false) {
getMessageAPI.getMessageInBackground();
}
}
class GetMessageListener implements OnSuccessListener<GetMessageResponse>, OnErrorListener {
@Override
public void onResponse(GetMessageResponse response) {
}
@Override
public void onErrorResponse(Response response) {
Log.e("Nuance Chat","Get Messages:error code:"+response.getStatusCode());
}
}