Class: Chat
Overview
Variables Summary
- EVENTS =
-
{ MESSAGES: 'messages', MESSAGES_WITH_STATUS_UPDATES: 'messages-with-status-updates', OPERATOR_TYPING_STATUS_UPDATE: 'operator-typing-status-update' }
- SENDERS =
-
{ VISITOR: 'visitor', OPERATOR: 'operator' }
Instance Method Summary
- # (void) addEventListener(type, listener) This method allows registration of event listeners on the Chat.
- # (void) removeEventListener(type, listener) This method allows the removal of event listeners from the Chat.
- # (void) sendMessagePreview(message) Send a message preview to the Operator.
- # (void) sendMessage(message) Send a chat message to the Operator.
Instance Method Details
#
(void)
addEventListener(type, listener)
This method allows registration of event listeners on the Chat.
If a listener is added while the Chat is processing an event, it will be not triggered with the current event.
If multiple identical listeners are registered on the same event type the duplicate instances are discarded. They do not cause the listener to be called twice and do not need to be removed with the removeEventListener method.
#
(void)
removeEventListener(type, listener)
This method allows the removal of event listeners from the Chat.
If an event listener is removed while the Chat is processing an event, it will not be triggered with the current event.
An event listener is never invoked after being removed.
Calling removeEventListener with arguments which do not identify any currently registered listener has no effect.
#
(void)
sendMessagePreview(message)
Send a message preview to the Operator.
The latest preview message will always be visible to the Operator. This means that Operators can use the preview messages as an indication of Visitor activity. The Operator could also use the preview messages to start preparing a response before the Visitor finishes typing, ensuring a fast and seamless communication experience.
Examples:
Sending message previews using an input field
var chatInput = document.querySelector('#chat-input');
chatInput.addEventListener('keyup', function(event) {
engagement.chat.sendMessagePreview(event.target.value);
});
#
(void)
sendMessage(message)
Send a chat message to the Operator.
Examples:
Sending a message using enter key
var chatInput = document.querySelector('#chat-input');
chatInput.addEventListener('keypress', function(event) {
// Send message on enter
if (event.keyCode === 13) {
engagement.chat.sendMessage(event.target.value);
// clear previous message from the input
event.target.value = '';
}
});