NAV Navbar
javascript

.sendTextToChat()

// You MUST use sendTextToChat() inside the ChatMessageReceived callback
// which ensures that there is an active chat before the message is sent.
SnapEngage.setCallback('ChatMessageReceived', function (agent, msg) {

    // Send a message to the agent
    var text = 'Remember to mention the current promotion!';
    SnapEngage.sendTextToChat(text);

    // Now clear the ChatMessageReceived callback since you
    // just sent the message. (Otherwise, this callback will
    // send the message every time ChatMessageReceived fires)
    SnapEngage.setCallback('ChatMessageReceived', '');

});

Send a message to the active chat agent without showing it to the visitor. Optionally, add a second parameter of 'visitor' to send this message to the visitor.

Parameters

// You MUST use sendTextToChat() inside the ChatMessageReceived callback
// which ensures that there is an active chat before the message is sent.
SnapEngage.setCallback('ChatMessageReceived', function (agent, msg) {

    // Send a message to the visitor
    var text = 'Thanks for chatting! Here is a 10% off coupon code: TENOFF';
    SnapEngage.sendTextToChat(text, 'visitor');

    // Now clear the ChatMessageReceived callback since you
    // just sent the message. (Otherwise, this callback will
    // send the message every time ChatMessageReceived fires)
    SnapEngage.setCallback('ChatMessageReceived', '');

});
Parameter Type Description
text String The text content of a message to be sent to the currently-active agent. When fired, the message will be sent to the agent but not to the visitor.
to String Enter this optional parameter if you would like to send a message to the currently-active visitor and not to the agent.

Parameter values

to value
the visitor, not the agent 'visitor'

Return values

// if the call above returns 'false', it means
// there is an active chat and the message was
// sent to the visitor.
false
Type Description
boolean If true, there is an active chat and the message was sent to the agent. If false, there is an active chat and the message was sent to the visitor. Or, there is no active chat.