Extend the guide with flow modules
A flow module is a reusable part of a flow, with inputs, output fields and custom
branches; see Flow modules for reusable functions
in Connect Customer. The stack creates the ten modules in the table that follows: nine in the stack
itself, and Create a case with details in the nested stack
.
Your own flows can call any of them, and AI agents can use those with external invocation
on.stack-name-GuideModules-random
You can also build modules of your own, such as one that starts your system's automation, and plug one in as the guide's Find the record step. The stack owns its ten modules, and a stack update rewrites them. A module you create is yours, and stack updates never change it, so build your changes as modules of your own rather than editing the stack's.
With the stack's modules and modules of your own, you can do the following:
-
Read a record before routing: call Read the account or Read a case from your own IVR or bot flow, for example to play a case's status to the caller.
-
Create a case with no agent: call Create a case from an after-hours or self-service flow, on the account your flow verified.
-
Give your own AI agent the modules as tools, as the stack's agent assist AI agent uses seven of them.
-
Choose the record the guide opens your own way: replace Find the record with your own module, which can run an invocable Apex action (
runApexAction) or an autolaunched Salesforce flow (runFlow) through the gateway, or call an AWS Lambda function. -
Start your system's automation from the guide or a flow, with a module that calls one gateway tool, such as the Initiate return example in Start your system's automation from the guide.
The following diagram shows who calls a module and what the module calls.
Every caller goes through the same module, and only the module calls your system, so a check you put in the module applies to the guide, your flows and agent assist alike.
The stack creates these ten modules, each named
followed by the
suffix in the table. Each one's stack-name-account-360-v1 alias is the stack output in the first
column. The console calls a module's results its branches:
| Module | Inputs | Output fields | Branches |
|---|---|---|---|
Find the customer, |
|
One, Several and None: up to five accounts ( | One, Several, None, Results, Refused, Failed |
Read the account, |
None; reads the contact's | In |
Answered, Refused, Failed |
Read a case, |
None; reads the contact's |
The case in |
Found, Trimmed, NotFound, Refused, Failed |
List the account's cases, |
|
A page of ten cases, open first, then the newest, and the
account's open and closed case counts, in
|
Results, Refused, Failed |
Update a record, |
|
For Updated, and for Refused when Salesforce refuses the write, the Salesforce
Composite response: the write, then the account view's data, in
|
Updated, Conflict, Refused, Failed |
Create a case, |
|
The new case and the account read again in
|
Answered, Refused, Failed |
Create a customer, |
| Created: the new account and contact in |
Created, Duplicate, Refused, MayHaveBeenSaved, Failed |
Find the record, |
The seven inputs of the Find the record contract, which follows |
|
One, Several, None, Error |
Read the verified account, |
None; reads the contact's |
In |
Answered, Refused, Failed |
Create a case with details, |
|
The new case and the account read again in
|
Answered, Refused, Failed |
The guide flow also calls the gateway directly, outside any module: updateCase and then getCase for Update case, createContact for Add a contact, and queryAccounts for four reads: the org's case statuses, a case by its case number, the names of the accounts on the Which record is this? screen, and a new case's read-back.
Each module limits what it can act on, and who can run it:
No module takes an account ID or a case ID as an input. Each one reads those IDs from the calling contact's attributes and checks them itself, so it acts only on the record your inbound flow, or the agent's search, put on the contact. Update a record's one ID input,
recordId, names a contact, and the module refuses it, withreasonscope, unless that Salesforce Contact is on the account inaccountId.Eight of the ten are tools for AI agents. Find the record and Create a case with details aren't: only the guide runs them, and Create a case with details only from the account view's Create case card.
An AI agent runs a module only when its own security profile lists the module, and agent assist also needs the agent's security profile to list it; see Give agents agent assist in the agent workspace and Let self-service read the verified account.
Anyone who can edit flows (Flows - Edit) can add an Invoke flow module block that runs any module in the instance, so your Connect Customer administrator decides which security profiles have Flows - Edit.
To call a module from your own flow
-
Set the record IDs the module reads, such as
accountId, as contact attributes before the call, from a trusted source. -
Add an Invoke flow module block, and choose the module, such as
, and its aliasstack-name-account-360-read-accountv1. In a flow you build with CloudFormation, use the stack output, such asReadAccountModuleRef. -
Set the module's inputs, and connect each of its branches and its Error branch.
-
Read the module's output fields as
$.Modules.ResultData., for examplefield$.Modules.ResultData.reason, and copy any value you need later into a contact attribute.
Example: play a case's status in your IVR with Read a case
In this example, your IVR has verified the caller, and your own system has
returned the Salesforce IDs of the caller's account and of the case they are calling
about. Read a case takes no inputs: it reads the case in caseId, only if it
is on the account in accountId, so it needs both as Salesforce IDs, not
numbers.
-
A Set contact attributes block sets
accountIdto the account ID andcaseIdto the case ID. -
An Invoke flow module block calls
, aliasstack-name-account-360-read-casev1, with no inputs. -
Connect its branches. Found and Trimmed return the case; Trimmed is the read without the description and the related lists, after the full read fails. NotFound means no case with that ID is on that account. Refused means an ID failed the module's check, with
$.Modules.ResultData.reasonset toinvalid. Failed and the Error branch mean the read didn't run. Send each of the last three to a queue or a message. -
On Found and Trimmed, a Set contact attributes block copies the case's status,
$.Modules.ResultData.records[0].Status, into an attribute such ascaseStatus. The result also holdsCaseNumber,Subject,Priorityand the other fields of the case inrecords[0]. Write a path with an array index in backticks,`$.Modules.ResultData.records[0].Status`, as the guide flow does. -
A Play prompt block reads it to the caller, such as
Your case is $.Attributes.caseStatus.
To build a module of your own
-
In the Connect Customer admin website, create a flow module, and define its inputs, its output fields and its custom branches.
-
Check each input and each record ID the module reads from the contact's attributes before you use it.
-
Add an External Tool block that calls one tool on your system's target. For the application, choose the integration of the gateway; for the stack's gateway, that is
Salesforce -. Choose the tool by its name,stack-namegateway_. For an example that starts a Salesforce flow, see Start your system's automation from the guide.gateway-id__target-name___operation -
End each path with a Return block that names its branch and sets the output fields, including on the External Tool block's error branch.
-
Publish the module, and create a version and an alias. Call it from your flows, such as a copy of the guide flow, as in the previous procedure.
To let agent assist run your module as well, you need an AI agent of your own, because the stack sets the tools of its own agent assist AI agent:
-
Create the module as a tool, with external invocation on; see Create module as tools.
-
Add the module's version, not an alias, to the tools of your AI agent (see Create AI agents in Connect Customer), and list the module in your AI agent's own security profile, in its allowed flow modules (see Assigning security profile permissions to AI agents).
-
Make your AI agent the one agents see: name it in the Connect assistant block of the flow that takes the contact.
-
Add the module to the agents' security profile, in the Flow modules section of its Edit page; see Give agents agent assist in the agent workspace.
To have the guide find the record a contact is about your own way, for example from
a bot conversation or by a rule in your system, build a module with the Find the record
contract and set the stack's Find the record module parameter
(FindRecordModuleArn) to its alias ARN with a stack update. The alias
ARN is the module's ARN, a colon and the alias ID:
arn:aws:connect:.
To list a module's alias IDs, run region:account:instance/instance-id/flow-module/module-id:alias-idaws connect
list-contact-flow-module-aliases --instance-id at the prompt. The guide
then opens the case your module names in the case view, one account in the account
view, or several accounts as possible matches. Leave the parameter empty to use the
stack's built-in module, which reads the attributes in How the guide finds the record. The contract:instance-id
--contact-flow-module-id module-id --query
"ContactFlowModuleAliasSummaryList[].[AliasName,AliasId]" --output text
-
Inputs, seven required strings, each empty when the contact has no value:
contractVersion(1),contactId(thecustomerContactIdattribute, which the stack's inbound flow sets from$.ContactId; your own inbound flows must set it too),channel,queueArn,phone(thecustomerPhoneattribute, the caller's number on a call),email(thecontactEmailattribute) andcaseNumber(the contact's arrivalcaseId, unless it is a case ID). The guide passes exactly these seven, because Connect Customer refuses an input a module doesn't declare. To use the other attributes, read them from the contact in your module:$.Attributes.accountId,$.Attributes.arrivalCaseId(the contact's arrivalcaseId, which the guide copies there) and$.Attributes.contactEmail. OnlycontactIdidentifies the contact; the others are hints. -
Branches: One, Several, None and Error. On Error, the guide shows the screen We couldn't look up this contact's record, with the note This contact's record could not be looked up. Search for the customer., Try again, which runs your module again with the same inputs, and the searches.
-
Output fields, strings,
-when unset. One returnscount1,accountId1and optionallycaseId,contactIdandreason(bot,phone,email,caseNumber,contactorrule). Several returnscountfrom 2 to 5 and that many account IDs inaccountId1onward. None withreasonnomatchshows "No account matched". -
What the guide refuses:
an account ID that doesn't start with 001;
a case ID that doesn't start with 500;
a contact ID that doesn't start with 003;
an ID that holds any of
' \ % & # ? / +;a Several count outside 2 to 5.
A refused output, or a case that isn't on the returned account, shows the same We couldn't look up this contact's record screen. A failed read of the record the module returned shows the error screen.
Example: open the account by a loyalty number
In this example, your inbound flow sets the contact attribute
loyaltyId after it verifies the caller, and an autolaunched Salesforce
flow, Find_Loyalty_Account, takes loyaltyId and returns the
account's ID in its output variable accountId.
-
Create a flow module with the seven inputs and the four branches of the contract, and the output fields
count,accountId1toaccountId5,caseId,contactIdandreason. -
Add a Check contact attributes block on
$.Attributes.loyaltyIdthat sends an empty value, or one that holds any of' \ % & # ? / +, to a Return block with the branch None. -
Add an External Tool block that calls the
salesforcetarget'srunFlowtool, withdomainNameset to your org's My Domain name,flowApiNameset toFind_Loyalty_Accountandbodyset to{"inputs": [{"loyaltyId": "$.Attributes.loyaltyId"}]}. Send its error branch to a Return block with the branch Error. -
On its success branch, add a Set contact attributes block that copies
`$.ExternalTool.ResultData[0].outputValues.accountId`, with the backticks, into the flow attributefoundAccountId, and a Check contact attributes block on$.FlowAttributes.foundAccountIdthat sends a value that doesn't start with 001 to a Return block with the branch None andreasonset tonomatch. -
End with a Return block with the branch One, and set
countto1,accountId1to$.FlowAttributes.foundAccountId,reasontorule, and every other output field to-.
The guide then opens that account in the account view. Every branch sets every
output field, with - for the ones it doesn't use.
Publish the module, with a version and an alias, in the stack's instance. Keep its
external invocation off and leave it out of every AI agent's tools. Connect Customer checks the
guide's Invoke flow module block against your module when the stack
creates or updates the guide flow, so a module without these inputs and branches fails
that step. The module can do anything a flow module can: run an invocable Apex action
with runApexAction or an autolaunched Salesforce flow with
runFlow, call another gateway tool or an AWS Lambda function, or use
flow logic alone, for example to choose a customer by a loyalty number or to open the
customer's most recent open case.