Customer Typing API
The the CustomerTypingAPI call is used to let the agent know when the customer starts or stops typing.
The API method for sending the customer typing status is exposed from the NuanMessaging class.
NuanMessaging nuanMessaging = NuanMessaging.getInstance();
Public Methods
Use the public methods shown here from the NuanMessaging Class to send customer typing status message to the agent.
-
public void sendCustomerTypingStatus(boolean isTyping, OnErrorListener error) throws IllegalStateException
Send customer typing status to agent. Starting and stopping are distinguished by value of the parameter isTyping=true or isTyping=false. OnErrorListener.onErrorResponse will be invoked if there an error while sending this request. Error listener param is optional.
-
public void sendCustomerTypingStatus(boolean isTyping) throws IllegalStateException
Send customer typing status to agent.
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.
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(isTyping == false && count>0 && NuanMessaging.getInstance().getEngagementID() != null) {
isTyping = true;
sendTypingStatus(isTyping);
}
handler.removeCallbacks(input_finish_checker);
}
@Override
public void afterTextChanged(Editable s) {
if(textWatcher != null) {
textWatcher.afterTextChanged(s);
}
if (NuanMessaging.getInstance().getEngagementID() != null) {
last_text_edit = System.currentTimeMillis();
handler.removeCallbacks(input_finish_checker);
handler.postDelayed(input_finish_checker, delay);
}
}
});
private Runnable input_finish_checker = new Runnable() {
public void run() {
if (System.currentTimeMillis() > (last_text_edit + delay - 500)) {
isTyping = false;
if(NuanMessaging.getInstance().getEngagementID() != null) {
sendTypingStatus(isTyping);
}
}
}
};
private void sendTypingStatus(boolean status) {
NuanMessaging.getInstance().sendCustomerTypingStatus(status);
}