Mockservice.io

Mockservice.io — a tool that can help you implements chatbots

Have you ever wanted to use JSON API plugin in Chatfuel or External Request in ManyChat, but you didn’t know how to deploy quickly an external API? Or maybe you knew how to deploy it, but you wanted to focus on the chatbot’s logic, not on additional API infrastructure? Today we will show you a way you can simulate external API and thus extend your chatbot with dynamic elements. Look at Mockservice.io!

Mockservice.io

Mockservice.io is a tool that allows you to mock the API without a need to set up an additional server. What does it mean? It helps you define a series of rules which on matching certain request returns pre-defined response and other associated parameters like response code, headers, etc.

What Mockservice.io offers?

  • Unlimited number of endpoints (rules)
  • Intuitive UI (you don’t need to have the programming knowledge to define endpoints)
  • Team-work cooperating (based on user permissions)
  • SSL (you can expose an endpoint using https protocol, which is required for most chatbot builder tools)
  • Delayed responses (simulating long-running processing)
  • Dynamic response body (you can build response dynamically by using JS code — based on incoming request)
  • Real-time endpoints monitoring

What features do we consider shortly? Firstly we plan to build “Endpoint templates gallery” — set of predefined requests/responses of public APIs. What does it exactly mean? If you want to simulate API response from public API you will be able to search for a specified template, import it to your project and adjust the chosen template to your needs. And how about building API that returns image/text/gallery in Chatfuel or ManyChat format? You don’t have to investigate documentation anymore — you will be able to add a suitable template to your project and properly adjust added JSON. Sounds simple? It has to sound like that.

In the next paragraph, I will show you a simple example of using Mockservice.io. More advanced using (chatbot case) I will introduce in the next section.

What we can do easily and quickly is creating a simple endpoint, which returns us users’ data. To do this you have to log in into Mockservice Paneland create a new project:

Test project

Next thing you need to do is adding endpoint (you have to define endpoint path and sample response):

Sample endpoint

Open your browser and try to invoke already configured endpoint. Verify that received JSON data is equal to predefined endpoint response body. Let’s test it:

Sample endpoint result

As you can see, we just have created https endpoint in less than 5 minutes.

JSON API

How we can use Mockservice.io in chatbot’s build process? Let’s imagine a case when your chatbot needs interact with external API to save/get/update some information, but that API isn’t ready yet. In such cases, Mockservice.io allows you to create a fake API and simulate real API responses.

There are special plugins available in most of chatabot’s tools to interact with external APIs. In Chatfuel you can use JSON API plugin and in ManyChat you can use External Request (only in Premium version).

Now I will show you how to do it using JSON API in Chatfuel. This plugin allows your bot to send GET and POST requests to external API and interpret responses.

It allows you to:

  • Generate dynamic content
  • Get and set user attributes
  • Redirect users to another block in the bot
  • Create postbacks
  • Display galleries
  • Display buttons
  • etc.

A proper format of JSON interpretable by Chatfuel you can find HERE.

One possible scenario in a chatbot is order something by a user, sending order information to a backend, saving and send back a summary message. If we have already created an API, which can process it we can use it, but the problem is when the API isn’t ready yet. In this case, we have two options:

Let’s assume that placing an order consisted of a sequence of questions, collecting answers about the ordered food and setting responses to the following attributes:

  • pizza_name: Prosciutto
  • amount: 1
  • drink: not

The next step is sending them to our backend and save the order. As we assumed earlier — our API isn’t ready yet, so we can simulate it using Mockservice.io. To do this you have to create a new project (name it accordingly) and add an endpoint to simulate real API response (I called it Saving Order). As an HTTP method, I chose POST and as path I set: /order/save.

The endpoint we’ve prepared in this way isn’t very useful yet. It returns the empty response for now, but you can add it to Chatfuel, before starting to mock endpoint response. To do this you have to copy the endpoint URL and go to Chatfuel. Then you have to add JSON API plugin at the end of the order process, paste copied URL inside it, set request type as POST and fill body with earlier specified attributes.

Now you have to set a suitable response body in Mockservice.io. Assuming that chatbot should send a message with order summary, you have to set Body, based on JSON API documentation. I have set the following JSON:

{
"messages": [
{"text": "Thank you for your order."},
{"text": "You will receive it soon."}
]
}
Endpoint configuration

Now we should receive thanks message after order a pizza. Will it happen? Let’s see:

Chatbot test

Visit website: https://mockservice.io

Share: