Skip to main content

$request

This object contains the user request data.

Object format

This object contains the following properties.

note
The exact set of properties may vary depending on the channel.
PropertyTypeDescription
accountIdStringAccount ID.
botId, channelBotIdStringBot ID.
channelTypeStringChannel type.
channelUserIdStringUser ID specific to the channel.
dataObjectVarious request data.
data.chatIdStringSession ID.
data.isTestChannelBooleantrue if the request originates from the test widget.
data.JustWidgetRawParamsObjectParameters passed to the chat widget.
data.livechatStatusObjectTransfer to agent status.
data.requestHeadersObjectHTTP headers of the request sent to the channel.
caution
This property is only available in the chat widget and Chat API.
eventStringThe event that occurred in the script. Mutually exclusive with query.
queryStringThe request text. Mutually exclusive with event.
questionIdStringRequest ID.
rawRequestObjectRequest dump as it was originally received by the channel.
requestTypeStringRequest type.
userFromObjectUser data: id, firstName, lastName.
versionNumberProtocol version. Has the default value of 1.

How to use

$request.query

The query property allows using the request text to send it back to the user or elsewhere, such as a data aggregation system:

state: NoMatch
event!: noMatch
a: I didn’t get it. You said, “{{$request.query}}”.

$request.channelType

The channelType property is used for branching the script depending on the channel:

state: SwitchToAgent
intent!: /Switch to agent
# In this script, transferring to an agent only works in the phone channel.
if: $request.channelType === "resterisk"
a: Hold on. I’m connecting you to one of our agents.
TransferCallToOperator:
phoneNumber = 16123456789
else:
a: Unfortunately, we cannot connect you with an agent. We’ll be sure to get back to you soon.
script:
$dialer.hangUp();
All possible channelType values
ChannelchannelType
Automated teststest-channel
Bot quality evaluationbot_scorer_api
Chat APIchatapi
Chat widgetchatwidget
Chat2Deskchat2desk
Facebookfacebook
Instagraminstagram
JivoChatincoming_jivosite
Microsoft Teamsazure
Slackslack
Telegramtelegram
Telephonyresterisk
Viberviber
Vonagenexmo
WeChatwechat
WhatsAppwhatsapp
WhatsApp (via edna WhatsApp 2.0)edna_platform
ZenDeskzendesk
Zendesk Chatzopim

$request.botId, $request.channelUserId

Use botId and channelUserId when the script needs to assign a unique ID to the bot or its user. For instance, you can pass them to $pushgate.createPushback:

state: Subscribe
intent!: /Subscribe
script:
// Create a pushback.
var pushback = $pushgate.createPushback(
$request.channelType,
$request.botId,
$request.channelUserId,
"newNotification",
{}
);

// Send the Pushgate API link to an external service.
$http.post("https://example.com/subscribe", {
headers: {
"Content-Type": "application/json"
},
body: {
"link": pushback.link
}
});
a: Hooray! Now you’ll be the first to know about all our sales and promotions.

$request.rawRequest

You can use the rawRequest property to access the request data provided to Tovie Platform by the channel. For example, when a user shares their contact info in Telegram, a telegramSendContact event is triggered in the script. In the state that handles this event, you can access the user’s phone number:

state: GetPhoneNumber
event: telegramSendContact
script:
$client.phoneNumber = $request.rawRequest.message.contact.phone_number;
a: Thank you! Our manager will contact you by this phone number: {{$client.phoneNumber}}.