Skip to main content

$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.

ArgumentDescriptionTypeRequiredDefault value
dateTimeDate and time of the eventStringYes
eventEvent nameStringNotimerEvent
eventDataData passed along with the eventObjectNo{}
channelTypeChannel typeStringNo$request.channelType
botIdBot identifierStringNo$request.botId
chatIdClient identifierStringNo$request.channelUserId
caution
Bear in mind the following details when passing the date and time of the event:
  • The string in the dateTime argument must conform to the format yyyy-MM-ddTHH:mm:ss.
  • An event scheduled for the past will not result in an error, but will be triggered immediately.
tip
In 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.

info

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.

caution
If the time zone for the client is not set, the time zone on the Classifier tab in project settings is used by default.

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!
  1. 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.
  2. The parsed @duckling.time entity has a value property — a string describing the parsed time and conforming to the format required by $pushgate.createEvent. The event is scheduled for this time.
  3. When the time arrives, the scheduled timerEvent is triggered and gets processed by the script in the Alarm state.
info

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.