# Case 1. Data Purchase

## Before you begin

* This tutorial requires a webhook setup. Add a test webhook URL `http://mock-webhook.mind.ai` to your webhook settings.
* This tutorial requires "customer\_name", "customer\_number" global keys in the Scope.
* The entity MSISDN is going to be used for this tutorial. It can be found on the System(Extensible) tab of Entities.

**MSISDN**

**Regex Pattern Block 1**

**REGEX PATTERN** `[nN]?[fF] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9]`

**DESCRIPTION** `9 digits: 1st digit can be n or N, 2nd digit can be f or F`

**Regex Pattern Block 2**

**REGEX PATTERN** `[1,2,3,6,8,9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9]` ?\[0-9]

**DESCRIPTION** `7 digits: 1st digit can be 1,2,3,`6,8,9

**Regex Pattern Block 3**

**REGEX PATTERN** `[1,2,3,6,8,9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9]`

**DESCRIPTION** `8 digits: 1st digit can be 1,2,3,6,8,9`

**Regex Pattern Block 4**

**REGEX PATTERN** `[0,1,2,6,8,9]-?[0-9]-?[0-9]-?[0-9]-?[0-9]-?[0-9]-?[0-9]-?[0-9]-?[0-9](-?[0-9A-Za-z])?`

**DESCRIPTION** `10 digits with " - " in between of each digit`

**Regex Pattern Block 5**

**REGEX PATTERN** `[0,1,2,6,8,9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9] ?[0-9]( ?[0-9A-Za-z])?`

**DESCRIPTION** `10 digits: 1st digit can be 0,1,2,6,8,9 and last digit can be 0-9, A-Z, a-z)`

### Add a Subject

1. Click **Add Subject** on the Scope details page.
2. Select the Query Freestyle tab.
3. Enter a Subject name.
4. Enter Query Statement which is the expected customer query as "Can I purchase more data?"
5. Click **Recognize Statement** to get the Recognition Result. The **Recommended Statement** is the statement which is semantically related to more ontologies and can generally capture more statement structures with the same intent. To use the recommended statement, just tick the checkbox saying **Use Recommended Statement**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FUShRfA9zx9MH46cgmRLX%2Fimage.png?alt=media&#x26;token=980eca02-c735-444a-803b-3d43ca9b82f8" alt=""><figcaption></figcaption></figure>

6\. **Additional Query Statement to Recognize** may also be used in case of multiple statements being able to trigger the subject.

7\. Click **Add**

### Build the Subject

#### Step 1: Data Purchase

1. Name the first Step "Data Purchase".

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FC5RH0XFLUmaRmCYW8cBU%2Fimage.png?alt=media&#x26;token=b1ee6caa-a456-4373-a6be-7413aa29c902" alt=""><figcaption></figcaption></figure>

2\. Click **Add Component** in the Components panel.

3\. Click **Parameter Bundle**.

4\. In the popup, enter a Parameter Bundle name as "Purchase" and Parameter names as "Data Plan", "Name", "Number". Set them as required.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FMTKDWluLicP6LNXMgh7x%2Fimage.png?alt=media&#x26;token=62f24589-59e2-4c6a-aa6d-1c4466e98a43" alt=""><figcaption></figcaption></figure>

5\. Click **Add**.

6\. To set up the Data Plan Parameter, select the **Compound Value** tab in the Component Settings panel.

7\. Enter the `Local Binding Key` as "data\_plan".

8\. Click **Set up Entity Type**.

9\. In the popup, click on **System(Extensible)** tab.

10\. Select the `MSISDN` entity type.

11\. Click **Submit**.

12\. Enter Designator. Key Path.

```
$.data-list.data-id
```

13\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FCpGnuigpKAgrNDblWwsG%2Fimage.png?alt=media&#x26;token=5074e231-d786-4598-896a-0dcc7b51d0d6" alt=""><figcaption></figcaption></figure>

14\. Click **Add Action** in the Conversational panel.

15\. Under Check for Parameter, click **Check**.

16\. In the Action Settings panel, select the Combined tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FyDE78463ebAC8RqchuBW%2Fimage.png?alt=media&#x26;token=7b0e9ae0-260a-4be6-94fd-ba695669e734" alt=""><figcaption></figcaption></figure>

