Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.');
}
public listen(): Observable {
if (!this.session) {
return Observable.throw(new Error('No session found.'));
}
return Observable.fromEvent(
this.session,
Events.MESSAGE_RECEIVED,
(...args) => ({ message: args[0], user_profile: args[1].userProfile }))
.mergeMap((event: any) => this.parser.normalize(event))
.mergeMap((normalized: any) => {
if (!normalized) { return Promise.resolve(null); }
const id: any = R.path(['author', 'id'], normalized);
if (id) {
this.storeUsers.set(id as string, normalized.author);
}
if (this.me) {
normalized.target = this.me;
return Promise.resolve(normalized);
}
return this.session.getBotProfile()
.then((profile: any) => {
public listen(): Observable {
if (!this.session) {
return Observable.throw(new Error("No session found."));
}
return Observable.fromEvent(this.session, Events.MESSAGE_RECEIVED,
(...args) => ({ message: args[0], user_profile: args[1].userProfile }))
.mergeMap((event: any) => this.parser.normalize(event))
.mergeMap((normalized: any) => {
if (!normalized) { return Promise.resolve(null); }
const id: any = R.path(["author", "id"], normalized);
if (id) {
this.storeUsers.set(id as string, normalized.author);
}
if (this.me) {
normalized.target = this.me;
return Promise.resolve(normalized);
}
return this.session.getBotProfile()
.then((profile: any) => {
public listen(): Observable {
if (!this.session) {
return Observable.throw(new Error("No session found."));
}
return Observable.fromEvent(this.session, Events.MESSAGE_RECEIVED,
(...args) => ({ message: args[0], user_profile: args[1].userProfile }))
.mergeMap((event: any) => this.parser.normalize(event))
.mergeMap((normalized: any) => {
if (!normalized) { return Promise.resolve(null); }
const id: any = R.path(["author", "id"], normalized);
if (id) {
this.storeUsers.set(id as string, normalized.author);
}
if (this.me) {
normalized.target = this.me;
return Promise.resolve(normalized);
}
return this.session.getBotProfile()
.then((profile: any) => {