What are Webhooks & How can they help you?
How are webhooks used?
Have you ever wondered how all of those travel sites get all the flight prices from so many different airlines? Imagine a process where Orbitz representatives are on the phone calling American Airlines, Delta, Jetblue, and requesting the new prices since the last time they called. Then they would take that price and enter into their site so that their end users could book the flight. By the time all of this was done, it’s more likely that prices would have changed again and the information that the user is looking at is no longer accurate. The Solution: Instead of doing all that manual scraping, companies like Orbitz simply send your flight criteria to all the airlines and return the results to their own site, with a webhook using a REST API service.
What are webhooks?
“Webhooks” (WH) is just a way of describing the use of third-party APIs to pull data or content into a site, without changing the overall structure or code. They can be triggered by different events in a site. (e.g. clicking “Search” in Orbitz). When triggered, the webhook makes requests to the API it needs to pull data from. Typically included in that request are the criteria or “parameters” that users input, (e.g. Destination: New York, Flight Type: Non-stop). The API passes those criteria to a server where they are processed and sent back with response data. (e.g. 10 flight options from $ - $$$$). This “conversation” allows a service to pull in data and content from any third party service back to their site without having to scrape data on the web or doing any processing on its own servers.
Webhooks: A Lesson in Lingo
There are a few terms that are important to grasp before describing and understanding how the webhooks process works.
API Endpoint: this is the API URL of the 3rd party service that the requests will be sent to. Every API is unique, so It is important that the requests being sent match the expected structure that the API is configured for.
Request Parameters: The data values that are sent to the API in order to return the desired response.
JSON Response: This is the response returned to the requesting service with information. Responses can come in a variety of formats from JSON to XML or Raw Text.
How does Instabot use webhooks?
Recently, we released a webhooks integration tool within our Instabot Builder. This allows you to configure a webhooks for any API you have access to, in order to pull outside data into your bots. This means that your bot doesn’t need to know the answers to all questions before you can ask a user. You can simply pass their responses to a 3rd party API via the WH configuration and receive results just like the aforementioned Orbitz use case.
For example, let's say I wanted to build a bot that provided users with a recipe based on ingredients they already have at home. The conversation could be built so that it asks the user for some information:
Name all your ingredients you want to use.
The user’s answer would then be sent to an API which could interpret those ingredients and pass them to a recipe service (the Food2Fork API happens to do just that). The service would then quickly search its database for available recipes that include those ingredients and send the list back to Instabot. The end user could then choose from this list and be directed to full recipes to try or search again with other ingredients.
With webhooks, the possibilities and use cases are endless. You can utilize them to create conversations that are dynamic and react to the user’s needs leading to increased engagement. The beauty is that WH enable any data source that has an API available to be included in your conversation.
Play around with our Recipe bot below and see how we used the Food2Fork API to create a bot that helps you find a meal using ingredients you already have.
Check it out! https://instabotdemo.roko.mobi/wh/nytimes.html
Have any questions about webhooks or how to use them in bots? Just ask. E-mail us at firstname.lastname@example.org