Send HTTP requests and store data in the Context object
Many use cases require fetching data from an external API. An HTTP request is an easy way to exchange data with 3rd party systems. The Context object is designed to hold such and other data during the user session of conversational interaction.
#1 Create a new Flow
Create a new Flow and name it "Developer Flow".
#2 Create a Question Node
Add a Question Node, select Type Text. Use the text “What is your favorite Star Wars character?”
#3 Send an HTTP Request
For this tutorial, we’ll use the popular Star Wars API to fetch some demo data. Add an HTTP Request Node after the Question Node. Select Type GET. The URL should be this:
https://swapi.dev/api/people/?search={{input.text}}
The object {{input.result}} represents the user input and is used as a search query. The API will return a list of all Star Wars characters in the database that match the user input. Open the “Storage Options” menu and navigate to Context Key. This is the attribute that can later be used to work with the data. In this example, use this key:
result_character
#4 See the results in the Context object
Use the Interaction Panel and process through the VA’s dialog. Type in “Luke” as an example. Now navigate to Info and Context. You’ll see a "result_character" JSON object that holds the info retrieved from the API.
#DONE! Now let's process data and build custom logic to enhance your Virtual Agent!
Comments
2 comments