In the final part of this tutorial series, you’ll learn how to pass user context (the information about the user that was captured during the dialog) back to DialogFlow from your fulfillment app so it can be presented back to the user in future requests. In this way, you can provide a much richer experience for the end-user. First, we’ll walk through an example use case and then implement it using DialogFlow and Apigee fulfillment. Example Use Case: Ordering Pizza Let’s say I want to order pizza using a voice interface. I tell my assistant: “Order me a pizza for dinner tonight,” and it responds “Sure thing! What kind of crust do you want?” Great! I respond “Pepperoni, please!” My assistant then confirms that I want pepperoni on my pizza (because pepperoni isn’t exactly what most people would consider pizza) by asking me if that’s what I meant (I say yes). Then she says “One large pepperoni pizza coming up with two toppings – are those correct?” Perfect! Now she just needs my address before placing my order. But there is one problem…I don’t remember where I live!! So instead of responding with something along the lines of “Alexa forgot your address,” Alexa simply asks me “What is your address?” This time I know what she’s referring to so type in my address and Alexa confirms everything is correct with an audio prompt like “Great! Your address is 123 Main St., thanks!” Alexa then says “Thanks for ordering a pepperoni pizza from Pizza Hut” as she places my order. Later that night when I get home from work, there’s no need for me to call Pizza Hut or ask Alexa again because Alexa sends an email/text message letting me know that my food has been delivered successfully (and in fact, with an option to cancel if for some reason it hasn’t been delivered yet). Pretty neat right? Let’s make this happen now!

Start Building Your Skill Using DialogFlow And Apigee Fulfillment

After you create a Dialogflow agent using the instructions in Part 1, let’s explore creating a fulfillment app. We’ll use Apigee to handle all of the voice aspects of this tutorial. I will not be going into too much detail on how to build an Alexa skill in the context of this tutorial, but there are a lot of great resources out there if you want to learn more! What we will cover here are: Creating an API via Apigee (this is already done for you when you create a DialogFlow Skill) Creating an Alexa Skill that can talk with your API Making your fulfillment app communicate with both DialogFlow and Alexa The first thing you will need to do is log into Apigee and select “Develop” from the top nav bar. If you don’t have an account yet, click here and follow the steps until you are logged in. Then select “Fulfillment” from the left nav menu. If this is your first time using Apigee then create a new client by clicking “New Client” in the top right corner of the screen and fill out all necessary information. Once created, add your client as a new project by selecting it from within your account dashboard along with selecting “Add Project.” Now we need to create our application. Click “APIs” from the left nav menu and select “Create New API.” Give it any name that makes sense to you – I called mine “Pizza Hut,” but feel free to call it whatever you’d like! Now let’s configure our new API so that we can put together our Alexa Skill! Expand out “Endpoints” under APIs and click on “Add Endpoint” at the bottom right corner of the screen. Fill out each field with what they represent as seen below:

give it any name that makes sense to you – I called mine “Pizza Hut,” but feel free to call it whatever you’d like! Now let’s configure our new API so that we can put together our Alexa Skill! Expand outunderand click onat the bottom right corner of the screen.

Fill out each field with what they represent as seen below: Create Method: POST URL : https://dev-api-key-here/pizzahut/v1/orders Service : pizza_hut_alexa Policy : PUT Response Policy : 200 Headers Mode : Request Headers Only Body Type : JSON Body Content Type: application/json Access Control List (ACL): Public Scope Rules: None Checkout Policies : Global Keep Auth Token : checked Sample Request Header Content Type: application/json Payload Content Type(s): template(application/json) Sample Request Body Content Type(s): template(application/json) Sample Response Status Code(s): 200 , 201 , 202 , 400 , or 500 Specify Secret Key Expires On: Never Maximum Age (in seconds): 0 Agent Certificate Expiry Date (in seconds): never Use Custom Expiry Date Field? Yes Custom Expiry Date Field Name: custom_expiry_date Data Format String Template Id: id Create Custom Variables? No Add Default Values? Yes Default Value Values Array Ids (string format only): id Response Object Id Id Name Data Format String Template Id Comments Add more endpoints ? No Click Save Changes when finished and back in your main Apigee dashboard, go ahead and enable SSL for your newly created endpoint by expanding it out and checking off SSL support under “Additional Information” on its main config page. Let’s also go ahead now and make sure that incoming webhook requests sent from DialogFlow will be accepted by turning them on via Manage Webhook Connections within Developer Settings at https://dev-api-key-here/. If everything went well, then check back over here once everything has been set up correctly or reach us at support@apigee.com if anything looks wonky or isn’t working correctly! Next we’ll need some sample data so we can test things before going live with real requests sent from an actual user interacting with our mobile app (or other means). So expand out Endpoints again under APIs, select one of them – maybe one without any methods created yet – then click on Edit Endpoint under Actions > Edit Endpoint . You’ll see something similar shown below where there is no method defined under Methods . So go ahead now and add Method Create Application ID for Voice To get started building my Pizza Order App I used XCode which requires me set up my own Apple Developer Account . Within XCode choose Create Your First App > Single View App .

Make sure ‘Use Storyboards’ is unchecked while ‘Use Core Data’ is checked off near bottom left side of screen like image below . Choose any organization identifier , name & language . Choose iPhone | Swift & Next . For device names choose iPhone 6 | iPhone 6 Plus | iPhone 5 | iPad Air 2 | iPad mini 4 | iPad Pro 12 inch & Next . For default options choose Album Example App & Next .

Choose Main Interface & Finish Now open ViewController scene then find viewDidLoad() method inside ViewController class which located under Standard Editor tab; // Define variables var pizzaOrderRequestApiURL = “\ https://dev-api-key-here.apigee.com/pizzahut/v1/orders”; var pizzaOrderRequestApiParams = [ { name : “order_#”, value : “My Order” } ]; // Create a local object with the above variables let pizzeriaOrderRequest = PizzaHutOrderRequest () // Create an API call and print out response body from Apigee Fulfillment Logger . debug ( “PizzaHutOrderRequest() – printing out response” ) logger . debug ( “\(pizzeriaOrderRequest.requestUrl)” ) logger . debug ( “\(pizzeriaOrderRequest.requestMethod)” ) logger . debug ( “\(pizzeriaOrderRequest.bodyJSONDictionary)” ) pizzeriaOrderRequest . requestURL = pizzaOrderRequestApiURL pizzeriaOrderRequest . requestMethod = HTTP_METHODS . POST pizzeriaOrderRequest . bodyJSONDictionary = pizzaOrderrequestAPIParams let urlResponseString = “” let resultArrayOfDictionariesFromAPILoggingFunctionCall = try? JSONSerialization.jsonObject(with: domLoggerResult, options: []) if resultArrayOfDictionariesFromAPILoggingFunctionCall != nil { urlResponseString = resultArrayOfDictionariesFromAPILoggingFunctionCall!.stringForKey(“urlResponse”) } else { urlResponseString = “Error” } Logger.info(“PizzaHutOrder(): IPAddress – \(urlResponseString)”) return urlResponseString Note: Replace dev-api-key in the first line with your own Apigee API key for this project’s namespace otherwise it will fail to work!

Note: Replace dev-api-key in the first line with your own Apigee API key for this project’s namespace otherwise it will fail to work!


Marco Lopes

Excessive Crafter of Things

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *