The feedback
[prebuilt component](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component.md.txt)
collects quantitative and qualitative feedback from users.

The component first performs a lookup using the configured
`Check last feedback` webhook to check whether a user has provided feedback
recently. If no recent feedback exists, the component asks the user to provide a
quantitative feedback score between 1 and 5. If the feedback is negative, the
component can collect freeform qualitative feedback from the user.

## Limitations

In addition to the
[common prebuilt component limitations](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component.md.txt#limits),
this prebuilt component includes the following limitations:

- The component assumes that you maintain customer phone numbers in a Customer Relationship Management (CRM) system or another service.
- This component doesn't authenticate existing customers who use an alternate phone number to contact you.

## Sample dialogs

The sample dialogs show common scenarios that this prebuilt component handles.
They demonstrate behavior when the user calls the component using telephony,
which triggers the Default Welcome Intent and the first agent response at the
start of the conversation.

### Positive feedback

The response from the [Check last feedback webhook](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component/feedback.md.txt#check_last_feedback)
indicates that the user hasn't provided feedback recently. The agent requests
the user's feedback score, and the user provides a score indicating a positive
experience.

| User Input | Agent Response |
|---|---|
|   | Thank you for calling. Your feedback is important to us. Please take a moment to share your opinion of the service you received today by answering a few short questions. On a scale of 1 to 5, where 1 is most unsatisfied and 5 is most satisfied, how satisfied are you with the service you received today? |
| 5 |   |
|   | Great, thank you for your positive feedback. |

### Negative feedback

The response from the [Check last feedback webhook](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component/feedback.md.txt#check_last_feedback)
indicates that the user hasn't provided feedback recently. The agent requests
the user's feedback score, and the user provides a score indicating a negative
experience. The agent then requests qualitative feedback from the user.

| User Input | Agent Response |
|---|---|
|   | Thank you for calling. Your feedback is important to us. Please take a moment to share your opinion of the service you received today by answering a few short questions. On a scale of 1 to 5, where 1 is most unsatisfied and 5 is most satisfied, how satisfied are you with the service you received today? |
| 2 |   |
|   | Thank you for your feedback. Tell us how we can improve this experience for you. |
| Some of my questions weren't answered completely. |   |
|   | Thanks for your feedback. We apologize for the inconvenience caused to you and strive to give you a better experience next time. |

### Recent feedback

The response from the [Check last feedback webhook](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component/feedback.md.txt#check_last_feedback)
indicates that the user has provided feedback recently, so the agent doesn't ask
the user for further input.

| User Input | Agent Response |
|---|---|
|   | Thank you for reaching out to us. |

### Invalid input

The response from the [Check last feedback webhook](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component/feedback.md.txt#check_last_feedback)
indicates that the user hasn't provided feedback recently. The agent
requests the user's feedback score, and the user provides invalid input
multiple times. The component ends the flow with failure.

| User Input | Agent Response |
|---|---|
|   | Thank you for calling. Your feedback is important to us. Please take a moment to share your opinion of the service you received today by answering a few short questions. On a scale of 1 to 5, where 1 is most unsatisfied and 5 is most satisfied, how satisfied are you with the service you received today? |
| -1 |   |
|   | Sorry, we didn't get that. Enter a feedback score that is 1, 2, 3, 4, or 5. |
| 100 |   |
|   | Sorry, we didn't get that. Enter a feedback score that is 1, 2, 3, 4, or 5. |
| Nice |   |
|   | We're sorry, but the maximum number of retries has been exceeded. Please try again after some time. |

## Naming conventions

This prebuilt component uses the following naming conventions:

| Feature | Format | Example |
|---|---|---|
| Flow | \[Component Name\] | Feedback |
| Parameter | \[param_name\] | feedback_score |
| Webhook | prebuilt_components_\[component_name\]:\[webhook_action\] | prebuilt_components_feedback:last_feedback_check |

## Input parameters

Input parameters configure certain behaviors of the component. One or more
conditions within the flow use these parameters to determine how the
component behaves. You must set flow-scoped parameters on the start page of
the component as described below. You can set session-scoped parameters by
using a calling flow or on the start page of this component.

This prebuilt component accepts the following input parameters:

| Parameter Name | Description | Input Format |
|---|---|---|
| $session.params.phone_number | The user's local phone number, which is used to identify the user in API requests. The phone number shouldn't include the country code. | string |
| $flow.minimum_feedback_score | Indicates the threshold for what is considered a negative or positive feedback score. A low score (equal to or less than this parameter's value) indicates a negative experience and a high score (greater than this parameter's value) indicates a positive experience. If a low score is provided by the user, qualitative feedback is requested from the user, asking them how the experience can be improved. The default value for this parameter is `3`. | integer |
| $flow.feedback_max_retry_count | A configurable parameter that captures the maximum number of retries that are provided to a user. The value assigned to this parameter should be one less than the number of the tries available. The default value is `2`, which means that the caller gets three tries to provide the requested information. | integer |

#### To configure the input parameters for this component, expand for instructions.

1. Open the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects).
2. Choose your Google Cloud project.
3. Select your agent.
4. Select the **Build** tab.
5. Click the imported component in the **Flows** section.
6. Click the Start Page in the **Pages** section.
7. Click the **true** Route in the Start Page.
8. In the Route window, edit the **Parameter Presets** values as needed.
9. Click **Save**.

## Output parameters

Output parameters are session parameters that remain active after exiting the
component. These parameters contain important information collected by the
component.

This prebuilt component provides values for the following output parameters:

| Parameter Name | Description | Output Format |
|---|---|---|
| feedback_score | Captures the feedback score provided by the user. Valid values are integers between 1 and 5, inclusive. | integer |
| feedback_comment | Captures the qualitative comments provided by the user, if any. | string |
| transfer_reason | Indicates the reason the flow exited, if it's not successful. The returned value is one of the following: `agent`: the user requested a human agent at some point during the conversation. `denial_of_information`: the user declined to share information requested by the component. `max_no_input`: the conversation reached the maximum number of retries for no-input events. See [no-input built-in events](https://docs.cloud.google.com/dialogflow/cx/docs/concept/handler.md.txt#event-built-in). `max_no_match`: the conversation reached the maximum number of retries for no-match events. See [no-match built-in events](https://docs.cloud.google.com/dialogflow/cx/docs/concept/handler.md.txt#event-built-in). `webhook_error`: a webhook error occurred. See [webhook.error built-in event](https://docs.cloud.google.com/dialogflow/cx/docs/concept/handler.md.txt#event-built-in). `webhook_not_found`: a webhook URL was unreachable. See [webhook.error.not-found built-in event](https://docs.cloud.google.com/dialogflow/cx/docs/concept/handler.md.txt#event-built-in). | string |

## Basic setup

To set up this prebuilt component:

1. [Import the prebuilt component](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component.md.txt#import).
2. Configure the provided [flexible webhooks](https://docs.cloud.google.com/dialogflow/cx/docs/concept/webhook.md.txt#flexible) with your external services. For more information, see the [Webhook setup](https://docs.cloud.google.com/dialogflow/cx/docs/concept/prebuilt-component/feedback.md.txt#webhook-setup) section.

## Webhook setup

To use this component, configure the included
[flexible webhooks](https://docs.cloud.google.com/dialogflow/cx/docs/concept/webhook.md.txt#flexible) to retrieve
necessary information from your external services.

### Check last feedback

The component uses the `prebuilt_components_feedback:last_feedback_check`
webhook to check whether the user has provided feedback recently. The external
service integrated with this webhook defines the time period during which
previously provided feedback counts as recent, and the service owner can
configure this period.

#### API request parameters

The component provides the following parameters as inputs to the API request:

| Parameter Name | Description | Input Format |
|---|---|---|
| phone_number | The user's local phone number, without the country code, used to identify the user. | string |

#### API response parameters

The component retrieves the following parameters from the API response:

| Parameter Name | Description | Output Format |
|---|---|---|
| last_feedback_time_elapsed | Indicates whether feedback has been provided by the user recently. `true` indicates that enough time has elapsed since the user last gave feedback and that no recent feedback was found. `false` indicates that feedback was provided recently, and not enough time has elapsed since the user last gave feedback. | boolean |

#### To configure the Check last feedback webhook for this component, expand for instructions.

1. Open the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects).
2. Choose your Google Cloud project.
3. Select your agent.
4. Select the **Manage** tab.
5. Click **Webhooks**.
6. Select the prebuilt_components_feedback:last_feedback_check webhook.
7. Replace the URL in the Dialogflow CX **Webhook URL** field with the endpoint for the service you want to integrate with. Select the proper **Method** in the dropdown.
8. Review and update the **Request body** to form the proper request format for your webhook.
9. Review and update the **Response configuration** to extract specific fields from your webhook's response. Do not modify the parameter names, as these are required by the component to access the returned field values.
10. Review and update the **Authentication** settings as needed.
11. Click **Save**.

### Update feedback

The component uses the `prebuilt_components_feedback:update_feedback` webhook
to send collected feedback to an external service.

#### API request parameters

The component provides the following parameters as inputs to the API request:

| Parameter Name | Description | Input Format |
|---|---|---|
| phone_number | The user's local phone number, without the country code, used to identify the user. | string |
| feedback_score | Stores the feedback score provided by the user. Expected values are integers between 1 and 5, inclusive. | integer |
| feedback_comment | Stores the qualitative feedback comment provided by the user. | string |

#### To configure the Update feedback webhook for this component, expand for instructions.

1. Open the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects).
2. Choose your Google Cloud project.
3. Select your agent.
4. Select the **Manage** tab.
5. Click **Webhooks**.
6. Select the prebuilt_components_feedback:update_feedback webhook.
7. Replace the URL in the Dialogflow CX **Webhook URL** field with the endpoint for the service you want to integrate with. Select the proper **Method** in the dropdown.
8. Review and update the **Request body** to form the proper request format for your webhook.
9. Review and update the **Response configuration** to extract specific fields from your webhook's response. Do not modify the parameter names, as these are required by the component to access the returned field values.
10. Review and update the **Authentication** settings as needed.
11. Click **Save**.

### Complete

The feedback prebuilt component and its webhooks are now set up and ready to
test.