# Webhooks

{% hint style="info" %}
**To learn more about eva's features that use webhooks:**

* [Services cell](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/develop-your-bot/dialog-cells/service-cells)
* [Transactional Answers](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/develop-your-bot/dialog-cells/answer-cells#e-transactional-answer)
  {% endhint %}

## Basic request and response <a href="#basic-request-and-response" id="basic-request-and-response"></a>

The webhooks have the same base request, called conversation event. The information in this event is common for all webhooks, and each one add the information needed for its execution.

### Basic request body <a href="#basic-request-body" id="basic-request-body"></a>

| **Name**           | **Type**    | **Required** | **Description**                                                                                              |
| ------------------ | ----------- | ------------ | ------------------------------------------------------------------------------------------------------------ |
| **text**           | String      | No           | User inputted text or transcription from audio.                                                              |
| **code**           | String      | No           | Code sent by the channel. See conversation service.                                                          |
| **info**           | Info        | Yes          | Information about the virtual agent, channel and session of the current transaction                          |
| **entities**       | Entity\[]   | No           | List of entities returned by the NLP                                                                         |
| **intents**        | Intent\[]   | No           | List of intents returned by the NLP                                                                          |
| **openContext**    | JSON Object | No           | See [open context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture)    |
| **visibleContext** | JSON Object | No           | See [visible context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture) |
| **hiddenContext**  | JSON Object | No           | See [hidden context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture)  |

### Info <a href="#info" id="info"></a>

| **Name**                                                               | **Type** | **Required** | **Description**                                                                     |
| ---------------------------------------------------------------------- | -------- | ------------ | ----------------------------------------------------------------------------------- |
| **bot**                                                                | String   | Yes          | Name of the virtual agent                                                           |
| **operatingSystem**                                                    | String   | Yes          | Same as conversation service                                                        |
| <p><strong>operatingSystem</strong></p><p><strong>Version</strong></p> | String   | No           | Same as conversation service                                                        |
| **browser**                                                            | String   | No           | Same as conversation service                                                        |
| **browserVersion**                                                     | String   | No           | Same as conversation service                                                        |
| **userRef**                                                            | String   | Yes          | Same as conversation service                                                        |
| **businessKey**                                                        | String   | No           | Same as conversation service                                                        |
| **locale**                                                             | String   | Yes          | Same as conversation service                                                        |
| **channelName**                                                        | String   | Yes          | Name of the channel                                                                 |
| **channelType**                                                        | String   | Yes          | Type of the channel (i.e. Web, Whatsapp)                                            |
| **channelClassification**                                              | String   | Yes          | Classification for the types of channel (i.e. Messaging Platform, Smart Assistants) |
| **sessionCode**                                                        | String   | Yes          | Same as conversation service                                                        |

### Intent <a href="#intent" id="intent"></a>

| **Name**       | **Type** | **Required** | **Description**                                                                     |
| -------------- | -------- | ------------ | ----------------------------------------------------------------------------------- |
| **name**       | String   | Yes          | Name of the intent, same as the NLP                                                 |
| **confidence** | Double   | Yes          | Confidence score returned by the NLP, this will be a percentage number from 0 to 1. |

### Entity <a href="#entity" id="entity"></a>

| **Name** | **Type** | **Required** | **Description**                                      |
| -------- | -------- | ------------ | ---------------------------------------------------- |
| name     | String   | Yes          | Name of the entity, same as the NLP.                 |
| value    | String   | Yes          | The value of the entity returned by the NLP.         |
| position | Position | No           | Position of the string within the user input (text). |

### Position <a href="#position" id="position"></a>

| **Name** | **Type** | **Required** | **Description**   |
| -------- | -------- | ------------ | ----------------- |
| start    | Integer  | No           | Starting position |
| end      | Integer  | No           | End position      |

### Basic response body <a href="#basic-response-body" id="basic-response-body"></a>

| **Name**       | **Type**    | **Required** | **Description**                                                                                              |
| -------------- | ----------- | ------------ | ------------------------------------------------------------------------------------------------------------ |
| openContext    | JSON Object | No           | See [open context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture)    |
| visibleContext | JSON Object | No           | See [visible context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture) |
| hiddenContext  | JSON Object | No           | See [hidden context](https://docs.eva.bot/user-guide/v/_eva-3.4.1_1/using-eva/experience/base-architecture)  |

## Transactional answer <a href="#transactional-answer" id="transactional-answer"></a>

In the Cockpit, when creating an answer, there is an option to mark the answer as “transactional”. If this option is checked, the webhook field appears. Enabling this options means that this answer has dynamic content that must replaced by the webhook.

![](https://gblobscdn.gitbook.com/assets%2Fdocs%2F-MXDZaqaEC6PaNEVLv7s%2F-MXDZkUpyUpQATxas4WP%2F20.png?alt=media)

When this answer is executed by eva, the webhook is called so it can modify the answer before delivering it to the user. This functionality is used to make answers dynamic.

### Request body <a href="#request-body" id="request-body"></a>

This service will add the following fields to the [basic request body](https://docs.eva.bot/user-guide/for-technicians/api-guidelines/webhooks#basic-response-body).

| **Name** | **Type**       | **Required** | **Description**                       |
| -------- | -------------- | ------------ | ------------------------------------- |
| answer   | AnswerTemplate | Yes          | Answer as created through the Cockpit |

### Answer Template <a href="#answer-template" id="answer-template"></a>

| **Name**      | **Type**             | **Required** | **Description**                                                                                                                                                          |
| ------------- | -------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| content       | Content              | Yes          | The content is based on the template selected through the Cockpit                                                                                                        |
| template      | String               | Yes          | <p>Template selected in the Cockpit.</p><p>See Answer.type</p>                                                                                                           |
| technicalText | String or JSONObject | No           | <p>This field is used for specific behaviours for an answer. It is an open field in the Cockpit. The type depends on how the field is filled in the Cockpit.</p><p>.</p> |

### Content <a href="#content" id="content"></a>

| **Name**    | **Type**  | **Required** | **Description**                                                             |
| ----------- | --------- | ------------ | --------------------------------------------------------------------------- |
| content     | Any       | Yes          | <p>This content can be a Carousel or a String.</p><p>See Answer.content</p> |
| description | String    | No           | Same description as created through the Cockpit.                            |
| type        | String    | No           | See AnswerTemplate.template                                                 |
| buttons     | Button\[] | No           | See Answer.buttons                                                          |
| quickReply  | Button\[] | No           | See Answer.quickReply                                                       |

### Response body <a href="#response-body" id="response-body"></a>

This service will add the following fields to the [basic response body](https://docs.eva.bot/user-guide/for-technicians/api-guidelines/webhooks#basic-response-body).

| **Name** | **Type**       | **Required** | **Description**                       |
| -------- | -------------- | ------------ | ------------------------------------- |
| answer   | AnswerTemplate | Yes          | Answer as created through the Cockpit |

### Sample request <a href="#sample-request" id="sample-request"></a>

When eva is executing an answer marked as transactional, it will send a request like the one below. In this example, the user said “hi there!” and we want to greet the user back, but replacing the \[NAME] string with the user’s name.

```
{
   "answer": {
      "content": {
         "content": "Hi, [NAME]. How may I help you?",
         "description": "Dynamic user greeting",
         "type": "TEXT",
         "buttons": [],
         "quickReply": []
      },
      "template": "TEXT"
   },
   "info": {
      "bot": "MyBot",
      "channelName": "MyHomepage",
      "channelType": "Web",
      "channelClassification": "Mobile / Tablet / Desktop",
      "sessionCode": "beaf7d7d-2642-4827-bc51-ecf74ba64dd8",
      "operatingSystem": "Windows",
      "operatingSystemVersion": "10",
      "browser": "",
      "browserVersion": "",
      "userRef": "200.222.134.27",
      "businessKey": "5662988",
      "locale": "en-US"
   },
   "text": "hi there!",
   "openContext": {
      "unsafeVar": 55
   },
   "visibleContext": {
      "unsafeVarRO": "foo"
   },
   "hiddenContext": {
      "id": 6722
   },
   "intents": [
      {
         "name": "HELLO",
         "confidence": 0.987576
      },
      {
         "name": "GOODBYE",
         "confidence": 0.147442
      }
   ],
   "entities": []
}
```

### &#x20;Sample response <a href="#sample-response" id="sample-response"></a>

Continuing the example above, this webhook will call another service to fetch the user info using the *id* that is stored in the *hiddenContext* (this data cannot be shared with other systems).

After calling another service, we will load the user data inside the safe context and change the content of the answer.

```
{
   "answer": {
      "content": {
         "content": "Hi, John. How may I help you?",
         "description": "Dynamic user greeting",
         "type": "TEXT",
         "buttons": [],
         "quickReply": []
      },
      "template": "TEXT"
   },
   "openContext": {
      "unsafeVar": 55
   },
   "visibleContext": {
      "unsafeVarRO": "foo"
   },
   "hiddenContext": {
      "id": 6722,
      "clientInfo": {
         "name": "John Doe",
         "id": 6722,
         "birthdate": "1980-03-03",
         "document": "87237236722"
      }
   }
}
```

## Service cell <a href="#service-cell" id="service-cell"></a>

| Method: | **POST**             |
| ------- | -------------------- |
| Type:   | **application/json** |

While the Transactional answer is used to dynamically change the content of the answer, the Service cell is used to change the flow of the dialogue. For example, when a user asks for his balance, the virtual agent might have to check if the user is a client before continuing the flow, fetching his balance (giving a transactional answer) if he is a client or asking him if he wants to become one if he is not a client.

In this example the service is called to check if the user is either a CLIENT or NOT\_CLIENT.

![Since the service call can return an error, the SERVICE ERROR is shown](https://gblobscdn.gitbook.com/assets%2Fdocs%2F-MXDZaqaEC6PaNEVLv7s%2F-MXDZkUqTTaQDZVnSIao%2F21.png?alt=media)

### Request body <a href="#request-body-1" id="request-body-1"></a>

This service will add the following fields to the [basic request body](https://docs.eva.bot/user-guide/for-technicians/api-guidelines/webhooks#basic-response-body).

| Name            | **Type**  | **Required** | **Description**                                                                               |
| --------------- | --------- | ------------ | --------------------------------------------------------------------------------------------- |
| expectedOptions | String\[] | Yes          | List of options created through the Cockpit. In the example above “CLIENT” and “NOT\_CLIENT”. |

### Response body <a href="#response-body-1" id="response-body-1"></a>

This service will add the following fields to the [basic response body](https://docs.eva.bot/user-guide/for-technicians/api-guidelines/webhooks#basic-response-body).

| **Name** | **Type** | **Required** | **Description**                                                                     |
| -------- | -------- | ------------ | ----------------------------------------------------------------------------------- |
| option   | String   | Yes          | Single option to be interpreted by the Dialog Manager and change the dialogue flow. |

### Sample request <a href="#sample-request-1" id="sample-request-1"></a>

In this example we will check if the user is a client or not using an ID that is present in the context.

```
{
   "expectedOptions": [
      "CLIENT",
      "NOT_CLIENT"
   ],
   "info": {
      "bot": "MyBot",
      "channelName": "MyHomepage",
      "channelType": "Web",
      "channelClassification": "Mobile / Tablet / Desktop",
      "sessionCode": "beaf7d7d-2642-4827-bc51-ecf74ba64dd8",
      "operatingSystem": "Windows",
      "operatingSystemVersion": "10",
      "browser": "",
      "browserVersion": "",
      "userRef": "200.222.134.27",
      "businessKey": "5662988",
      "locale": "en-US"
   },
   "text": "hi there!",
   "openContext": {
      "unsafeVar": 55
   },
   "visibleContext": {
      "unsafeVarRO": "foo"
   },
   "hiddenContext": {
      "id": 6722
   },
   "intents": [
      {
         "name": "HELLO",
         "confidence": 0.987576
      },
      {
         "name": "GOODBYE",
         "confidence": 0.147442
      }
   ],
   "entities": []
}
```

### Sample response <a href="#sample-response-1" id="sample-response-1"></a>

The example below is telling the Dialog Manager to execute the flow continuing from the CLIENT option.

```
{
   "option": "CLIENT",
   "openContext": {
      "unsafeVar": 55
   },
   "visibleContext": {
      "unsafeVarRO": "foo"
   },
   "hiddenContext": {
      "id": 6722,
      "clientInfo": {
         "name": "John Doe",
         "id": 6722,
         "birthdate": "1980-03-03",
         "document": "87237236722"
      }
   }
}
```
