Comparing version 3.0.4 to 3.0.5
@@ -7,2 +7,3 @@ 'use strict'; | ||
const debug = require('debug')('botmaster:BaseBot'); | ||
const get = require('lodash').get; | ||
@@ -308,3 +309,3 @@ class BaseBot extends EventEmitter { | ||
sendTextMessageTo(text, recipientId, sendOptions, cb) { | ||
if (!this.sends.text) { | ||
if (!get(this, 'sends.text')) { | ||
return this.__throwCantSendError('text', sendOptions, cb); | ||
@@ -347,3 +348,3 @@ } | ||
sendAttachmentTo(attachment, recipientId, sendOptions, cb) { | ||
if (!this.sends.attachment) { | ||
if (!get(this, 'sends.attachment')) { | ||
return this.__throwCantSendError('attachment', sendOptions, cb); | ||
@@ -368,2 +369,9 @@ } | ||
sendAttachmentFromUrlTo(type, url, recipientId, sendOptions, cb) { | ||
if (!get(this, `sends.attachment.${type}`)) { | ||
let cantThrowErrorMessageType = `${type} attachment`; | ||
if (!get(this, 'sends.attachment')) { | ||
cantThrowErrorMessageType = 'attachment'; | ||
} | ||
return this.__throwCantSendError(cantThrowErrorMessageType, sendOptions, cb); | ||
} | ||
const attachment = { | ||
@@ -385,3 +393,4 @@ type, | ||
* @param {Array} buttonTitles | ||
* @param {string|object} textOrAttachment, if falsy, will be set to a default text of "Please select one of:" | ||
* @param {string|object} textOrAttachment, if falsy, will be set to a | ||
* default text of "Please select one of:" | ||
* @param {string} recipientId | ||
@@ -460,3 +469,3 @@ * @param {object} [sendOptions] | ||
sendIsTypingMessageTo(recipientId, sendOptions, cb) { | ||
if (!this.sends.senderAction || !this.sends.senderAction.typingOn) { | ||
if (!get(this, 'sends.senderAction.typingOn')) { | ||
return this.__throwCantSendError('typing_on sender action', sendOptions, cb); | ||
@@ -477,3 +486,4 @@ } | ||
* | ||
* @param {Array} messageArray of messages in a format as such: [{raw: someRawObject}, {message: some valid outgoingMessage}] | ||
* @param {Array} messageArray of messages in a format as such: | ||
* [{raw: someRawObject}, {message: some valid outgoingMessage}] | ||
* | ||
@@ -480,0 +490,0 @@ * @return {Promise} promise |
{ | ||
"name": "botmaster", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"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", |
@@ -145,2 +145,5 @@ import test from 'ava'; | ||
const cb = (err) => { | ||
if (!err) { | ||
t.false(true, 'Error should have been returned, but didn\'t get any'); | ||
} | ||
t.deepEqual(err.message, params.expectedErrorMessage, | ||
@@ -167,3 +170,5 @@ 'Error message is not same as expected'); | ||
// this occurs when sendMessageMethod can't even process | ||
// i.e. error shouldn't be dealt with. Code definitely has error and should be changed | ||
// i.e. error shouldn't be dealt with dynamically in code. try catch block | ||
// should be used to identify the error, then removed once the developer | ||
// understands how to use the method (in terms of sendOptions and cb). | ||
cb(err); | ||
@@ -359,2 +364,19 @@ // need to try again with cb in this case as it's not managed in first catch block | ||
{ | ||
const bot = new MockBot({ | ||
sends: { | ||
attachment: { | ||
audio: false, | ||
image: true, | ||
}, | ||
}, | ||
}); | ||
test('#sendAttachmentFromUrlTo throws error if bot class does not support attachment of specific type', sendMessageErrorMacro, { | ||
sendMessageMethod: bot.sendAttachmentFromUrlTo.bind( | ||
bot, 'audio', 'SOME_AUDIO_URL', 'user_id'), | ||
expectedErrorMessage: 'Bots of type mock can\'t send messages with audio attachment', | ||
}); | ||
} | ||
{ | ||
const bot = new MockBot(); | ||
@@ -361,0 +383,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
288681
4232