Bots can do a lot with static messages, menus, and Embedded Code. But if you want to bring in dynamic content or real-time data, accomplish tasks outside of the chat interface, you’re probably going to need to connect your bot to another service using a web API.
Web Responders provide an easy interface for connecting with RESTful web APIs and parsing returned JSON data.
Most of the configuration for this should be self explanatory.
Name — how your Responder is identified in the platform
Webhook — the URL of the web service
Headers — a series of key/value pairs, added to the header of the REQUEST
Params — a series of key/value pairs, added to the URL as parameters to the REQUEST (Note: REQUEST parameters are appended to the URL for both GET and POST methods. If you want to send data in the REQUEST payload, use the Post Body)
- Method — POST or GET
- If the Method is POST, an additional input window opens, allowing you to define a Post Body.
- Depending on how you format Post Body (and the needs of your web service), you may also want to specify a Content-Type in your Headers.
Result Type — provides several options for how the JSON results from your API call should be presented back to the user.
Using Variables in Your API Requests¶
All of the input fields in the Responder setup can include curly-braced Variables.
Displaying Results to the User¶
After a Responder completes its call and receives a response, you can respond to the user the same way you would inside a Message, except you have the JSON data returned by your responder.
Within the Results setup, details from the API response can be accessed inside curly braces, with $ representing the JSON document root.
If you have a single text response message you want returned to the user, set your Result Type to Text. Audio, Video accept a URL, and embed the content into the chat window. Button lets you respond to the user with a text message and up to three buttons.
If you need to present a menu-like list of items to the user, try a Structured Tiles.
To iterate through a set of elements within the JSON response, use parentelement[i] within the curly braces. (Again, $ represents the document root.)
For more details, see the Newsbot example.