How do I pass through a string to an Intent unprocessed?

Updated 1 month ago by Matthew Clementson

The system entity sys.any allows you to match any string during the execution of an intent flow. Unlike other entities, sys.any simply passes what the user types to your webhook with no further processing.

Sys.any can be useful when you are trying to add an entity to an intent that does no match any of the built-in system entities and that is difficult or impossible to model as custom entity.

For example, say you want to build a bot that can talk to your customers so they can book an appointment with you. And you want to build an intent so your bot can collect location, phone number, and last name of the person who is requesting a meeting with you.

While handling location and phone number can be easily done by adding a sys.places and sys.number entity to your intent, you will not be able to easily create a custom entity to capture the user last name. That will require you to enumerate every possible last name that exists. To solve this problem, you can use a sys.any entity instead.

Lets try to build an actual bot that does the things discussed here.

Step 1 - Create a 'booking' intent

The booking intent will have 3 entities:

  • Location -- a sys.places system entity to capture the meeting location
  • Phone -- a sys.number system entity to capture the user phone number
  • Last Name -- a sys.any system entity to capture the user last name

Once your done, your entity section should look like this

sys.any example

Step 2 - Catpure sys.any in your webhook

Sys.any variables can be accessed like any other variables. For example, the following sample python code implements a webhook to will print back the variables it receives from your bot.

    import argparse
              import random
              import json
              import sys
              from flask import Flask
              from flask_restful import Api, reqparse, Resource
              from flask import request
              app = Flask(__name__)
              api = Api(app)
              parser = reqparse.RequestParser()
              parser.add_argument('memoryVariables', type=dict, action='append')
              parser.add_argument('chatResult', type=dict)
              class sample_webhook(Resource):
                  def post(self):
                      args = parser.parse_args()
                      variables = args['memoryVariables']
                      return {"text": variables}, 200
              api.add_resource(sample_webhook, '/getVariables')
              if __name__ == "__main__":
                  p = argparse.ArgumentParser()
                  p.add_argument('port', type=int)
                  args = p.parse_args()
        '',debug=True, port=args.port)

Remember you will need to host your webhoook somewhere and update your intent so it will point to it.

sys.any example

How did we do?