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, Aimybox, 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 = 79123456789
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
Aimyboxzenbox
Aliceyandex
Bitrix24bitrix
Chat APIchatapi
Chat widgetchatwidget
Chat2Deskchat2desk
edna.chatCenterthreads
JivoChatincoming_jivosite
LiveTexinbound_livetex
Marusiamarusia
Microsoft Teamsazure
Odnoklassnikiodnoklassniki
Sber Salutsber
Slackslack
Telegramtelegram
Telephonyresterisk
Viberviber
VKvk
Vonagenexmo
Wazzupwazzup
Webim (Custom Channel API)incoming_webim
Webim (External Bot API 2.0)incoming_webim2
WeChatwechat
WhatsAppwhatsapp
WhatsApp (via edna WhatsApp 2.0)edna_platform
WhatsApp (via i-Digital)i_digital
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 JAICP 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}}.