Group meeting
Introduction to wildcard actors and conditions
The previous tutorial had our two actors introducing themselves. In that scenario, we've given one actor the role of initiator and another of recipient.
In this tutorial, we'll model a situation where a random number of people have a conversation. They first all need to introduce themselves after which each one can talk.
Create file
meeting.yamlinscenarios.Create subdirectory
meetinginfeaturesfor the test files.
Start action
So far, we've created scenarios in which an actor initiates the process. In this tutorial, we’ll introduce a start action, which can only be triggered by a service, such as your backend or a microservice. This is a common pattern that prevents users from starting a process directly.
In this case, a start action is necessary because the scenario involves only a wildcard actor. Instead of relying on predefined participants, the start action will dynamically create the actors participating in the process.
start:
actor: service:default
update: actors
response:
patternProperties:
'^person_.*$':
properties:
name: string
organization: string
nullable: true{
"start": {
"actor": "service:default",
"response": {
"patternProperties": {
"^person_.*$": {
"properties": {
"name": "string",
"organization": "string"
},
"nullable": true
}
}
},
"update": "actors"
}
}Wildcard actors
We don't exactly know how many participants the process will have. However, we do that each participant has essentially the same role. We'll number the actors when we instantiate the process.
Test case
In the initial state, everyone has the opportunity to introduce themselves. With an introduction, we stay in the initial state. When someone starts to talk we transition to the talking state.
Scenario
Instead of defining the actors individually, we use a wildcard. The actor schema is applied to every actor with the key person_{number}.
For goto we can use null (which is ~ in YAML) to indicate that we don't want to transition to another state.
It's bad practice to have a process without an end state. We'll add a way to end the conversation later in this tutorial.
Everyone introduced?
In the introduction tutorial, the state machine ensured that both parties introduced themselves before starting the conversation. However, in this scenario, that requirement no longer applies. If the actors' names are already known, they don’t need to introduce themselves. Additionally, actors should not be required to introduce themselves more than once.
Test case
Scenario
We can use if conditions to disallow an action or a transition. The field needs to contain a boolean value. We typically use <ref> data function for conditions. This function performs a JMESPath query against the process.
For the "introduce" action we specify a condition to prevent an actor from performing it if we already know its name.
We'll add a condition statement for state transition from "initial" to "talking", which validates that the name of every actor is known.
The last condition is on the "talk" action. We compare if the current actor is not the actor of the previous event to ensure a person doesn't talk twice.
No introductions
When all actors are known from the start, we can skip the "introductions" state entirely and move directly into the "talking" state, streamlining the workflow.
Test case
Scenario
We use an if condition for the state transition that checks if there are any actors for which the name is unknown.
Leaving the conversation
Instead of ending the interaction, any person can choose to leave. The remaining persons can continue the conversation. When there are less than two persons left, the process should end.
Test case
The scenario
We add an is_present property to the actor, which defaults to true. The "leave" action will set is_present to false for the current actor.
As long as there are two or more actors present, the "leave" action will not cause a state transition. If that condition is not true, the process will end. Transitions are validated in order. Therefore we only need to have a condition on the first transition of "leave" action in the "talking" state.
Last updated
Was this helpful?