Create your own Viber Chatbot in Minutes

Mehfuz Hossain
Smartloop
Published in
5 min readNov 7, 2017

There there is a new version of the blog post available, please read it here: https://blog.smartloop.ai/createviber-chatbot-in-minutes-b3d6ae175484

Builder Dashboard

Viber was founded in Israel in 2010 and today it has over 900 million users. According to sources it is ranked as #3 after Facebook and WhatsApp with a large user base, mostly in Europe and Asia.

In this post, I am going to show how to quickly create a Viber chatbot with dynamic data. I am creating a very simple weather bot that will pull data from openweather.org for a given city with the forecast.

First, create your free smartloop.ai account. Then create a Weather Bot by clicking the +Create New Bot button.

Once you hit “Submit”. Smartloop will do the following:

  1. Create a container specific to the subscription to run the bot.
  2. Create the basic blocks like (start, about, default) to give you an idea of the flow.
  3. Configure the underlying AI.

Now click on your weather bot to go into the build tab, you should see the following once everything is ready:

Next, I am going to use the built-in JSON API plugin. This is one of the core plugins that comes out of the box with our new chatbot builder. There is also a “Script Block” option to bring in your own custom logic to the conversation flow but that is a topic for another post, therefore, stay tuned! The JSON API plugin quickly lets you embed data from an external source. Think of it as POSTMAN.

There are a few different things that you can do with the plugin, including setting query string parameters, customer headers, and POST body. You can pass results to the conversation flow by setting a user variable as shown above.

Before, I dive more into details, first create the intent for the weather bot. Let’s call it “location” and configure it for a common weather question. Add “How is the weather in Paris?” in the Define Expression tab.

Highlight **Paris** as an entity and mark it as “location” this will give AI the pattern that will be used to resolve similar expressions. This part is commonly referred to as training.

Next step is to make a request to the weather API and pull the current forecast based on geo-location. Here I have to do the following:

  1. Use lat / lng from the resolved location entity. It is available as a variable for use from the conversation context.
  2. Make a request to the weather API with lat/lng from #1 to get the weather forecast and set it as a user variable to use in the next step.

The first step is to set the entity lat/lng as a query parameter.

Here, I have used {{nlp.entities.location}} to get the location object from resolved entities.

Check out the resources link below to find out more about context variables.

Tip: You can easily debug the context variables from within “Cloud Code” and you can access them throughout your conversation flow as a template variable by using *double braces* syntax.

Next, make a GET request to openweathermap.org API to retrieve the current forecast:

https://api.openweathermap.org/data/2.5/weather

Copy and paste the following Query string JSON to your JSON API plugin as shown above:

{
"lat": "{{nlp.entities.location.0.lat}}",
"lon": "{{nlp.entities.location.0.lng}}",
"appid": "APP_ID",
"units": "imperial"
}

Complete the step by replacing the APP_ID with yours from openweathermap.org and defining the {{result}} variable.

Configure the conversation UI by adding the following elements:

1. Add Text response for current weather:

Currently in {{nlp.entities.location.0.formatted}}  it's {{result.main.temp}}°F.

3. Add Text response for the forecast:

Today's forecast: {{result.weather.0.description}} and with high of {{result.main.temp_max}}°F  and a low of {{result.main.temp_min}}°F.

Lastly, test your bot making sure everything is working correctly:

Click on the publish icon from the left navigation bar and connect your bot. Follow the instructions in “Create a Bot” wizard to create a new Viber chatbot. Please refer to the viber developer documentation on how to create a bot account.

Go to your Viber desktop or mobile app and start chatting with the bot.

Weather Bot Demo

We would love to hear what bots you are creating in Viber. If you have feedback and want to share it with us then drop us a line at hello@smartloop.ai. We would be glad to assist you.

Finally, if you liked reading the post, please share it and we always love to hear from you for feedback in improving the product and adding features that make you more productive. Also, don’t forget to check out the resources below and reach to support@smartloop.ai for more information.

--

--