17\. Choose a webhook URL <http://mock-webhook.mind.ai> to use from the dropdown and enter URL Parameter (domain path and/or query string) as tutorial/mobile-data-list?code=200.

**Webhook URL (Method: GET)**

**BASE URL** `http://mock-webhook.mind.ai`

**URL PARAMETER** `tutorial/mobile-data-list?code=200`

***

**Response Body**

```
{
 "data-list": [
  {
   "data-id": "21000000",
   "name": "1GB Extra Data",
   "amount": "$3",
   "data": "1GB"
  },
  {
   "data-id": "22000001",
   "name": "2GB Extra Data",
   "amount": "$5",
   "data": "2GB"
  },
  {
   "data-id": "23000002",
   "name": "3GB Extra Data",
   "amount": "$7",
   "data": "3GB"
  },
  {
   "data-id": "24000003",
   "name": "4GB Extra Data",
   "amount": "$9",
   "data": "4GB"
  },
  {
   "data-id": "25000004",
   "name": "5GB Extra Data",
   "amount": "$11",
   "data": "5GB"
  }
 ]
}
```

18\. \*\*\*\* Select the `GET` request method.

19\. Select an error message display method as `Template` and select an action as Terminate to take in case of HTTP 400. If `Passthrough` is selected, the webhook response will be displayed without modification.

20\. Enter an error message that will be displayed to the customer.

```
Sorry, I am terminating the session.
```

21\. Enter Key and JSONPath pairings for Result Mapping.

**KEY** `data_list`

**JSONPATH** `$.data-list`

22\. Enter the instruction.

```
Sure thing. These are the mobile data you can purchase.

{{#data_list}}
- ID: {{data-id}}
- Data: {{data}}
- Amount: {{amount}}
---------------------------------
{{/data_list}}
```

24\. Enter `Prompt` "How much data would you like to purchase?", then click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FJZuGFmQz4SqBOn38tiHm%2Fimage.png?alt=media&#x26;token=03fed871-3417-47a6-8255-9d72345e7efb" alt=""><figcaption></figcaption></figure>

25\. Select the Name Parameter in the Component panel.

26\. In the Component Settings panel, stay with the Single Value tab.

27\. For the Binding Key, select the Global tab and choose the `customer_name` global binding key.

28\. Click **Set up Entity Type**.

29\. In the popup, select the **System Entities** tab.

30\. Select the **Any Entity** entity type.

31\. Click **Submit**.

32\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2F3dqaYDZl16LbMW01nQYN%2Fimage.png?alt=media&#x26;token=4f0b5a5a-2d4d-4158-bebd-01509a88a345" alt=""><figcaption></figcaption></figure>

33\. Click **Add Action** in the Conversational panel.

34\. Under Check for Parameter, click **Check**.

35\. In the `Action Settings` panel, stay in the `Customer` tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FmU5or5iDzEhxt48Mcexv%2Fimage.png?alt=media&#x26;token=7ff14401-5f1b-42d5-b553-0d77956785a3" alt=""><figcaption></figcaption></figure>

36\. In the `Instruction to show before the prompt`, enter "Let me verify your name and your number."

37\. Enter the `Prompt` as "What is your name?"

38\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FujPDXyLGt7kHuc4EgLvt%2Fimage.png?alt=media&#x26;token=2b5a28fa-bccd-4e17-9a80-518f47e75131" alt=""><figcaption></figcaption></figure>

39\. Select the Number Parameter in the Component panel.

40\. In the Component Settings panel, stay with the Single Value tab.

41\. For the Binding Key, select the Global tab and choose the `customer_number` global binding key.

42\. Click **Set up Entity Type**.

43\. In the popup, click the **System(Extensible)** tab.

44\. Select the **MSISDN** entity type.

45\. Click **Submit**.

46\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FGwwuD374yP8Uft48M16M%2Fimage.png?alt=media&#x26;token=e3fe679c-dcb4-4eed-947d-11d3a9cd841e" alt=""><figcaption></figcaption></figure>

47\. Click **Add Action** in the Conversational panel.

48\. Under Check for Parameter, click **Check**.

