Creating a Viber chatbot

Viber recently opened up an interface for chat-bot automation. Claudia Bot Builder, since version 2.5.0, allows you to easily create and deploy chat bots for the new Viber platform. In this set-by-step tutorial, you’ll learn how to create a Viber chat-bot and deploy it to AWS Lambda.

Prerequisites

If you’re completely new to using Claudia.js, check out Installing and configuring Claudia.js for information on how to set up access credentials.

Creating the Viber Public Account

To create a Viber bot, you will need to create a Public Account (PA). The PA represents an account of a company, celebrity, person or product. After your Public Account is approved, you will be able to get the authentication token from the Public Account. You’ll need this later to configure the bot.

Creating a Viber bot

First, create an empty folder, and a new NPM project inside it. Just make sure to give it a descriptive name:

npm init

Add the claudia-bot-builder library as a project dependency:

npm install claudia-bot-builder -S

Let’s first create a very simple bot, just to check that everything is configured correctly. Create a file called bot.js with the following content:

var botBuilder = require('claudia-bot-builder');

module.exports = botBuilder(function (request) {
  return 'Thanks for sending ' + request.text;
});

This bot will just reply back with the same message it received. Later on, we’ll modify it to do something more interesting.

Deploying your Viber bot

You can now deploy the bot to AWS:

claudia create --region us-east-1 --api-module bot --configure-viber-bot

The api-module parameter is the name of your JavaScript module (if you saved the code as bot.js, this will be just bot).

While deploying, Claudia will ask for your Viber Public Account Access Token. It will then automatically create the right web hooks for the Viber bot platform. In a few moments, your bot will be online and you will be able to chat to it using Viber.

Viber Chat bot screenshot

And that’s it.

Did you like this tutorial? Get notified when we publish the next one.

Once a month, high value mailing list, no ads or spam. (Check out the past issues)