$pushgate.createEvent
The method creates an event that will be triggered at a specified time.
Syntax
Accepted arguments
The $pushgate.createEvent
method accepts 6 arguments.
Argument | Description | Type | Required | Default value |
---|---|---|---|---|
dateTime | Date and time of the event | String | Yes | — |
event | Event name | String | No | timerEvent |
eventData | Data passed along with the event | Object | No | {} |
channelType | Channel type | String | No | $request.channelType |
botId | Bot identifier | String | No | $request.botId |
chatId | Client identifier | String | No | $request.channelUserId |
- The string in the
dateTime
argument must conform to the formatyyyy-MM-ddTHH:mm:ss
. - An event scheduled for the past will not result in an error, but will be triggered immediately.
eventData
, you can pass arbitrary data that will be needed when the event is triggered. This data will be available for access in the event handler in $request.rawRequest.eventData
.Return value
The method returns an object having one property, id
— the identifier of the newly created event.
Identifiers are used to cancel events via the $pushgate.cancelEvent
method.
Time zone adjustment
When scheduling events from the script, the time zone set for the client via the $reactions.setClientTimezone
method is taken into account.
Example
Consider the following example of a text-based alarm.
state: SetAlarm
intent!: /Alarm/Set
a: At what time?
state: Time
q: * @duckling.time *
script:
$temp.time = $parseTree["_duckling.time"];
$pushgate.createEvent($temp.time.value);
a: The alarm has been set for {{$temp.time.hour}}:{{$temp.time.minute}}.
state: Alarm
event!: timerEvent
a: Time to wake up!
- When the client tells when the alarm should be set, they transition to the
Time
state. The time is extracted from the request using one of the Duckling entities —@duckling.time
. - The parsed
@duckling.time
entity has avalue
property — a string describing the parsed time and conforming to the format required by$pushgate.createEvent
. The event is scheduled for this time. - When the time arrives, the scheduled
timerEvent
is triggered and gets processed by the script in theAlarm
state.
In addition to one-time events, you can create events that occur at regular intervals. To implement this behavior, the state for processing the event should call $pushgate.createEvent
and reschedule the same event for the future. Note that events are triggered once every 30 seconds at most.