The event
library provides functions for understanding an event and the environment in which it was raised as well as actions for sending events.
Event Functions
There are three categories of event functions.
Event Environment
For historical reasons, some of these are Web-centric. The following functions are available:
event:env()-
returns information about the event's environment. The function takes an argument that determines what will be returned:
caller -
return the URL of the Web page on which the event is firing (assumes an event in theweb
domain)ip -
return the IP number of the endpoint (client).referer -
return the URL of the referring page to the caller (assumes a web event).title -
return the page title of the calling page.- txn_id - return the transaction ID of this ruleset evaluation.
Event Attributes
event:attr() -
returns a specific event attribute. The function takes the name of the attribute to be returned as its sole argument.event:attrs() -
returns all the event attributes as a map.
Event Channels
event:channel()
- returns information about the event channel. The function takes an argument that determines what is returned:id
- returns the event channel identifier.
Event Actions
The event library supports sending events to event channels. Event channels can be specified by ESL or by Channel ID.
- event:send()
# assume $args->[0] is a subscription map (SM)
# subscription_map =
# {"name":"Phil",
# "phone":"8013625611",
# "token":"072a3730-2e8a-012f-d2db-00163e411455",
# "calendar":"https://www.google.com/calendar/..."
# };
# Only some of the records in the SM matter to the event:send()
# action as defined below. Of course, KRL can be used to manipulate the
# SM in various ways.
# The only thing a subscription map MUST contain is a token OR an ESL.
# Everything else is optional.
# You send events with the send action in the events space:
# event:send(subscription_map, event_domain, event_type) with
# attrs = ... # map of event attributes
# token_key = ... # key for token in SM, "token" is default
# esl_key = ... # key for ESL in SM, "esl" is default; if token and esl are both present, esl wins
# So, you could simply:
# event:send(subscription_map,
# "notification",
# "status"
# )