Function Reference

These built-in functions can be used in any Embedded Code panel.

Get Current User Message

botContext.getCurrentUserMessage()
Returns:The full text of the most recent message from the user.
Return type:string

Get Quick Reply Payload

botContext.getQuickReplyPayload()
Returns:The payload associated with the user-selected Quick Reply option.
Return type:string

Set Bot Variable

botContext.setBotVariable(name, value[, persistForSession=false, persistForever=false])
Arguments:
  • name (string) – The name for the variable. Used to retrieve the variable in getBotVariable()
  • value (object) – The value to be stored, retrieved with getBotVariable().
  • persistForSession (bool) – If true, the variable persists for the current user session. Otherwise, the variable expires at the end of the current message flow.
  • persistForever (bool) – If true, the variable persists for the user indefinitely.
Returns:

void

Get Bot Variable

botContext.getBotVariable(name)
Arguments:
  • name (string) – The name of the variable.
Returns:

The object defined in setBotVariable().

Send Immediate Reply

botContext.sendImmediateReply(message)
Arguments:
  • message – (string or array) – A string to be added to output. Or an array of strings, each to be aded to output in succession.
Returns:

void

This function adds the message(s) to output, and the output is sent to the user immediately after the Embedded Code is finished. If there is already queued output from the Result, the immediate message will be added after this.

If both sendImmediateReply() and setTriggerNextMessage() are called in the same embedded code panel, the next message will not be triggered, regardless of the order in which they are called.

This function always stops Message Flow.

Set Trigger Next Message

botContext.setTriggerNextMessage(messagename)
Arguments:
  • messagename (string) – The Message to trigger, as identified by the Name of the Message.

Sets a Message to be triggered after the current Embedded Code is processed.

If setTriggerNextMessage() is called during Preprocess Code, the Result from the current Message will not be added to Output.

If both sendImmediateReply() and setTriggerNextMessage() are called in the same embedded code panel, the next message will not be triggered, regardless of the order in which they are called.

Get Responder Results Count

botContext.getResponderResultsCount()
Returns:The number of results returned by the most recent Responder.
Return type:integer

This is most commonly used to check whether a responder returned any results at all. You might want to redirect to another message if no results are returned.

For example, imagine you are using the KnowledgeBase feature to create an FAQ bot. If the user’s query doesn’t return any results, you may want to respond with another message that provides some guidance.

var results = botContext.getResponderResultsCount();
botContext.printDebugMessage('FAQ Results Count = ' + results);

if (results < 1){
    // no results
    botContext.setTriggerNextMessage('FAQs Menu');
}

Get User Location

botContext.getUserLocation()
Returns:location object

When you create a Required Context of type Location, a Location object is created.

You can retrieve this object with getUserLocation(), and access the properties of the location object by assigning it to a local variable and then calling several get methods on the object.

location.getCityName()
Returns:city name
Return type:string
location.getState()
Returns:two-letter state abbreviation
Return type:string
location.getLatitude()
Returns:latitude
Return type:string
location.getLongitude()
Returns:longitude
Return type:string
location.getZipCode()
Returns:postal code
Return type:string

You can also access the location information with the {$location} variable.