Awesome Open Source
Awesome Open Source

botbuilder-viber

NPM version NPM downloads

A node module for Microsoft BotBuilder Framework.

This module provides plug-in Viber connector for Microsoft BotBuilder framework.

botbuilder-viber currently supports the following tracking features:

  • sending text, image, buttons, stickers messages
  • receiving text messages
  • receiving images
  • receiving other messages as text message [json] with message.attachments[0] filled with raw Viber message:
{
    payload: rawMessage, /* json from viber directly */
    contentType: 'object',
}

Getting started

botbuilder-viber is installed just like any other node module:

$ npm i botbuilder-viber

In your bot's app.js:

var viber = require('botbuilder-viber')
...
var viberOptions = {
  Token: process.env.VIBER_TOKEN,
  Name: 'ViberBotName',  
  AvatarUrl: 'http://url.to/pngfile'
}
var viberChannel = new viber.ViberEnabledConnector(viberOptions)
//after initialising your bot and existing connectors 
bot.connector(viber.ViberChannelId, viberChannel)
app.use('/viber/webhook', viberChannel.listen())

When the bot starts, you need to register your webhook with Viber.

Url of the webhook will be the url of your bot appended /viber/webhook.

Example: https://botappservice.azurewebsites.net/viber/webhook

botbuilder-viber requires express instead of restify like most BotBuilder samples do.

Sending stickers

var viberPayload = {}
viberPayload[viber.ViberChannelId] = {
    "type": "sticker",
    "sticker_id": 114406
}
var stickerMessage = new builder.Message(session).sourceEvent(viberPayload)
session.send(stickerMessage)

How to find out Viber's sticker ids?

Viber API documentation

Viber REST API

Other information

  • This BotBuilder is working on top of viber-node module: https://github.com/Viber/viber-bot-node
  • It can probably send whole set of different messages Viber supports (Text, Url, Contact, Picture, Video, Location, Sticker, File)
  • Avatar is recommended to be 720x720, and no more than 100kb (otherwise will not show on mobile clients). Use tinypng to make it smaller.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (68,034
nodejs (3,632
chat (372
chatbot (289
connector (27

Find Open Source By Browsing 7,000 Topics Across 59 Categories