|
| 1 | +// Copyright 2022 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * Configures a webhook to set form parameters as optional/required |
| 17 | + */ |
| 18 | + |
| 19 | +// [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] |
| 20 | + |
| 21 | +exports.configureOptionalFormParam = (request, response) => { |
| 22 | + // The value of the parameter that the webhook will set as optional or required. |
| 23 | + // Note that the webhook cannot add or remove any form parameter |
| 24 | + const parameter = request.body.pageInfo.formInfo.parameterInfo[0].value; |
| 25 | + |
| 26 | + const jsonResponse = { |
| 27 | + pageInfo: { |
| 28 | + formInfo: { |
| 29 | + parameterInfo: [ |
| 30 | + { |
| 31 | + displayName: parameter, |
| 32 | + // if required: false, the agent will not reprompt for this parameter, even if the state is 'INVALID' |
| 33 | + required: true, |
| 34 | + state: 'VALID', |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + }, |
| 39 | + }; |
| 40 | + |
| 41 | + // Info about form parameter that is sent in the webhook response: |
| 42 | + console.log( |
| 43 | + 'Parameter Info: \n', |
| 44 | + jsonResponse.pageInfo.formInfo.parameterInfo[0] |
| 45 | + ); |
| 46 | + |
| 47 | + response.send(jsonResponse); |
| 48 | +}; |
| 49 | +// [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] |
0 commit comments