$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.
Property | Type | Description |
---|---|---|
accountId | String | Account ID. |
botId , channelBotId | String | Bot ID. |
channelType | String | Channel type. |
channelUserId | String | User ID specific to the channel. |
data | Object | Various request data. |
data.chatId | String | Session ID. |
data.isTestChannel | Boolean | true if the request originates from the test widget. |
data.JustWidgetRawParams | Object | Parameters passed to the chat widget. |
data.livechatStatus | Object | Transfer to agent status. |
data.requestHeaders | Object | HTTP headers of the request sent to the channel. caution |
event | String | The event that occurred in the script. Mutually exclusive with query . |
query | String | The request text. Mutually exclusive with event . |
questionId | String | Request ID. |
rawRequest | Object | Request dump as it was originally received by the channel. |
requestType | String | Request type. |
userFrom | Object | User data: id , firstName , lastName . |
version | Number | Protocol 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
Channel | channelType |
---|---|
Aimybox | zenbox |
Alice | yandex |
Bitrix24 | bitrix |
Chat API | chatapi |
Chat widget | chatwidget |
Chat2Desk | chat2desk |
edna.chatCenter | threads |
JivoChat | incoming_jivosite |
LiveTex | inbound_livetex |
Marusia | marusia |
Microsoft Teams | azure |
Odnoklassniki | odnoklassniki |
Sber Salut | sber |
Slack | slack |
Telegram | telegram |
Telephony | resterisk |
Viber | viber |
VK | vk |
Vonage | nexmo |
Wazzup | wazzup |
Webim (Custom Channel API) | incoming_webim |
Webim (External Bot API 2.0) | incoming_webim2 |
wechat | |
whatsapp | |
WhatsApp (via edna WhatsApp 2.0) | edna_platform |
WhatsApp (via i-Digital) | i_digital |
ZenDesk | zendesk |
Zendesk Chat | zopim |
$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}}.