

# Step 4: Test the guide, then add it to your inbound flow

## Test the guide with the inbound flow
<a name="real-time-data-integration-test-chat"></a>

Test with a chat, a call, or both, for the channels your agents take. Either test sends a contact through the stack's inbound flow, named in the stack's `InboundFlowName` output, to the test queue, and the test agent accepts it in the agent workspace. Neither test changes your own inbound flow.
+ A test chat, from the Connect Customer admin website's test chat page, carries a test account's ID as a contact attribute, so the guide opens on that account.
+ A test call, to a test phone number that you assign to the stack's inbound flow, carries no account ID. The guide opens on **Unknown caller** and offers the caller's number as a search, which finds the test account by a contact's phone number.

**To get the test agent ready**
+ Open the agent workspace in a browser. Its URL is the instance's access URL, which the check in [Check the instance](real-time-data-integration-instance.md#real-time-data-integration-instance-check) prints, followed by `/agent/`:
  + For an access URL that ends in `my.connect.aws`: `https://{{instance-name}}.my.connect.aws/agent/`.
  + For an access URL that ends in `awsapps.com/connect`: `https://{{instance-name}}.awsapps.com/connect/agent/`.

  Log in as the test agent you set up in Step 1, such as `rtdi-test-agent`, and set your status to **Available**.

------
#### [ Test chat ]

Before you start, make sure your Salesforce org has a test account with a Salesforce Contact and a case, so that the guide has something to show. Create one in Salesforce if it doesn't.

**To test the guide with a test chat**

1. In another browser tab, log in to the Connect Customer admin website. On the navigation menu, choose **Channels**, and then **Test chat**.

1. Choose **Test Settings**.

1. In **Contact Flow**, choose the stack's inbound flow, named in the stack's `InboundFlowName` output. Scroll the list to find it; typing to search doesn't find it.

1. In **Contact Attributes (optional)**, enter the ID of a test Salesforce account, with the key and the value in quotes, for example **{"accountId": "001xx000003DGb2AAG"}**. To find a test account's ID, open the Salesforce Developer Console, choose the **Query Editor** tab, enter **SELECT Id, Name FROM Account ORDER BY LastModifiedDate DESC LIMIT 5**, and choose **Execute**.

1. Choosing **Apply** starts the chat at once and offers it to the agent. The guide starts when the chat is offered, and shows the account when the agent accepts. Keep the agent workspace tab ready, choose **Apply**, then switch to the agent workspace and accept the chat.

The test passes when the guide shows the test account, with its recent cases, after the agent accepts the chat. If it doesn't:
+ No chat reaches the agent: check that the agent's status is **Available**, that the agent's routing profile has chat and the test queue, and that **Contact Flow** is the stack's inbound flow.
+ The chat arrives but the guide shows **Customer not found**, or **The customer's details could not be loaded.** with **Refresh**: check the account ID and that the integration user can see that account, then see [Testing in the agent workspace](real-time-data-integration-troubleshoot.md#real-time-data-integration-troubleshoot-agent).

------
#### [ Test call ]

Before your first test call, set up the following:

