Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Dialogflow cx adding plus & hypen to user utterance have numbers

Hi,

we have use-case where user is giving some order numbers and then making a webhook call, but getting plus & hypen symbol in the order number, how to remove those or not to add those in user utterance?
like user utterance is: 3226611004567 but getting +32-266-110-04567, need only numbers 3226611004567

0 1 118
1 REPLY 1

Hi @mayur4,

Welcome to Google Cloud Community!

I understand that you need guidance on how to remove the plus & hypen symbol in the order number in user utterance.

Here’s how to handle this in Dialogflow CX to extract only the digits:

1. Dialogflow CX Agent Design:

Use a Parameter: Create a parameter for the order number in your intent. This parameter will capture the user’s input, including any dashes or plus signs. For example, you could name it "orderNumber".

Regular Expression: Use a regular expression to extract the digits only. In your intent, within the parameter's "Entity Type," you'll see a section for "Regular Expression." Here's a suitable expression:

  \d+

This expression matches one or more digits (\d+) and will capture the entire sequence of digits from the user's input.

2. Webhook Handling:

In your webhook: You'll receive the order number as a parameter in the request payload.

Clean the Input: Before processing the order number, use your programming language's string manipulation functions to remove any non-digit characters.

For example, in Python:

order_number = request.get_json()["orderNumber"] 
order_number = ''.join(filter(str.isdigit, order_number)) 

3. Example Dialogflow CX Intent:

{
  "displayName": "OrderLookup",
  "trainingPhrases": [
    {
      "text": "My order number is +32-266-110-04567"
    },
    {
      "text": "I need to check on order 3226611004567"
    }
  ],
  "parameters": [
    {
      "name": "orderNumber",
      "displayName": "Order Number",
      "required": true,
      "entityType": "@sys.number",
      "isList": false,
      "regex": "\\d+" 
    }
  ],
  "webhook": {
    "disabled": false,
    "webhookUrl": "https://your-webhook-endpoint.com" // Replace with your actual webhook URL
  }
}

Here’s a breakdown of the JSON code above:

  • Parameter: The orderNumber parameter is defined, and it's required for the intent.
  • Entity Type: @sys.number indicates that Dialogflow understands this is a numeric input.
  • Regular Expression: The regex field uses the pattern \d+ to extract only digits.
  • Webhook: The webhook receives the orderNumber with only the digits.

Here’s additional key points to keep in mind:

  • Customize: Adjust the regular expression or cleaning logic based on your specific use case.
  • Error Handling: Implement error handling in your webhook to handle cases where the user provides an invalid order number.

I hope the above information is helpful.