49\. In the Action Settings panel, stay in the Customer tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FO17i6JgNq1K3VuYQ0IiI%2Fimage.png?alt=media&#x26;token=a3edd4c9-1f59-4e8d-9c18-a00b0bd1bec0" alt=""><figcaption></figcaption></figure>

50\. Enter the `Prompt` as "Thanks, {{customer\_name}}. What is your number?"

51\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2F1y0rxKYpZZfPmW1IQzq5%2Fimage.png?alt=media&#x26;token=dea98e9f-7b62-4c37-99d8-d11e3247cc83" alt=""><figcaption></figcaption></figure>

52\. Click **Add Action** in the Conversational panel.

53\. Click **Confirm**

54\. Select the **Webhook** tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2Fvp9BiYGA2FzdrWi8FTM8%2Fimage.png?alt=media&#x26;token=f067f362-e047-4db9-a88f-90831bca1084" alt=""><figcaption></figcaption></figure>

55\. Choose a webhook URL `http://mock-webhook.mind.ai/` to use from the dropdown and enter URL Parameter (domain path and/or query string) as `tutorial/validate-name-phone?code=200&out=valid`. It will return affirmation.

**Webhook URL (Method: POST)**

**BASE URL** `http://mock-webhook.mind`.ai

**URL PARAMETER** `tutorial/validate-name-phone?code=200&out=valid`

\*\*\*\*

**Request Parameter**

```
out=valid - Returns affirmation
out=invalid - Returns negation
```

**Response Body (out=valid)**

```
{
  "validate-result": "valid",
  "name": "Rachel",
  "phone": "123123123",
  "amount": "$11"
}
```

**Response Body (out=invalid)**

```
{
  "validate-result": "invalid",
  "name": "Rachel",
  "phone": "123123123",
  "amount": ""
}
```

56\. Select the request method as `POST`. For the `POST` request, you can enter the Request Body if needed. Enter the `Request Body` as stated below:

**Request Body**

```
{
  "data-id": "{{data-id}}",
  "name": "{{name}}",
  "phone": "{{phone}}"
}
```

57\. Select an error message display method as `Template` and select an action as `Terminate` to take in case of HTTP 400. If `Passthrough` is selected, the webhook response will be displayed without modification.

58\. Enter an error message that will be displayed to the customer.

```
Sorry, I am terminating the session.
```

59\. Enter a JSONPath for Expected Value Matching Path.

```
$.validate-result
```

60\. Enter a value for Expected Value.

```
valid
```

61\. Select an action as `Terminate` to take in case of getting the opposing value. Enter the message "Sorry, I am terminating the session." to display to the customer.

62\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FP6b6EAk7d4y9ob5Ze97X%2Fimage.png?alt=media&#x26;token=8f23b173-9a7d-4cf4-9d36-9663d0926f43" alt=""><figcaption></figcaption></figure>

63\. Click **Confirm** under Completion of Parameter Bundle.

64\. In the Action Settings panel, select the `Combined` tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2F268IuEQh6EJWomff8wAx%2Fimage.png?alt=media&#x26;token=e56d0acc-6c55-4183-a1da-9549f3d99b17" alt=""><figcaption></figcaption></figure>

65\. Choose a webhook URL `http://mock-webhook.mind.ai` to use from the dropdown and enter URL Parameter (domain path and/or query string) as `tutorial/mobile-data-detail?code=200`. It will return affirmation.

**Webhook URL (Method: POST)**

**BASE URL** `http://mock-webhook.mind.ai`

**URL PARAMETER** `tutorial/mobile-data-detail?code=200`

***

**Response Body**

```
{
  "data-id": "21000000",
  "name": "1GB Extra Data",
  "amount": "$3",
  "data": "1GB"
}
```

66\. Select the request method as POST. For the POST request, you can enter the Request Body if needed. Enter the Request Body.

**Request Body**

```
{
  "data-id": "{{data_plan}}"
}
```

67\. Select an error message display method as Template and select an action as Terminate to take in case of HTTP 400. If Passthrough is selected, the webhook response will be displayed without modification.

68\. Enter an error message that will be displayed to the customer.

```
Sorry, I am terminating the session.
```