1. The instance allows incoming calls (**Receive inbound calls with Connect Customer**); see [Update settings for your Connect Customer instance](https://docs.aws.amazon.com/connect/latest/adminguide/update-instance-settings.html).

1. The test agent's routing profile takes calls from the test queue, as in [Create the test agent and its Modern layout](real-time-data-integration-instance.md#real-time-data-integration-instance-agent).

1. A test phone number. Claim one, or use a number the instance already has that no customer calls; see [Get a local toll-free or DID Connect Customer phone number](get-connect-number.md).

1. The test phone number goes to the stack's inbound flow, named in the stack's `InboundFlowName` output: in **Flow / IVR** for the number, choose that flow. See [Attach a claimed or ported phone number to a flow in Connect Customer](associate-claimed-ported-phone-number-to-flow.md). Every call to the number then goes to the test queue.

1. In Salesforce, a contact on a test account has the number of the phone you call from in its **Phone** field, so the caller's number finds it.

**To test the guide with a test call**

1. From the phone whose number you stored, call the test phone number.

1. The call is offered to the test agent, and the guide starts. In the agent workspace, accept the call.

1. The guide shows **Unknown caller**, with the warning **No record matches this contact.** and the card **Search for the caller's number**, which shows the number's digits, without \+1 for a North American number. Choose the card.

1. The guide searches Salesforce for the number, as the **Name, phone, email or case subject** search does. If it finds more than one record, choose the test contact's card.

The test passes when the guide shows the test account, with its recent cases. When the contact is among the account's five newest contacts, **Customer information** also shows **Caller:** with the contact's name. If the test doesn't pass:
+ No call reaches the agent: check that the agent's status is **Available**, that the agent's routing profile has voice and the test queue, and that the number's **Flow / IVR** is the stack's inbound flow.
+ The search finds nothing: check that the contact's **Phone** holds the number you called from, and that the integration user can see that contact, then see [Testing in the agent workspace](real-time-data-integration-troubleshoot.md#real-time-data-integration-troubleshoot-agent).

A call opens an account without a search only when your inbound flow sets `accountId` after it verifies the caller; see [Add the guide to your inbound flow](#real-time-data-integration-inbound-flow).

------

For details, see [Test voice, chat, and task experiences](chat-testing.md).

## Add the guide to your inbound flow
<a name="real-time-data-integration-inbound-flow"></a>

In your own inbound flow, set the contact attributes that name the customer and set both agent UI events with **Set event flow**, as the stack's inbound flow does: the default flow for the agent UI and, with the wrap-up, the disconnect flow. The stack's inbound flow is a test flow: it never sets a record attribute. A test chat supplies one as a contact attribute, and a test call has none.

The guide opens whichever record the attributes name, so set them from a value your own system verified: your website's server for a chat, or an IVR step that checks the caller for a call. A caller ID can be spoofed, so a caller's number alone doesn't verify the caller. See [Security considerations](real-time-data-integration-security.md). For the attributes the guide reads, the order it reads them in, what the agent sees for each, and worked examples, see [How the guide finds the record](#real-time-data-integration-find-record).

A contact with no usable value, or one that matches no account the integration user can see, shows **Customer not found** on a chat or **Unknown caller** on a call. The agent then finds the account with a search, or creates the customer. A search is the agent's choice, not a verification of the caller, so until your inbound flow sets a verified value, agents must verify each caller themselves.

1. In your inbound flow, before the contact is transferred to a queue, add a **Set contact attributes** block that sets, from your verified source, whichever of these attributes the flow knows:
   + `accountId`: a Salesforce account ID or an account number.
   + `caseId`: a Salesforce case ID or a case number.
   + `contactEmail`: a contact's email address.

   The same block also sets these attributes, as the stack's inbound flow does:
   + `customerContactId` to the contact's ID, `$.ContactId`. The guide passes it to the Find the record module, and the **Customer not found** screen reads it.
   + `customerChannel` to the contact's channel, `$.Channel`. Without it, the guide treats every contact as a chat: it shows **Customer not found** instead of **Unknown caller** on a call, and gives the cases it creates the Origin `Web` instead of `Phone`.
   + On a call, `customerPhone` to the caller's number, `$.CustomerEndpoint.Address`. The not-found screen offers it as the **Search for the caller's number** search; without it, that search doesn't appear. The stack's inbound flow sets it only when `$.Channel` is `VOICE`.

1. Add a **Set event flow** block. For the event, choose **Default flow for Agent UI**, and choose the guide flow, the stack's flow whose name ends in `-account-360-guide`. See [Invoke a guide at the start of a contact](how-to-invoke-a-flow-sg.md).

1. If you deploy with **Wrap-up flow and form** set to `Enabled`, and you want to show the wrap-up when the contact ends, add a second **Set event flow** block that sets the disconnect flow for the agent UI to the wrap-up flow, the stack's flow whose name ends in `-account-360-wrapup`. Your instance might also show the default wrap-up guide from Connect Customer; see [Enable smart default guides for after contact work](enable-smart-default-guides-acw.md). Check which wrap-up agents see before you go live.

1. Check that the instance's concurrent active chats quota covers your busiest time. Each contact that runs the guide uses one active chat, and one more if a wrap-up guide opens when the contact ends, such as the stack's wrap-up flow or the default after contact work guide from Connect Customer. See [Plan for scale](real-time-data-integration-limits.md).

1. Publish the flow.

1. Check the change with a test chat or a test call, as in [Test the guide with the inbound flow](#real-time-data-integration-test-chat), with these differences:
   + For a test chat, in **Contact Flow**, choose your own inbound flow, and leave **Contact Attributes (optional)** empty.
   + For a test call, call a test phone number whose **Flow / IVR** is your own inbound flow; see [Attach a claimed or ported phone number to a flow in Connect Customer](associate-claimed-ported-phone-number-to-flow.md).

   Your flow must route the contact to a queue the test agent serves, on that channel.

The change works when the guide opens with **Customer not found** on the test chat, or **Unknown caller** on the test call, because the test contact carries no verified value. If the guide doesn't open, check the **Set event flow** block for the **Default flow for Agent UI**, and that you published the flow. To see the guide open an account through your own flow, use a contact your verification step accepts, then test as in [Test and roll out to agents](real-time-data-integration-test.md).

## How the guide finds the record
<a name="real-time-data-integration-find-record"></a>

When a contact reaches the guide, the guide calls one flow module, Find the record, which reads the contact's attributes and returns the Salesforce record the contact is about. The stack's built-in module reads the following attributes, in this order, and the first that gives a record wins. Every lookup is an exact match, and each value is checked before any Salesforce call.


**Contact attributes the built-in Find the record module reads**  

| Attribute | What it can hold, and how the module reads it | What the agent sees first | 
| --- | --- | --- | 
| `accountId` | A Salesforce account ID, or else an account number. When it gives one account, the module also reads `caseId`. When it matches nothing, the module goes on to `caseId`. | One account: the account view. Two to five accounts with that account number: **Which record is this?**. | 
| `caseId` | A Salesforce case ID, or else a case number. With an account from `accountId`, the module keeps the case only if it is on that account; otherwise the account opens alone. On its own, `caseId` gives the case and the case's account. A case with no account gives nothing, and the module goes on to `contactEmail`. | The case view, marked **From this contact**, with **Back to the account**. | 
| `contactEmail` | A contact's email address, read only when `accountId` and `caseId` gave nothing. The module finds the accounts that have a contact with that email address. | One account: the account view. Two to five accounts: **Which record is this?**. | 
| None of them | No attribute is set, or none matches. | **Customer not found** on a chat, or **Unknown caller** on a call, with the searches. On a call, the screen offers the caller's number as a ready search. | 

When a Salesforce lookup fails, the screen's heading is **We couldn't look up this contact's record**, with the warning **This contact's record could not be looked up. Search for the customer.** and **Try again**, which runs Find the record again.

The guide overwrites `caseId` and `accountId` on the customer's contact as the agent works. Reports and flows that read them after the contact see the last case open in the guide, or `-` for no case, and the last account the guide showed. The guide keeps the value your inbound flow set in `caseId` in its own attribute, `arrivalCaseId`, until it has shown that case.

**Example: a signed-in customer starts a chat on your website**

1. The customer signs in to your website and starts a chat.

1. Your website's server starts the chat with a `StartChatContact` request whose attributes include `accountId` from the customer's session, or `contactEmail` with the address they signed in with. The server sets the value, so the customer's browser never supplies it. See [Pass contact attributes when a chat starts](pass-contact-attributes-chat.md).

1. Your inbound flow sets `customerContactId` and `customerChannel`, runs the **Set event flow** block for the guide, and the one for the wrap-up flow if you deployed it, and transfers the chat to a queue.

1. The agent sees the account view, or **Which record is this?** when the email address is on contacts of several accounts.

**Example: set accountId after your IVR verifies the caller**

In this example, the caller enters an account number and a PIN, and an AWS Lambda function that you write checks them against your own system and returns the Salesforce account ID:

1. Your inbound flow collects the account number and the PIN with **Store customer input** blocks, as it might already do for self-service.

1. An **AWS Lambda function** block calls your function with both values. The function verifies them in your own system. If they match, it looks up the customer's Salesforce account ID, for example from the account number, and returns `{"accountId": "001xx000003DGb2AAG"}`. If they don't match, it returns no `accountId`. Add the function to your instance first; see [Grant Connect Customer access to your AWS Lambda functions](connect-lambda-functions.md).

1. A **Set contact attributes** block sets the user-defined attribute `accountId` to the function's result, `$.External.accountId`, along with `customerContactId`, `customerChannel` and `customerPhone`.

1. The two **Set event flow** blocks in [Add the guide to your inbound flow](#real-time-data-integration-inbound-flow), then the transfer to the queue.

1. The agent sees the account view. When the function returns no `accountId`, the agent sees **Unknown caller** with the searches.

**Example: a known customer calls about a known case**

1. Your IVR verifies the caller and sets `accountId`, for example with an account number and a PIN.

1. A **Store customer input** block collects the case number, or a bot collects it in a slot.

1. On the branch where your flow verified the caller and set `accountId`, a **Set contact attributes** block sets `caseId` to the number, such as `$.StoredCustomerInput` after **Store customer input**. Because `accountId` is also set, the guide keeps the case only if it is on that account. On the branch where the caller isn't verified, leave `caseId` unset: `caseId` on its own opens the case and its account, so set it only from a verified source.

1. The agent sees the case view, marked **From this contact**. **Back to the account** opens the account view.

To choose the record your own way, for example from a bot conversation or by a rule in your system, build your own Find the record module and name it in the stack's **Find the record module** parameter (`FindRecordModuleArn`). Your module gets the same seven inputs as the built-in one, and can read `accountId`, `arrivalCaseId` and `contactEmail` from the contact; see [Extend the guide with flow modules](real-time-data-integration-modules.md).