Skip to content

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's an operator with the status "online" in the current chat. Returns true or false.

sendChatByMail(mail: string)

Sends 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 a bulk 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. Object contains the following fields:

  • name - operator name
  • position - operator position
  • avatar - link to operator’s photo

getVisitorCard()

The method returns an object containing information about a visitor. An object may contain the following fields:

  • name - visitor name
  • email - an bulk containing up to five e-mails specified earlier by a customer
  • phone - an bulk 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 a bulk of visitor’s card fields 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 on the website not interacting with widgets.
  • invite - visitor received an invitation to a chat.
  • chat - visitor in talking to chat operator.
  • lead - the form of the lead generator is displayed.

chatTyping(text: string)

The method sends text to the RMO as a message typed by the visitor.

Events

operatorjoined

The event occurs when an operator joins the chat.

operatorjoined event features:

Object, containing the following fields:

  • name - operator name.
  • position - operator position.
  • avatar - link to operator’s photo.

operatorleave

The event occurs when an operator leaves the chat.

operatorleave event properties Fields similar to operatorjoined event, containing null.

sendmessage

The event is triggered when receiving a chat message. It can be a message from the chat operator, system message or message from the customer sent from the other website page.

sendmessage event features: 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 from is equal to source.
  • chat_id - id of a 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 features: Object, containing the field:

  • alternate_communication_way - alternative communication mnemonics.

Mnemonics possible values:

  • offline_message - application form.
  • sitephone - call form.
  • chat - group choice form.

chatavailabilitychange

The event occurs in the following situations:

  • There are no PMO operators online, in this case the value false returns in the event.
  • There is at least one operator online, in this case the value true returns.

invite

The event occurs when an operator invites a visitor to the chat, or when the auto-invite function is activated.

invite event features:

  • invite_message - the message to be displayed when inviting.

startchat

Event occurs in response to the command chat.startChat()

closechat

Event occurs in response to the command chat.closeChat()

inviteaccept

Event occurs in response to the command chat.inviteAccept()

invitereject

Event occurs in response to the command chat.inviteReject()

setrating

Event occurs in response to the command chat.setOperatorRating()

sendchatbymail

Event occurs in response to the command chat.sendChatByMail()

ratingchange

The event occurs when operator's rating is changed.

ratingchange event features: The number corresponding to the operator’s rating in the current chat, or null if no rating exists.

statechange

The event occurs when website visitor status changes.

statechange event features: mnemonics corresponding to the visitor's new status. Possible values:

  • available - visitor on the website not interacting with widgets.
  • invite - visitor received an invitation to a chat.
  • chat - visitor in talking to chat operator.
  • lead - the form of the lead generator is displayed.

chattyping

Event occurs when an operator types a message.