Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
// Viber bot specifics
const ViberBot = require('viber-bot').Bot;
const BotEvents = require('viber-bot').Events;
const TextMessage = require('viber-bot').Message.Text;
// Microsoft Bot Framework (MBF) - DirectLine - Connector
const MbfBotConnector = require('mbf-directline').Core;
const MbfEvents = require('mbf-directline').Events;
const MbfPlatformViber = require('mbf-directline').Platform.Viber;
// Utilities
const winston = require('winston');
const toYAML = require('winston-console-formatter');
require('dotenv').config();
// config items
const ViberBotName = 'MBF Connector';
const ViberBotImageUrl = 'https://raw.githubusercontent.com/devrelv/drop/master/151-icon.png';
const ViberPublicAccountAccessTokenKey = 'xxxxxxxxxxxxxxxxxx'; // ToDo: Replace with your Viber Public Account access token
const MbfEvents = require(__dirname + '/mbf-events');
const Swagger = require('swagger-client');
const open = require('open');
// ATTENTION this implementation does only support the V3 bots
const directLineSpecV3 = require(__dirname + '/directline-swagger-v3.json');
// Viber Messages
const TextMessage = require('viber-bot').Message.Text;
const PictureMessage = require('viber-bot').Message.Picture;
const UrlMessage = require('viber-bot').Message.Url;
const ContactMessage = require('viber-bot').Message.Contact;
const VideoMessage = require('viber-bot').Message.Video;
const LocationMessage = require('viber-bot').Message.Location;
const StickerMessage = require('viber-bot').Message.Sticker;
const FileMessage = require('viber-bot').Message.File;
// MBF Activities
const MessageActivity = require(__dirname + '/activity/messageActivity.js').MessageActivity;
// config items
const defaultPollInterval = 1000;
const defaultDirectLineClientName = 'ViberBotConnector';
const defaultDirectLineSecret = 'xxxxxxxxxxxxxxxxxxxxx'; // ToDo: Replace with your Microsoft Bot Framework DirectLine secret
class MicrosoftBot extends EventEmitter {
constructor(logger, platform, options) {
super();
this._logger = logger;
this._platform = platform;
const EventEmitter = require('events');
const MbfEvents = require(__dirname + '/mbf-events');
const Swagger = require('swagger-client');
const open = require('open');
// ATTENTION this implementation does only support the V3 bots
const directLineSpecV3 = require(__dirname + '/directline-swagger-v3.json');
// Viber Messages
const TextMessage = require('viber-bot').Message.Text;
const PictureMessage = require('viber-bot').Message.Picture;
const UrlMessage = require('viber-bot').Message.Url;
const ContactMessage = require('viber-bot').Message.Contact;
const VideoMessage = require('viber-bot').Message.Video;
const LocationMessage = require('viber-bot').Message.Location;
const StickerMessage = require('viber-bot').Message.Sticker;
const FileMessage = require('viber-bot').Message.File;
// MBF Activities
const MessageActivity = require(__dirname + '/activity/messageActivity.js').MessageActivity;
// config items
const defaultPollInterval = 1000;
const defaultDirectLineClientName = 'ViberBotConnector';
const defaultDirectLineSecret = 'xxxxxxxxxxxxxxxxxxxxx'; // ToDo: Replace with your Microsoft Bot Framework DirectLine secret
class MicrosoftBot extends EventEmitter {
constructor(logger, platform, options) {
super();
"use strict";
const EventEmitter = require('events');
const MbfEvents = require(__dirname + '/mbf-events');
const Swagger = require('swagger-client');
const open = require('open');
// ATTENTION this implementation does only support the V3 bots
const directLineSpecV3 = require(__dirname + '/directline-swagger-v3.json');
// Viber Messages
const TextMessage = require('viber-bot').Message.Text;
const PictureMessage = require('viber-bot').Message.Picture;
const UrlMessage = require('viber-bot').Message.Url;
const ContactMessage = require('viber-bot').Message.Contact;
const VideoMessage = require('viber-bot').Message.Video;
const LocationMessage = require('viber-bot').Message.Location;
const StickerMessage = require('viber-bot').Message.Sticker;
const FileMessage = require('viber-bot').Message.File;
// MBF Activities
const MessageActivity = require(__dirname + '/activity/messageActivity.js').MessageActivity;
// config items
const defaultPollInterval = 1000;
const defaultDirectLineClientName = 'ViberBotConnector';
const defaultDirectLineSecret = 'xxxxxxxxxxxxxxxxxxxxx'; // ToDo: Replace with your Microsoft Bot Framework DirectLine secret
const builder = require('botbuilder');
const ViberBot = require('viber-bot').Bot;
const BotEvents = require('viber-bot').Events;
const UserProfile = require('viber-bot').UserProfile;
const VTextMessage = require('viber-bot').Message.Text
const VPictureMessage = require('viber-bot').Message.Picture
const VLocationMessage = require('viber-bot').Message.Location
const VContactMessage = require('viber-bot').Message.Contact
const VStickerMessage = require('viber-bot').Message.Sticker
const winston = require('winston');
const toYAML = require('winston-console-formatter'); // makes the output more friendly
const async = require("async");
/*
Until BotBuilder supports custom channels,
we have to use Kik's channelId to make BotBuilder play nice with user data.
We can use any other channel which supports buttons instead of Kik here.
*/
const ViberChannelId = 'kik'
const logger = function() {
const logger = new winston.Logger({ level: "debug" }); // We recommend DEBUG for development
logger.add(winston.transports.Console, toYAML.config());
return logger;
const builder = require('botbuilder');
const ViberBot = require('viber-bot').Bot;
const BotEvents = require('viber-bot').Events;
const UserProfile = require('viber-bot').UserProfile;
const VTextMessage = require('viber-bot').Message.Text
const VPictureMessage = require('viber-bot').Message.Picture
const VLocationMessage = require('viber-bot').Message.Location
const VContactMessage = require('viber-bot').Message.Contact
const VStickerMessage = require('viber-bot').Message.Sticker
const winston = require('winston');
const toYAML = require('winston-console-formatter'); // makes the output more friendly
const async = require("async");
/*
Until BotBuilder supports custom channels,
we have to use Kik's channelId to make BotBuilder play nice with user data.
We can use any other channel which supports buttons instead of Kik here.
*/
const ViberChannelId = 'kik'
const logger = function() {
const logger = new winston.Logger({ level: "debug" }); // We recommend DEBUG for development
logger.add(winston.transports.Console, toYAML.config());
function ViberEnabledConnector(opts) {
var self = this;
this.options = opts || {};
this.viberBot = new ViberBot({
authToken: this.options.Token,
name: this.options.Name,
// It is recommended to be 720x720, and no more than 100kb.
avatar: this.options.AvatarUrl,
logger: logger
});
this.viberBot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
self.processMessage(message, response);
});
this.viberBot.on(BotEvents.CONVERSATION_STARTED, (response, onFinish) => {
// onFinish(new TextMessage(`Hi, ${userProfile.name}! Nice to meet you.`))
var self = this;
var userProfile = response.userProfile;
var addr = {
const WebServerUrl = 'https://YOUR_BOT_SITE_URL'; // ToDo: This is the URL where the Viber bot is hosted. Has to be an external URL
const WebServerPort = 8080; // ToDo: This is the port of the Viber bot.
function createLogger() {
const logger = new winston.Logger({
level: "debug" // We recommend using the debug level for development
});
logger.add(winston.transports.Console, toYAML.config());
return logger;
}
const logger = createLogger();
// Creating the bot with access token, name and avatar
const bot = new ViberBot(logger, {
authToken: process.env.VIBER_PUBLIC_ACCOUNT_ACCESS_TOKEN_KEY || ViberPublicAccountAccessTokenKey,
name: ViberBotName,
avatar: ViberBotImageUrl
});
// create the MBF bot instance
const mbfBot = new MbfBotConnector(logger, new MbfPlatformViber(), {
clientName: MicrosoftBotDirectLineClientName,
secret: process.env.MICROSOFT_BOT_DIRECT_LINE_SECRET || MicrosoftBotDirectLineSecret,
pollInterval: process.env.MICROSOFT_BOT_POLL_INTERVAL || 1000});
mbfBot.on(MbfEvents.MBF_MESSAGE_RECEIVED, function(recipient, message) {
// send a MBF bot message back to Viber
bot.sendMessage(recipient, message);
});
function ViberEnabledConnector(opts) {
var self = this;
this.options = opts || {};
this.viberBot = new ViberBot({
authToken: this.options.Token,
name: this.options.Name,
// It is recommended to be 720x720, and no more than 100kb.
avatar: this.options.AvatarUrl,
logger: logger
});
this.viberBot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
self.processMessage(message, response);
});
this.viberBot.on(BotEvents.CONVERSATION_STARTED, (response, onFinish) => {
// onFinish(new TextMessage(`Hi, ${userProfile.name}! Nice to meet you.`))
var self = this;
var userProfile = response.userProfile;
var addr = {
channelId: ViberChannelId,
user: { id: encodeURIComponent(userProfile.id), name: userProfile.name },
bot: { id: 'viberbot', name: self.options.Name },
conversation: { id: 'ViberConversationId' }
};
var msg = new builder.Message()
.address(addr)
mbfBot.on(MbfEvents.MBF_MESSAGE_RECEIVED, function(recipient, message) {
// send a MBF bot message back to Viber
bot.sendMessage(recipient, message);
});
bot.onSubscribe(response => {
// create a connection to the MBF bot
mbfBot.createNewConversation(response.userProfile);
});
bot.onUnsubscribe(response => {
mbfBot.closeConversation(response);
})
bot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
// send an user message to the MBF bot
mbfBot.sendMessage(response.userProfile, message);
});
var webHookUrl = process.env.WEBSERVER_URL || WebServerUrl;
if (webHookUrl) {
const http = require('http');
const port = process.env.WEBSERVER_PORT || WebServerPort;
http.createServer(bot.middleware()).listen(port, () => bot.setWebhook(webHookUrl));
} else {
logger.debug('Could not find the now.sh/Heroku environment variables. Please make sure you followed readme guide.');
}