Skip to content

Commit

Permalink
Merge pull request #16 from boybundit/reply-validation
Browse files Browse the repository at this point in the history
Validate missing param in reply method
  • Loading branch information
boybundit committed Nov 5, 2016
2 parents f7deb0e + 8c40f8e commit 175b04b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ bot.on('message', function (event) {
case 'Multiple':
return event.reply(['Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5']);
break;
case 'Version':
event.reply('linebot@' + process.env.npm_package_version);
break;
default:
event.reply(event.message.text).then(function (data) {
console.log('Success', data);
Expand Down
3 changes: 2 additions & 1 deletion lib/linebot.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class LineBot extends EventEmitter {
static createMessages(message) {
if (typeof message === 'string') {
return [{ type: 'text', text: message }];
} else if (message.constructor === Array) {
}
if (Array.isArray(message)) {
return message.map(function (m) {
if (typeof m === 'string') {
return { type: 'text', text: m };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linebot",
"version": "1.2.0",
"version": "1.2.1",
"description": "Node.js SDK for the LINE Messaging API",
"main": "index.js",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions test/linebot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ describe('linebot', function () {
const res = bot.reply('reply token', 'message');
assert.equal(Promise, res.constructor);
});
it('should not crash if message is missing.', function () {
const res = bot.reply('reply token');
assert.equal(Promise, res.constructor);
});
});
describe('#push()', function () {
it('should return a promise.', function () {
Expand Down

0 comments on commit 175b04b

Please sign in to comment.