$request
This object contains client request data.
Object format
The $request
variable has the following attributes:
Attribute | Description |
---|---|
data |
Request parameters: livechatStatus , JustWidgetRawParams , isTestChannel , requestHeaders . |
requestType |
Request type. |
version |
Protocol version. The last version by default. |
botId channelBotId |
Bot identifier. |
accountId |
Account identifier. |
channelType |
Communication channel type. |
channelUserId |
Client identifier. |
questionId |
Request identifier. |
query |
Client request in text format. |
rawRequest |
Request object in its original format to be processed within the script later on. |
language |
NLU language for the project. |
userFrom |
Client data: id , firstName , lastName . |
How to use
$request.channelType
Checking the channel type to transfer the dialog to the agent:
state: SwitchToAgent
script:
if ($request.channelType == 'telegram' || $request.channelType == 'chatwidget') {
$reactions.answer('Transferring the dialog to the agent')
} else {
$reactions.answer('Unable to transfer the dialog to the agent')
}
$request.botId and $request.channelUserId
Requesting client and bot IDs to authorize in the bank:
state: TransferMoney
q!: * transfer money *
# The bot function can only be accessed after client authentication
script:
# Get the pushback link
$temp.securityToken = "ExampleToken";
var channelType = $request.channelType;
# Get bot ID
var botId = $request.botId;
# Get client ID
var chatId = $request.channelUserId;
# Specify event name
var event = "authEvent";
var eventData = {
"token": $temp.securityToken,
"someData": {
"smth": 1
}
};
$temp.pushgateResponse = $pushgate.createPushback(channelType, botId, chatId, event, eventData);
...
$request.query
Displaying unrecognized client query:
state: NoMatch
event!: noMatch
a: I do not understand. You said: {{$request.query}}
$request.data.requestHeaders
The $request.data.requestHeaders
field is only available for Chat widget, Aimybox, and Chat API channels.
Receiving information about the client application:
state: RequestClientInfo
intent!: /info
a: {{$request.data.requestHeaders['user-agent']}}
The HTTP header names in the $request.data.requestHeaders
field are converted to lowercase.
$request.rawRequest
Getting client phone number to proceed with the order:
state: GetPhoneNumber
event: telegramSendContact
script:
$client.phone_number = $request.rawRequest.message.contact.phone_number;
a: Thank you! Our Manager will contact you by {{$client.phone_number}}.