69\. Enter a Key and JSONPath pairing for Result Mapping.

**KEY** `data_amount`

**JSONPATH** `$.amount`

70\. Enter the prompt as "{{data\_amount}} will be added to your bill for this month. Would you like to continue?".

71\. Set the Expected Response as `Affirmation`.

72\. Select an action as `Try again` to take on opposing response. Enter an error message to display to the customer.

73\. Click **Save**.

![](https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FBzKUKzWI4IQNCCSqEfJC%2F73.png?alt=media\&token=bd53d88c-e971-4610-8f03-a1a6ac0fb181)

#### Step 2: Response

1. Add another Step and name it "Response".

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FcpJd8LkUGIfAd4VTDNJX%2Fimage.png?alt=media&#x26;token=f8f813ec-fcd4-497e-885e-c994411686c5" alt=""><figcaption></figcaption></figure>

2\. Click **Add Component** in the Components panel.

3\. Click **Condition**.

4\. Name the Condition "Confirmation".

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FBTwOlmDEUX1UNdQxzyWI%2Fimage.png?alt=media&#x26;token=651b2dd7-0472-4c3c-b9c2-7623472408e6" alt=""><figcaption></figcaption></figure>

5\. Click **Add**.

6\. Stay with the autofilled Query Term then tick off the Query Statement option.

7\. Click **Save**.

8\. Click **Add Action** in the Conversational panel.

9\. Click **Show response** under Completion of Condition.

10\. In the Action Settings panel, select the `Webhook` tab.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FcwuohXBLaUBYlWsJR06T%2Fimage.png?alt=media&#x26;token=6d410d25-7f35-4c36-b213-3d435044e906" alt=""><figcaption></figcaption></figure>

11\. Choose a webhook URL `http://mock-webhook.mind.ai` to use from the dropdown and enter URL Parameter (domain path and/or query string) as `tutorial/confirm-data-purchase?code=200`

**Webhook URL (Method: POST)**

**BASE URL** `http://mock-webhook.mind.ai http://mock-webhook.mind.ai`

**URL PARAMETER** `tutorial/confirm-data-purchase?code=200`

***

**Response Body**

```
{
  "name": "Rachel",
  "phone": "123123123",
  "data": "5GB",
  "remain": "5.5GB"
}
```

12\. Select the request method as `POST`. For the `POST` request, you can enter the Request Body if needed. Enter the Request Body.

**Request Body**

```
{
 "data-id": "{{data_plan}}",
 "name": "{{name}}",
 "phone": "{{phone}}"
}
```

13\. \*\*\*\* Select an error message display method as `Template` and select an action as `Terminate` to take in case of HTTP 400. If `Passthrough` is selected, the webhook response will be displayed without modification.

14\. Enter an error message that will be displayed to the customer.

```
Sorry, I am terminating the session.
```

15\. Keep the Mapping toggle on.

16\. Enter Key and JSONPath pairings for Result Mapping.

**Result Mapping Pair 1**

**KEY** `data_final`

**JSONPATH** `$.data`

**Result Mapping Pair 2**

**KEY** `remain`

**JSONPATH** `$.remain`

17\. Enter the template to show to the customer as a response.

```
{{data_final}} is added to your account, and your remaining data is {{remain}}.
```

18\. Click **Save**.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FD0n0KW82sZyNPzjCY7mq%2Fimage.png?alt=media&#x26;token=08b0c344-e5fb-498b-b582-57b75a6b18b5" alt=""><figcaption></figcaption></figure>

19\. Click **Publish** to publish the Subject.

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FQNs210cwabh2qfwMejJa%2Fimage.png?alt=media&#x26;token=bebe88ec-4ebf-48d0-939c-180a07b81054" alt=""><figcaption></figcaption></figure>

20\. To test the subject, click on the sandbox button on the right side of the screen and enter the query statement configured, in this case, `I would like to purchase more data` .

<figure><img src="https://2637928320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRqPwZJVepiA6JYXHnaO%2Fuploads%2FUseGfT6lyDAWXF6daHDQ%2Fimage.png?alt=media&#x26;token=5a4dc877-4607-45af-bb43-9283fda2472f" alt=""><figcaption></figcaption></figure>

\\
