events

If your system uses web-hooks, you can implement them in your module with events. Events can be simpler or more complex than actions, depending on what you want to do with them.

Declare an event

If you just want to pass the payload of your web-hook to the Marjory event, you need to declare the event in the marjory.yml by specifying how to find the event type and some informations on the event.

Let's say your web-hooks works with this type of payload:

{
  "eventId": "x1234567890x",
  "from": "Pancake Factory",
  "eventType": "pancake_ordered",
  "id": "AZ112ZAOIJAE",
  "pancake": "🥞",
  "topping": ["BUTTER", "MAPPLE_SYRUP"]
}

Here is how to declare the event in the marjory.yml:

...
events:
  pancakeOrdered:
    name: Pancake Ordered
    description: Triggers every time a pancake is ordered from the factory
    event: pancake_ordered # This is the name of the event in your system
    path: eventType # This is the path to the event name in the global object
    payload:
      id:
        type: string
        description: The unique identity of the pancake
      pancake:
        type: string
        description: The pancake name
      topping:
        type: array
        description: All the toppings put on the pancake

Event type in nested object

If your event name is in a nested object, you can divide it using . separator. Example, if your object looks like this...

{
  "event": {
    "id": "x1234567890x",
    "type": "pancake_ordered",
    "from": "Pancake Factory"
  }
  "data": {
    "id": "AZ112ZAOIJAE",
    "pancake": "🥞",
    "topping": ["BUTTER", "MAPPLE_SYRUP"]
  }
}

... you can write the path like this:

path: event.type

Event with a handler function

If you want to modify the content of an event, you can create a function that will receive the payload and you can work with it before returning a ModuleResponse.

To do so, you can create a function similar to actions but in the events folder. Your function name must match the name of your event in the marjory.yml.

...
events:
  pancakeOrdered: # <- This must be the name of your function
    name: Pancake Ordered
    description: Triggers every time a pancake is ordered from the factory
...

Last updated