Workflow API¶
Customer password recovery adds the CRM trigger customer.password_reset_requested
and the subject-specific action customer.password_reset.request_delivery.
Workflow selects a logical delivery_route; external modules own templates and channels.
See the complete recovery contract,
including conditions, the single-action rule constraint and first-stage limitations.
Workflow API manages flat automation chains:
trigger -> conditions -> actions
Workflow chains are stored as WorkflowRuleRecord. Current API covers definitions, validation, CRUD, run log reads and runtime execution for trade, account, customer and KYC events.
Triggers and conditions belong to the server. Moleculer modules can add their own
actions — for example mailer.send_template of sct-mailer — see
Workflow provider actions.
Runtime¶
The runtime path is event-driven:
EventBus trade.push / account.push / customer.push / customer.converted_to_client / kyc.step.push
-> WorkflowManager
-> ThreadPoolGlobal worker
-> WorkflowRuntimeContext
-> active rules by resolved trading group brand + trigger
-> trade/account/customer conditions
-> runtime-supported actions
-> workflow run log
Supported trigger mapping:
EV_RECORD_ADD + OP_BUY/OP_SELL -> trade.opened
EV_RECORD_ACTIVATE_TRADE + OP_BUY/OP_SELL -> trade.opened
EV_RECORD_CLOSE_TRADE + OP_BUY/OP_SELL -> trade.closed
EV_RECORD_ADD + OP_BALANCE_IN -> deposit.created
EV_RECORD_ADD + OP_BALANCE_OUT -> withdrawal.created
EV_RECORD_ADD + OP_CREDIT_IN -> credit.created
account.push + EV_RECORD_ADD -> account:added
account.push + EV_RECORD_UPDATE -> account:updated
account.push + EV_RECORD_DELETE -> account:deleted
customer.push + EV_RECORD_ADD -> customer.created
customer.push + EV_RECORD_UPDATE -> customer.updated
existing lead becomes a client -> customer.converted_to_client
kyc.step.push + approved status -> kyc.step.approved
kyc.step.push + rejected status -> kyc.step.rejected
kyc profile submission -> kyc.profile.submitted
Lead converted to client¶
customer.converted_to_client is a CRM trigger (scope 0, payload type 3, entity type customer) that starts when an existing customer changes from lead to client. It starts for every conversion path: MngConvertLeadToClient, bulk MngConvertLeadsToClientsByFilter (once per converted customer) and the workflow action customer.convert_lead_to_client. A customer converted back to a lead and then converted again starts it again.
It does not start:
- when a customer is created as a client, for example by import or
MngAddClient— usecustomer.createdwithcustomer.kind == 1for that; - when a client is converted back to a lead;
- when a conversion is requested for a customer who is already a client.
The rule context is the converted customer as stored after the conversion. The trigger does not tell who or what converted the customer. The same write also raises customer.updated; the two triggers are processed independently, and their order is not guaranteed.
Actions: account.open, notify.manager, customer.set_status, webhook.send, customer.set_lifecycle_flags, customer.attach_desk, customer.attach_manager, customer.deposit_enable, customer.deposit_disable, customer.withdrawal_enable, customer.withdrawal_disable, kyc.require_step. The conversion actions customer.convert_lead_to_client and customer.convert_client_to_lead are not offered. Provider actions with the CUSTOMER payload type, such as mailer.send_template, are offered as well.
Conditions: brand, customer.country, customer.language, customer.email, customer.kyc_status, customer.risk_level, customer.affiliate_id, customer.campaign, customer.source_type, customer.lifecycle_flags, customer.assigned_manager_id. customer.lifecycle_flags holds the flags at the moment of conversion.
{
"trigger": "customer.converted_to_client",
"conditions": [
{ "field": "customer.country", "op": "==", "value": "DE" }
],
"actions": [
{
"type": "mailer.send_template",
"params": { "template": 21, "fallback_template": 4 }
},
{
"type": "customer.attach_desk",
"params": { "desk": "DESK_RETENTION_DE" }
}
]
}
The trigger is internal to workflow: no outbound module event is published for it.
Rule order and customer data¶
Several rules can match one event. They run one after another:
- Rules are ordered by
prioritydescending, then byiddescending. - A failed rule does not stop the chain. A rule with
stop_processing = 1stops the rules after it, but only when it succeeded. - The conditions of every rule are evaluated against the event snapshot: the customer as it was when the event was raised. A change made by an earlier rule for the same event does not change which later rules match.
- An action that changes the customer writes only its own fields. The server takes the current customer record under the customer lock, applies the change and stores it in one step. Changes made by earlier rules for the same event — desk, assigned manager, statuses, risk level, deposit and withdrawal permissions, lifecycle flags, customer kind — are kept, and so are changes made at the same time by other sources, such as a manager editing the customer in CRM or another event.
- Actions that read customer data, such as
notify.managerwithoutmanager_idornotify.send, use the event snapshot together with the results of the customer changes already made for this event. A rule that runs aftercustomer.attach_managernotifies the newly attached manager. Changes made by other sources after the event was raised are not visible to these actions. input_jsonin the run log keeps the event snapshot the conditions were evaluated against.
An action whose value is already set — the same status, risk level, desk, assigned manager, deposit or withdrawal permission, lifecycle flags or customer kind — does not write the customer and does not emit an update, so it does not raise customer.updated again. Such an action is not counted in executed_actions of the run result.
Supported runtime conditions include:
brand
amount_usd
trade.order
trade.login
trade.cmd
trade.volume
trade.close_price
trade.symbol
trade.comment
account.login
account.group
account.name
account.email
account.country
account.enable
account.leverage
customer.country
customer.language
customer.email
customer.kyc_status
customer.kyc_current_level
customer.risk_level
customer.lifecycle_flags
customer.kind
customer.created_by_import
customer.country and account.country are compared exactly with the stored
country, which is an upper-case ISO 3166-1 alpha-2 code: registration resolves it
by GeoIP and CRM forms store codes. The condition value must be such a code, for
example {"field": "customer.country", "op": "==", "value": "DE"}, or an array of
codes for in and not_in. Rule validation refuses other values with
CONDITION_VALUE_NOT_ALLOWED; see
MngValidateWorkflowRule.
Rules saved earlier with a country name never matched; open and save them again in
CRM, which converts the names to codes.
Supported runtime actions:
notify.manager
customer.set_risk_level
customer.set_status
customer.set_lifecycle_flags
kyc.require_step
kyc.set_required_level
webhook.send
Every server action that MngGetWorkflowActionsByTrigger returns has a runtime branch.
Provider actions run through one common branch that calls the provider, see
Workflow provider actions.
Removed, because they had no runtime branch:
note.add
tag.add
calendar.create_task
No trigger offers them: MngGetWorkflowActionsByTrigger and MngGetWorkflowTriggers (allowed_actions) do not return them, MngValidateWorkflowRule and MngTestWorkflowRule report ACTION_NOT_ALLOWED_FOR_TRIGGER: <type>, and MngAddWorkflowRule and MngUpdateWorkflowRule reject the rule as invalid data. Stored rules are not changed: an active rule with one of these actions fails at that action with UNSUPPORTED_RUNTIME_ACTION: <type>, after the actions placed before it have already run, until the action is removed.
Email by mailer template¶
Email to the customer of the event is the provider action mailer.send_template of
sct-mailer. The mailer registers it in workflow itself, renders the chosen template and
queues the email; the server only calls the mailer and stores its answer. See
Workflow provider actions for the contract and the
mailer module for
template selection.
The server action customer.email_template.request_delivery and its outbound event
customer.email_template.delivery_requested are removed. On upgrade, stored rules are
rewritten to mailer.send_template with the same template and fallback_template
(migration 20261023_workflow_migrate_email_template_rules); they are not archived. The
action is offered on the triggers with payload types TRADE, CUSTOMER, KYC, CASHIER
and MARGIN, so all triggers of the removed action keep it. The event snapshot sent to the
mailer now includes the deposit, margin and credit figures, so templates can use them.
{
"type": "mailer.send_template",
"params": {
"template": 12,
"fallback_template": 4
}
}
If notify.manager.params.manager_id is omitted or 0, backend first tries the linked customer's assigned_manager_id, then manager_id, then broadcasts to enabled managers.
webhook.send requires params.url and sends an outbound HTTP request from workflow runtime. Optional params are method, headers, body, and timeout_ms.
{
"type": "webhook.send",
"params": {
"url": "https://example.com/webhook",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"text\":\"High risk trade\"}",
"timeout_ms": 5000
}
}
method defaults to POST; timeout_ms is clamped to 1000..30000. The action succeeds only on HTTP 2xx; curl errors or non-2xx responses make the workflow run failed. Runtime logs mask common webhook tokens.
kyc.require_step creates or reuses a customer KYC profile and attaches a required step from a KYC step template. Required params are step_code; optional params are level and reason.
kyc.set_required_level creates or reuses a customer KYC profile and increases the required KYC level. Required param is level; optional param is reason. When the level is increased, KycManager attaches all active required templates for the same brand with template.level <= level.
customer.set_lifecycle_flags explicitly raises and clears milestone bits on the
linked customer. It takes params.add and params.remove, each in range
0..63; both are optional individually, but at least one must be present. KYC
and Cashier events do not raise a flag implicitly; a flag changes only when this
action is present in an active matching rule. Flag values are listed in
Lifecycle Flags.
Conditions on customer.lifecycle_flags use the bits type and the operators
has_all, has_any, and has_none; the value is a single integer holding the
selected bits. customer.kind is an ordinary integer condition.
Example: record the first deposit for a customer that is not marked yet:
{
"trigger": "deposit.created",
"conditions": [
{"field": "customer.lifecycle_flags", "op": "has_none", "value": 8}
],
"actions": [
{
"type": "customer.set_lifecycle_flags",
"params": {"add": 8}
}
]
}
KYC workflow actions require a linked customer context. They are executed through KycManager; the trading mainLoop is not involved.
For a deposit-triggered KYC flow, create a rule on deposit.created with conditions such as amount_usd >= 1 and customer.kyc_current_level < 1, then execute kyc.set_required_level with level = 1.
trade.volume is integer volume: 100 = 1.00 lot, so 10 lots is 1000.
Brand is resolved through the trading group:
TradeRecord.login -> AccountRecord.group -> GroupRecord.brand
This supports both CRM accounts linked to customers and direct BO/MT-style accounts without CRM customers. CustomerRecord.brand remains CRM metadata; trade workflow brand scope comes from the trading group. If no group brand can be resolved, the workflow is skipped and a warning is written to logs.
Access Model¶
Only SESSION_ADMIN can create, update, archive or delete workflow chains:
MngAddWorkflowRule
MngUpdateWorkflowRule
MngArchiveWorkflowRule
MngDeleteWorkflowRule
Read, metadata and validation methods are available to manager sessions:
SESSION_MANAGER
SESSION_ADMIN
SESSION_DEALER
SESSION_CRM_MANAGER
SESSION_CRM_ADMIN
SEO¶
Workflow API supports CRM workflow automation, BackOffice automation, broker rule engine, KYC automation, customer lifecycle automation and trigger condition action workflows.