Giter Club home page Giter Club logo

botbuilder-viber's Introduction

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.

botbuilder-viber's People

Contributors

alexsorokoletov avatar ebt-asorokoletov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

botbuilder-viber's Issues

Error ERR_INVALID_ARG_TYPE when sending message from Viber bot

Platform

Operating System: Ubuntu
Node Version: 9.3.0
NPM Version: 5.5.1

Code

https://github.com/DreamTeamMobile/botbuilder-viber
https://github.com/expressjs/express
https://github.com/expressjs/body-parser

var viber = require('botbuilder-viber');
var express = require('express');
var bodyParser = require('body-parser');

var viberOptions = {
  Token: '***',
  Name: '***',
  AvatarUrl: '***'
}
var viberChannel = new viber.ViberEnabledConnector(viberOptions);

var expressApp = express();

expressApp.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log("Express server is running.");
});

expressApp.use(bodyParser.urlencoded({ extended: false }));

expressApp.use(bodyParser.json());

bot.connector(viber.ViberChannelId, viberChannel);

expressApp.use('/viber/webhook', viberChannel.listen());

Expected Behavior

No error

Actual Behavior

Error (repeats twice everytime) when I sending message from my viber bot.

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, TypedArray, or DataView
at Hmac.update (internal/crypto/hash.js:53:11)
at MessageValidator._calculateHmacFromMessage (/app/node_modules/viber-bot/lib/message/message-validator.js:17:54)
at MessageValidator.validateMessage (/app/node_modules/viber-bot/lib/message/message-validator.js:11:30)
at _app.use (/app/node_modules/viber-bot/lib/middleware.js:61:32)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at textParser (/app/node_modules/body-parser/lib/types/text.js:60:7)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at query (/app/node_modules/express/lib/middleware/query.js:45:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, TypedArray, or DataView
at Hmac.update (internal/crypto/hash.js:53:11)
at MessageValidator._calculateHmacFromMessage (/app/node_modules/viber-bot/lib/message/message-validator.js:17:54)
at MessageValidator.validateMessage (/app/node_modules/viber-bot/lib/message/message-validator.js:11:30)
at _app.use (/app/node_modules/viber-bot/lib/middleware.js:61:32)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at textParser (/app/node_modules/body-parser/lib/types/text.js:60:7)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at query (/app/node_modules/express/lib/middleware/query.js:45:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)

Webhook: Data must be a string error

Hi,

We are using the same example as in instructions and using express app. When registering webhook, we are getting this error. Any help would be appreciated.

TypeError: Data must be a string or a buffer
at TypeError (native)
at Hmac.Hash.update (crypto.js:74:16)
at MessageValidator._calculateHmacFromMessage (....\node_modules\viber-bot\lib\message\message-validator.js:17:54)

How to register viberConnector on botframwork v4?

@alexsorokoletov @alexeystrakh
There seems to be drastic differences in the botframework v4 with V3. As I understand on V3 the viberConnector was registered with this line of code

//after initialising your bot and existing connectors
bot.connector(viber.ViberChannelId, viberChannel)

How would you achieve the same on V4?. Maybe use the botframework-connector package?

[Question] Does this library partially support Hero Card?

On Kik, hero card is supported like this.
image 2017-10-29 12 45 00

So it is possible for this library to support hero card like this.
image 2017-10-29 12 45 04

The question is, do you guys have this feature? Cuz you guys only mentioned this, which isn't really detailed:

It can probably send whole set of different messages Viber supports (Text, Url, Contact, Picture, Video, Location, Sticker, File)

Can't reply to messages

Action: Send any message to the bot (The bot is supposed to reply to every message)

Result: No reply

2017-11-09T14:23:31.909639+00:00 app[web.1]: �[36m[2017-11-09 14:23:31.908] [DEBUG] �[39m�[36mValidating signature 'undefined' == '8e2424a0e9f276633233d569ac17b55efca8b8389f520d65eed4b6d16ae58978'�[39m

Might be Is actually a problem with viber-bot-node but they don't even have a issue section. I used restify for middleware though (Since botbuilder uses restify anyways).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.