|
| 1 | +--- |
| 2 | +title: GLS Action Events |
| 3 | +description: Events emitted by the GLS Action — what they are, how they trigger flows in Aquila, and what future events are planned. |
| 4 | +--- |
| 5 | + |
| 6 | +# GLS Action Events |
| 7 | + |
| 8 | +In the Hercules platform, **events** are notifications emitted **by an action** that trigger flows in Aquila. They are the opposite of functions: instead of a flow calling the action, the action pushes data to Aquila, which starts any flows that are listening for that event type. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## How events work |
| 13 | + |
| 14 | +``` |
| 15 | +External world (e.g. GLS webhook / polling) |
| 16 | + │ |
| 17 | + │ something happens (parcel delivered, shipment arrived, ...) |
| 18 | + ▼ |
| 19 | + GLS Action |
| 20 | + │ |
| 21 | + │ sdk.dispatchEvent(eventType, projectId, payload) |
| 22 | + ▼ |
| 23 | + Aquila |
| 24 | + │ |
| 25 | + │ routes event to all flows listening for eventType |
| 26 | + ▼ |
| 27 | + Your Flow starts |
| 28 | + │ |
| 29 | + │ event payload available as flow input |
| 30 | + ▼ |
| 31 | + Flow nodes execute (functions, conditions, etc.) |
| 32 | +``` |
| 33 | + |
| 34 | +An event carries a **payload** — the data associated with what happened (e.g. shipment details, tracking ID, status). Flows that subscribe to an event type receive this payload as their starting input. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Current status |
| 39 | + |
| 40 | +> **The GLS Action does not currently emit any events.** |
| 41 | +> |
| 42 | +> The GLS action presently only exposes **functions** (called by flows) and registers **data types** and **configuration**. Event support — where the action proactively notifies Aquila of changes — is **planned for a future release**. |
| 43 | +
|
| 44 | +--- |
| 45 | + |
| 46 | +## Planned events |
| 47 | + |
| 48 | +The following events are candidates for future implementation. Once added, each will allow you to build flows that react automatically to GLS shipment lifecycle changes. |
| 49 | + |
| 50 | +### `gls.shipment.arrived` |
| 51 | + |
| 52 | +Emitted when a parcel arrives at a GLS depot or is scanned into the GLS network. |
| 53 | + |
| 54 | +**Trigger mechanism:** The action would periodically poll the GLS tracking API (or receive a GLS webhook) and emit this event for each new scan. |
| 55 | + |
| 56 | +**Payload type (planned):** `GLS_TRACKING_EVENT` |
| 57 | + |
| 58 | +``` |
| 59 | +GLS Action (polling / webhook listener) |
| 60 | + │ |
| 61 | + │ detects new scan for tracked parcel |
| 62 | + ▼ |
| 63 | +sdk.dispatchEvent("gls.shipment.arrived", projectId, { |
| 64 | + TrackID: "12345678", |
| 65 | + Status: "IN_TRANSIT", |
| 66 | + Location: "MUC-HUB", |
| 67 | + Timestamp: "2025-06-01T10:30:00Z" |
| 68 | +}) |
| 69 | + │ |
| 70 | + ▼ |
| 71 | +Aquila → triggers all flows subscribed to "gls.shipment.arrived" |
| 72 | +``` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +### `gls.shipment.delivered` |
| 77 | + |
| 78 | +Emitted when a parcel is confirmed delivered to the recipient. |
| 79 | + |
| 80 | +**Payload type (planned):** `GLS_TRACKING_EVENT` |
| 81 | + |
| 82 | +``` |
| 83 | +sdk.dispatchEvent("gls.shipment.delivered", projectId, { |
| 84 | + TrackID: "12345678", |
| 85 | + Status: "DELIVERED", |
| 86 | + DeliveredAt: "2025-06-02T14:15:00Z", |
| 87 | + SignedBy: "J. Doe" |
| 88 | +}) |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +### `gls.shipment.failed` |
| 94 | + |
| 95 | +Emitted when a delivery attempt fails (e.g. recipient not home, address problem). |
| 96 | + |
| 97 | +**Payload type (planned):** `GLS_TRACKING_EVENT` |
| 98 | + |
| 99 | +``` |
| 100 | +sdk.dispatchEvent("gls.shipment.failed", projectId, { |
| 101 | + TrackID: "12345678", |
| 102 | + Status: "DELIVERY_FAILED", |
| 103 | + Reason: "RECIPIENT_NOT_HOME", |
| 104 | + NextAttempt: "2025-06-03" |
| 105 | +}) |
| 106 | +``` |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +### `gls.shipment.returned` |
| 111 | + |
| 112 | +Emitted when a parcel is returned to sender after failed delivery attempts. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## How events are implemented (SDK reference) |
| 117 | + |
| 118 | +When events are added to the GLS Action, they will follow this pattern from the Hercules SDK: |
| 119 | + |
| 120 | +### 1. Register the flow type (event definition) |
| 121 | + |
| 122 | +```typescript |
| 123 | +sdk.registerFlowTypes({ |
| 124 | + identifier: "gls.shipment.arrived", |
| 125 | + editable: false, |
| 126 | + inputType: "GLS_TRACKING_EVENT", |
| 127 | + linkedDataTypes: ["GLS_TRACKING_EVENT"], |
| 128 | + name: [{ code: "en-US", content: "GLS Shipment Arrived" }], |
| 129 | + description: [{ |
| 130 | + code: "en-US", |
| 131 | + content: "Triggered when a GLS parcel arrives at a depot or is scanned." |
| 132 | + }] |
| 133 | +}) |
| 134 | +``` |
| 135 | + |
| 136 | +### 2. Dispatch the event when it occurs |
| 137 | + |
| 138 | +```typescript |
| 139 | +sdk.dispatchEvent( |
| 140 | + "gls.shipment.arrived", // must match registered flow type identifier |
| 141 | + projectId, // which project to notify |
| 142 | + payload // data payload (must match inputType) |
| 143 | +) |
| 144 | +``` |
| 145 | + |
| 146 | +### 3. User builds a flow triggered by the event |
| 147 | + |
| 148 | +In the Hercules UI, users create a flow with **"GLS Shipment Arrived"** as the trigger. When the GLS action dispatches this event, Aquila starts the flow and provides the payload (e.g. `TrackID`, `Status`, `Location`) as the flow's input. |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## Flow type settings |
| 153 | + |
| 154 | +Flow types can expose **settings** that allow users to configure how an event filters or behaves. For example, a future `gls.shipment.arrived` event might let users specify: |
| 155 | + |
| 156 | +| Setting | Type | Description | |
| 157 | +|---------|------|-------------| |
| 158 | +| `trackId` | string | Only trigger for a specific parcel | |
| 159 | +| `statusFilter` | string[] | Only trigger for specific status codes | |
| 160 | + |
| 161 | +Settings are defined in the `settings` array of `HerculesFlowType` and are configurable per-flow in the Hercules UI. |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Difference between events and functions |
| 166 | + |
| 167 | +| | Events | Functions | |
| 168 | +|-|--------|-----------| |
| 169 | +| **Direction** | Action → Aquila | Flow → Action | |
| 170 | +| **Who initiates** | The action (proactively) | The flow (on demand) | |
| 171 | +| **Purpose** | React to something that happened externally | Perform an operation and return a result | |
| 172 | +| **SDK method** | `registerFlowTypes` + `dispatchEvent` | `registerFunctionDefinitions` | |
| 173 | +| **Example** | Parcel delivered → trigger notification flow | Create a shipment and return the label | |
| 174 | +| **Current GLS status** | ❌ Not yet implemented | ✅ 26 functions available | |
0 commit comments