Comparing version 0.1.1 to 0.1.3
@@ -111,3 +111,8 @@ 'use strict'; | ||
sendMessage(message) { | ||
sendMessage(message, session) { | ||
if (session) { | ||
message.recipient = { | ||
id: session.id, | ||
}; | ||
} | ||
const options = { | ||
@@ -114,0 +119,0 @@ uri: baseMessageURL, |
@@ -181,3 +181,8 @@ 'use strict'; | ||
sendMessage(message) { | ||
sendMessage(message, session) { | ||
if (session) { | ||
message.recipient = { | ||
id: session.id, | ||
}; | ||
} | ||
const messageData = {}; | ||
@@ -184,0 +189,0 @@ |
@@ -27,2 +27,3 @@ 'use strict'; | ||
this.app = app; | ||
this.sessionStore = sessionStore; | ||
this.bots = []; | ||
@@ -39,11 +40,19 @@ | ||
for (const settings of this.botsSettings) { | ||
// first add the sessionStore to the settings | ||
if (this.sessionStore) { | ||
settings.sessionStore = this.sessionStore; | ||
} | ||
let botType = null; | ||
let botClass = null; | ||
if (settings.telegram !== undefined) { | ||
this.createBot('telegram', TelegramBot, settings.telegram); | ||
botType = 'telegram'; | ||
botClass = TelegramBot; | ||
} else if (settings.messenger !== undefined) { | ||
this.createBot('messenger', MessengerBot, settings.messenger); | ||
botType = 'messenger'; | ||
botClass = MessengerBot; | ||
settings.messenger.sessionStore = this.sessionStore; | ||
} | ||
if (!settings[botType].sessionStore) { | ||
// this will set the store to undefined or the specified sessionStore | ||
settings.telegram.sessionStore = this.sessionStore; | ||
} | ||
this.createBot(botType, botClass, settings[botType]); | ||
} | ||
@@ -50,0 +59,0 @@ } |
{ | ||
"name": "botmaster", | ||
"version": "0.1.1", | ||
"version": "0.1.3", | ||
"description": "Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -182,7 +182,6 @@ 'use strict' | ||
}, | ||
webhookEndpoint: '/webhook', | ||
sessionStore: new SessionStore() | ||
webhookEndpoint: '/webhook' | ||
}; | ||
const botsSettings = [{ messenger: messengerSettings }]; | ||
botmaster = new Botmaster(botsSettings, app); | ||
botmaster = new Botmaster(botsSettings, app, new SessionStore()); | ||
}) | ||
@@ -228,6 +227,3 @@ | ||
request(options) | ||
.then(function(body) { | ||
console.log(body); | ||
}) | ||
request(options); | ||
}); | ||
@@ -237,24 +233,1 @@ | ||
}) | ||
// function verifyRequestSignature(req, res, buf) { | ||
// const signature = req.headers['x-hub-signature']; | ||
// console.log("regfceds"); | ||
// if (!signature) { | ||
// // For testing, let's log an error. In production, you should throw an | ||
// // error. | ||
// console.error('Couldn\'t validate the signature.'); | ||
// } else { | ||
// const elements = signature.split('='); | ||
// const method = elements[0]; | ||
// const signatureHash = elements[1]; | ||
// const expectedHash = crypto.createHmac('sha1', FB_APP_SECRET) | ||
// .update(buf) | ||
// .digest('hex'); | ||
// if (signatureHash != expectedHash) { | ||
// throw new Error('Couldn\'t validate the request signature.'); | ||
// } | ||
// } | ||
// } |
36485
967