Extensions reference

Reference documentation for Extensions development

Alf.io extensions

The official repository for the extensions can be found here.

How to write an extension

Extensions allow you to link Alf.io with your existing tools, such as:

  • Billing/Accounting systems
  • CRMs
  • Additional Email marketing services (Mailjet, …)
  • Custom notifications (Slack, Telegram, etc.)

How it works

Extensions can be added and modified by each user. However, some limitations are applied that can be found here.

Each extension consists of a JavaScript script and is registered to one or more Application Events, and is fired as soon as the Application Event occurs.

You can find some sample code in the introduction page.

Scope Variables

Alf.io provides some objects and properties to the script in the script scope:

VariableTypeAbout
logLog4jLogging utility
extensionLoggerExtensionLoggerA logger that writes in the extension_log table.
simpleHttpClientSimpleHttpClientA simplified version created by Alf.io for calling external services
GSONGSONJSON parser/generator
returnClassjava.lang.Class<?>The return class of the methods
extensionParametersMap<String, Object>Defined parameters as in the script metadata
eventEventAlf.io's implementation of a general event
eventIdintThe id of the event
organizationIdintThe id of the organization that organized the event
UtilsExtensionUtilsA collection of utilities
executionKeyStringAn identifier for the execution, which can be treated as an idempotency key.

Other event-related variables are also injected in the scope.

Methods

getScriptMetadata

This method returns the actual configuration options and capabilities of the extension. It must return a JSON object with the following properties:

  • async boolean: whether or not the script should be invoked asynchronously.
  • events string[]: list of supported events
  • configuration {(key: string): string}: the extension configuration (WIP)

executeScript

The actual event handling. Return types are event-dependent. Will always receive a single parameter (scriptEvent) which is the event that triggered the script.

Organization

Some events provide the details of the organizer in the organization variable. It is an object with the following properties:

PropertyTypeAbout
idintThe id of the organization
nameStringThe name of the organization
descriptionStringThe description of the organization
externalIdStringThe id of the organization in an external system. Empty string if not set
slugStringThe slug of the organization, used in its public address. Empty string if not set

Application Events by entity

Below is a list of all the supported Application Events by related entity, with some additional global variables, expected result type and a short explanation.


Event

Compatible Application Events for the “Event” entity

Reservation

Compatible Application Events for the “Reservation” entity

Ticket

Compatible Application Events for the “Ticket” entity

Subscription

Compatible Application Events for the “Subscription” entity

Email

Compatible Application Events for the “Email” entity

Other

Other Application Events