Comparing version 2.2.4 to 2.2.5
@@ -89,2 +89,3 @@ 'use strict'; | ||
* message_id: <message_id_of_what_was_just_sent> | ||
* sent_message: <sent_message_object> | ||
* } | ||
@@ -104,9 +105,12 @@ * | ||
.then(this.__sendMessage.bind(this)) | ||
.then((middlewaredMessage) => { | ||
return this.__sendMessage(middlewaredMessage) | ||
.then((body) => { | ||
if (cb) { | ||
return cb(null, body); | ||
} | ||
return body; | ||
.then((body) => { | ||
body.sent_message = middlewaredMessage; | ||
if (cb) { | ||
return cb(null, body); | ||
} | ||
return body; | ||
}); | ||
}) | ||
@@ -246,6 +250,6 @@ | ||
message.text = textOrAttachment; | ||
} else if (textOrAttachment.constructor === Object) { | ||
} else if (textOrAttachment.constructor === Object && textOrAttachment.type) { | ||
message.attachment = textOrAttachment; | ||
} else { | ||
const error = new Error('ERROR: third argument must be a "String", "Object" or absent'); | ||
const error = new Error('ERROR: third argument must be a "String", an attachment "Object" or absent'); | ||
if (cb) { | ||
@@ -252,0 +256,0 @@ return cb(error); |
@@ -12,2 +12,3 @@ 'use strict'; | ||
const cloneDeep = require('lodash').cloneDeep; | ||
const debug = require('debug')('botmaster:botmaster'); | ||
@@ -58,3 +59,5 @@ class Botmaster extends EventEmitter { | ||
const server = this.app.listen(port, '0.0.0.0', () => { // running it for the public | ||
this.emit('server running', `App parameter not specified. Running new App on port: ${port}`); | ||
const serverMsg = `App parameter not specified. Running new App on port: ${port}`; | ||
debug(serverMsg); | ||
this.emit('server running', serverMsg); | ||
}); | ||
@@ -192,4 +195,5 @@ | ||
} | ||
if (!middlewareCallback) { | ||
throw new Error('ERROR: invalid middleware type. Type should be either \'incoming\' or \'outgoing\''); | ||
if (!middlewareCallback && (typeof middlewareType === 'string' || middlewareType instanceof String)) { | ||
throw new Error('ERROR: middlewareCallback needs to be defined'); | ||
} else if (arguments[3] !== undefined) { | ||
@@ -196,0 +200,0 @@ throw new Error('ERROR: too many arguments. 2-3 expected'); |
{ | ||
"name": "botmaster", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"s": "nodemon --legacy-watch ./example_jd.js", | ||
"s": "DEBUG=botmaster:botmaster nodemon --legacy-watch ./example_jd.js", | ||
"start": "node ./example_jd.js", | ||
@@ -40,2 +40,3 @@ "test": "istanbul cover _mocha -- --recursive tests", | ||
"crypto": "0.0.3", | ||
"debug": "^2.6.0", | ||
"express": ">=4x .4.x <5.0.0 || >=5.0.0-alpha.2 < 7.0.0", | ||
@@ -42,0 +43,0 @@ "jfs": "^0.2.6", |
@@ -13,3 +13,3 @@ # Botmaster | ||
Find the whole documentation for the framework on: https://botmasterai.github.io | ||
Find the whole documentation for the framework on: http://botmasterai.com/ | ||
@@ -16,0 +16,0 @@ |
@@ -482,3 +482,3 @@ 'use strict'; | ||
.catch((err) => { | ||
err.message.should.equal('ERROR: third argument must be a "String", "Object" or absent'); | ||
err.message.should.equal('ERROR: third argument must be a "String", an attachment "Object" or absent'); | ||
done(); | ||
@@ -492,3 +492,3 @@ }); | ||
bot.sendDefaultButtonMessageTo(buttons, recipientId, bot, function(err) { | ||
err.message.should.equal('ERROR: third argument must be a "String", "Object" or absent'); | ||
err.message.should.equal('ERROR: third argument must be a "String", an attachment "Object" or absent'); | ||
done(); | ||
@@ -495,0 +495,0 @@ }); |
@@ -83,2 +83,8 @@ 'use strict'; | ||
it('should throw an error if the first argument is a string but there is no callback defined', function() { | ||
expect(function() { | ||
botmaster.use('incoming'); | ||
}).to.throw('ERROR: middlewareCallback needs to be defined'); | ||
}); | ||
it('should throw an error if the second argument exists and it isn\'t an object', function() { | ||
@@ -241,7 +247,2 @@ expect(() => botmaster.use('incoming', 'some string', function(bot, update, next) { | ||
botmaster.once('update', function(bot, update){ | ||
expect(update.session).to.equal('disASession'); | ||
done(); | ||
}); | ||
const bot = botmaster.getBots('messenger')[0]; | ||
@@ -253,3 +254,3 @@ | ||
.then(function(body) { | ||
expect(body).to.not.equal(undefined); | ||
expect(body.sent_message).to.not.equal(undefined); | ||
done(); | ||
@@ -369,3 +370,3 @@ }); | ||
specify('Outgoing middleware should be ignored if configured so using sendTextCascadeTo', function(done) { | ||
this.timeout(4000); | ||
this.timeout(8000); | ||
// outgoing middleware should never be hit | ||
@@ -380,4 +381,4 @@ botmaster.use('outgoing', function(bot, message, next) { | ||
bot.sendTextCascadeTo( | ||
['message1', 'message2'], config.messengerUserId, | ||
{ ignoreMiddleware: true }) | ||
['message1', 'message2'], config.messengerUserId, | ||
{ ignoreMiddleware: true }) | ||
@@ -384,0 +385,0 @@ .then(function() { |
172017
4666
10
+ Addeddebug@^2.6.0