Automation in LetsFlow is handled by your backend or microservices. When a state transition occurs, the service needs to be notified. This is achieved through messaging.
If you're using the workflow engine, notifications are sent via a messaging queue or webhooks. However, if you're integrating the core library directly into your backend, you can leverage the event system provided by your framework to handle these notifications efficiently.
For any action available for a service, a notify instruction is automatically appended to that state. The service can be referenced in the by property of a state transition or the actor property of an action.
If there's exactly one action that the service can perform, the trigger property is automatically set to that action. If multiple actions are available the trigger property is set to null.
{% tabs %} {% tab title="YAML" %}
initial:
on: create_document
by: service:cms
goto: main{% endtab %}
{% tab title="JSON" %}
{
"initial": {
"on": "create_document",
"by": "service:cms",
"goto": "main"
}
}{% endtab %} {% endtabs %}
string (required)
The service to message
time
Delay notifying the service.
The time should be in the form of 'amount unit' in English, eg '10 minutes', '12 hours`, or `1 week`.
boolean or data function
If condition
string, data function, or null
The action that the service has performed when giving a response.
If the service provides a response and multiple actions are available to the service, you should use a data function to determine which action has been executed. The data function is evaluated after receiving a response and not when the state is instantiated.
{% tabs %} {% tab title="YAML" %}
initial:
transitions:
- on: continue
by: service:agent
goto: main
- on: cancel
by: service:agent
goto: (cancelled)
notify:
service: agent
trigger: !ref current.response.action{% endtab %}
{% tab title="JSON" %}
{
"initial": {
"transitions": [
{
"on": "continue",
"by": "service:agent",
"goto": "main"
},
{
"on": "cancel",
"by": "service:agent",
"goto": "(cancelled)"
}
],
"notify": {
"service": "agent",
"trigger": {
"<ref>": "current.response.action"
}
}
}
}{% endtab %} {% endtabs %}
string, object, or data function
Custom message to send the service.
If message is omitted, the standard message is sent. This is;
array of instantiated actions
The actions that the service is allowed to perform in the current state.
string
Instructions for the service as defined in the scenario for this state.
{% tabs %} {% tab title="YAML" %}
wait_on_agent:
on: respond
by: service:agent
goto: wait_on_user
instructions:
service:agent: |
Based on the conversation answer ...{% endtab %}
{% tab title="JSON" %}
{
"wait_on_agent": {
"on": "respond",
"by": "service:agent",
"goto": "wait_on_user",
"instructions": {
"service:agent": "Based on the conversation answer ..."
}
}
}{% endtab %} {% endtabs %}
Instructions are mostly useful when the service is an AI agent.