Lifecycle events
Lifecycle events allow you to trigger flows based on arbitrary events, including events generated by integrations, instead of relying on user input to launch flows. In this guide you’ll learn how to create events and handle them.
Creating an event
- Create a flow called
lifecycle.yaml
and add the following code:
triggers:
- keyword: lifecycle
steps:
- say: Here's a lifecycle event...
- lifecycle: foo
text: bar # Optional
- say: Done.
Run the following commands in your terminal:
meya format
Save the file.
In this flow, the lifecycle component will create an event with a lifecycle_id
of foo
. The text
property allows you to display text to the user when the event occurs, if you wish.
For the full definition of the component, check out the documentation here: Lifecycle component
- Push the new flow to the app:
meya push
- Test out the new flow in the simulator:
Listening for events
You can setup lifecycle triggers that listen for events with a matching lifecycle_id
.
- Create a new flow called
event.yaml
and add this code:
triggers:
- lifecycle_id: foo
steps:
- say: This is the event flow triggered by the foo lifecycle event.
Run meya
format in your terminal, then save.
- Push the code to your app:
meya push
- Test the trigger by running the
lifecycle.yaml
flow in the simulator:
If you run the flow multiple times you’ll notice the message from
event.yaml
may occur either before or after theDone.
message. Flows triggered by lifecycle events run asynchronously.
For more information on the lifecycle trigger, check out the documentation: Lifecycle trigger
Lifecycle event entries
You can search for lifecycle event entries in the logs using this GridQL query:
meya.lifecycle.event.event
You can also search for events with a particular lifecycle_id
:
lifecycle_id:foo
Here’s an example lifecycle event log entry:
Updated about 3 years ago