/api-ai-agent

Example Java api.ai agent using twilio SMS and google places search - find a squash court !

Primary LanguageJavaApache License 2.0Apache-2.0

license

Example api.ai with twilio programmatic SMS application.

Example agent integrating api.ai with twilio SMS service.

Text +1 (831) 77-SQUASH

You can test this directly by texting SMS @ +1-831-777-8274

  • Type find a court near [enter your city, location], will find squash courts anywhere in the world.
  • If more than one result, you can ask for subset by typing e.g. : 'first 2'.

Deploy

Edit the Google Maps API key to the configuration file: src/main/resources/config.properties :

google.places.apikey=<YOUR_GOOGLE_API_KEY>

Edit pom.xml as per your application, run maven build, deploy to heroku :

mvn clean heroku:deploy-war

After deployment of the war file to the servlet container, go to http://api.ai Configure your Fulfillment Webhook URL (which is the REST endpoint, defined using SparkJava), and set as enabled :

<YOUR_SERVER_URL>/webhook
https://api-ai-agent-khan-squash.herokuapp.com/webhook

* The parameters and actions are defined in api.ai console, and are specific to this application. The actions serve as router type values, these are defined in api.ai. The Java CONSTANTS are mapped to these values. The parameters are also defined in the intents in api.ai and are subsequently used to retrieve the values from the JSON payloads. This is a simplistic application. Using a Case Switch - as essentially a controller, is admittedly a bit crude. Good controller design is beyond the scope of this example application.

  // Actions used in intents
  public static final String FIND_COURTS_ACTION = "findCourts";
  public static final String LIST_COURTS_ACTION = "listCourts";

  // Parameters used in intents
  public static final String GEO_CITY_PARAMETER = "geo-city";
  public static final String GEO_STATE_PARAMETER = "geo-state-us";
  public static final String LIST_COUNT_PARAMETER = "count";

** Included in this project is an export of the agent used in this application [KhanSquashIO.zip] (https://raw.githubusercontent.com/mrisney/api-ai-agent/master/export/KhanSquashIO.zip)