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 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'
listen() {
if (!this.session) {
return Rx_1.Observable.throw(new Error('No session found.'));
}
return Rx_1.Observable.fromEvent(this.session, viber_bot_1.Events.MESSAGE_RECEIVED, (...args) => ({ message: args[0], user_profile: args[1].userProfile }))
.mergeMap((event) => this.parser.normalize(event))
.mergeMap((normalized) => {
if (!normalized) {
return Promise.resolve(null);
}
const id = R.path(['author', 'id'], normalized);
if (id) {
this.storeUsers.set(id, normalized.author);
}
if (this.me) {
normalized.target = this.me;
return Promise.resolve(normalized);
}
return this.session.getBotProfile()
.then((profile) => {
this.me = R.assoc('_isMe', true, profile);
listen() {
if (!this.session) {
return Rx_1.Observable.throw(new Error("No session found."));
}
return Rx_1.Observable.fromEvent(this.session, viber_bot_1.Events.MESSAGE_RECEIVED, (...args) => ({ message: args[0], user_profile: args[1].userProfile }))
.mergeMap((event) => this.parser.normalize(event))
.mergeMap((normalized) => {
if (!normalized) {
return Promise.resolve(null);
}
const id = R.path(["author", "id"], normalized);
if (id) {
this.storeUsers.set(id, normalized.author);
}
if (this.me) {
normalized.target = this.me;
return Promise.resolve(normalized);
}
return this.session.getBotProfile()
.then((profile) => {
this.me = R.assoc("_isMe", true, profile);