Chat
ViewController
For a consultant to work, you need to register a ViewController with the name consultant.
Important: ViewController is registered once for all the online consultant forms.
CreateWidget
To create a chat widget, you need to call the method CallGear.UI.createWidget() with the following parameters:
widgetName= 'consultant_chat'
Example
CallGear.UI.registerViewController('consultant', function (settings, tpls) {
...
var chat = CallGear.UI.createWidget('consultant_chat', {
settings: settings,
template: tpls['chat'],
...
});
...
chat.render();
});
Method
startChat()
Chat initiation by a visitor. At this moment, a visitor will get the "Waiting" status.
chat.on('show', function(){
chat.startChat();
});
When the form is opened, the show event is activated and the startChat() method is called.
closeChat()
The completion of the chat initiated by a visitor. The visitor will get the "On site" status.
chat.on('beforehide', function(){
chat.closeChat();
});
Before the form is hidden, the closeChat() method is called.
isChatAvailable()
Checks if there is an operator with the status "online" in the current chat.
Returns true or false.
sendChatByMail(mail: string)
Sends the correspondence history to an e-mail.
sendChatMessage(message: string)
Sends a message from a website visitor.
setOperatorRating(mark: number)
The method saves the mark that a visitor gave to an operator in the current chat.
hasHistory()
Checks for message history. Returns true or false.
if (chat.hasHistory()) {
var history = chat.getHistory();
}
Check for message history. If it exists, then we request it.
getHistory()
Request message history. Up to 20 messages per request. Returns an array of messages or false if there are no messages.
if (chat.hasHistory()) {
var history = chat.getHistory();
}
getOperatorVcard()
The method returns an object containing information about the operator of the current chat. The object contains the following fields:
- name - operator name
- position - operator position
- avatar - link to the operator's photo
getVisitorCard()
The method returns an object containing information about a visitor. The object may contain the following fields:
- name - visitor name
- email - an array containing up to five e-mails specified earlier by a customer
- phone - an array containing up to five phone numbers specified earlier by a customer
setVisitorCard(vcard)
The method stores information about the visitor. The vcard object may contain the following fields:
- name - visitor name
- email - visitor e-mail
- phone - visitor phone number
inviteAccept()
Invitation to chat accepted.
inviteReject()
Invitation to chat rejected.
sendFile(input)
Sending files to chat.
isReadyForFileTransfer()
Method that will return true when you can send a file.
getRequiredInfo()
The method returns an array of visitor card field names that must be requested the next time the personal data form is shown.
getState()
The method returns the current status of a visitor.
Valid values:
- available - visitor is on the website, not interacting with widgets.
- invite - visitor received an invitation to a chat.
- chat - visitor is talking to the chat operator.
- lead - the lead generator form is displayed.
chatTyping(text: string)
The method sends text to the operator workspace as a message typed by the visitor.
Events
operatorjoined
The event occurs when an operator joins the chat.
operatorjoined event properties:
Object containing the following fields:
- name - operator name.
- position - operator position.
- avatar - link to the operator's photo.
operatorleave
The event occurs when an operator leaves the chat.
operatorleave event properties:
Fields similar to the operatorjoined event, containing null.
sendmessage
The event is triggered when a chat message is received. It can be a message from the chat operator, a system message, or a message from the customer sent from another website page.
sendmessage event properties: Object containing the following fields:
- text - message text.
- date - Unixtime message-sending time.
- source - message sender. Possible values:
Operator,Visitor,System. - from - operator name if the message was sent by an operator. In other cases, the value of
fromis equal tosource. - chat_id - ID of the chat a message belongs to.
- message_id - message unique ID.
- uid - temporary ID, used to synchronize sent and received messages.
showchatretentionaction
An event occurs when you need to show an alternative communication button in the chat.
showchatretentionaction event properties: Object containing the field:
- alternate_communication_way - alternative communication mnemonic.
Possible mnemonic values:
- offline_message - application form.
- sitephone - call form.
- chat - group choice form.
chatavailabilitychange
The event occurs in the following situations:
- There are no operators online in the operator workspace - in this case the value
falseis returned in the event. - There is at least one operator online - in this case the value
trueis returned.
invite
The event occurs when an operator invites a visitor to the chat, or when the auto-invite function is activated.
invite event properties:
- invite_message - the message to be displayed when inviting.
startchat
The event occurs in response to the command chat.startChat().
closechat
The event occurs in response to the command chat.closeChat().
inviteaccept
The event occurs in response to the command chat.inviteAccept().
invitereject
The event occurs in response to the command chat.inviteReject().
setrating
The event occurs in response to the command chat.setOperatorRating().
sendchatbymail
The event occurs in response to the command chat.sendChatByMail().
ratingchange
The event occurs when the operator's rating is changed.
ratingchange event properties:
The number corresponding to the operator's rating in the current chat, or null if no rating exists.
statechange
The event occurs when the website visitor's status changes.
statechange event properties: A mnemonic corresponding to the visitor's new status. Possible values:
- available - visitor is on the website, not interacting with widgets.
- invite - visitor received an invitation to a chat.
- chat - visitor is talking to the chat operator.
- lead - the lead generator form is displayed.
chattyping
The event occurs when an operator types a message.