Comparing version
@@ -9,2 +9,10 @@ 'use strict'; | ||
/** | ||
* The class from which all Bot classes mus inherit. It contains all the base | ||
* methods that are accessible via all bot classes. Classes that inherit from | ||
* BaseBot and want to make implementation specific methods available have to | ||
* prepend the method name with an underscore; e.g. in botmaster-messenger: | ||
* _getGetStartedButton | ||
*/ | ||
class BaseBot extends EventEmitter { | ||
@@ -18,2 +26,8 @@ /** | ||
* object as first param. | ||
* @example | ||
* // In general however, one can instantiate a bot object like this: | ||
* const bot = new BaseBotSubClass({ // e.g. MessengerBot | ||
* credentials: <my_base_bot_sub_class_credentials>, | ||
* webhookEnpoint: 'someEndpoint' // only if class requires them | ||
* }) | ||
*/ | ||
@@ -173,7 +187,8 @@ constructor() { | ||
* @param {boolean} [sendOptions] options used for sending the message. e.g. ignoreMiddleware | ||
* @param {function} [cb] optional callback function | ||
* | ||
* @return {Promise} | ||
* The returned promise for all sendMessage type events returns a body that | ||
* looks something like this: | ||
* | ||
* @example | ||
* // The returned promise for all sendMessage type events resolves with | ||
* // a body that looks something like this: | ||
* { | ||
@@ -186,5 +201,5 @@ * raw: rawBody, // can be undefined (e.g. if rawBody is directly returned) | ||
* | ||
* Some platforms may not have either of these parameters. If that's the case, | ||
* the value assigned will be null or some other suitable value as the | ||
* equivalent to Messenger's seq in Telegram. | ||
* // Some platforms may not have either of these parameters. If that's the case, | ||
* // the value assigned will be null or some other suitable value as the | ||
* // equivalent to Messenger's seq in Telegram. | ||
* | ||
@@ -285,9 +300,15 @@ */ | ||
* sendMessageTo() Just makes it easier to send a message without as much | ||
* structure. message object can look something like this: | ||
* structure. | ||
* @param {object} message NOT an instance of OutgoingMessage. Use | ||
* #sendMessage if you want to send instances of OutgoingMessage | ||
* @param {string} recipientId | ||
* @param {object} [sendOptions] just options for sending. | ||
* | ||
* @example | ||
* | ||
* // message object can look something like this: | ||
* | ||
* message: { | ||
* text: 'Some random text' | ||
* } | ||
* @param {object} message | ||
* @param {string} recipientId | ||
* @param {object} [sendOptions] just options for sending. | ||
* | ||
@@ -341,4 +362,7 @@ * @return {Promise} promise | ||
* sendAttachmentTo() makes it easier to send an attachment message with | ||
* less structure. attachment typically looks something like this: | ||
* ```js | ||
* less structure. | ||
* @param {object} attachment | ||
* @example | ||
* // attachment object typically looks something like this: | ||
* | ||
* const attachment = { | ||
@@ -350,4 +374,3 @@ * type: 'image', | ||
* }; | ||
* ``` | ||
* @param {object} attachment | ||
* | ||
* @param {string} recipientId | ||
@@ -480,2 +503,5 @@ * @param {object} [sendOptions] just options for sending. | ||
* | ||
* | ||
* i.e. it has no message_id (or it is null/undefined) | ||
* | ||
* @param {string} recipientId | ||
@@ -485,12 +511,13 @@ * @param {object} [sendOptions] | ||
* @return {Promise} promise | ||
* The returned value is different from the standard one. It looks something | ||
* like this in this case: | ||
* | ||
* ```js | ||
* @example | ||
* | ||
* // the returned value is different from the standard one. It looks something | ||
* //like this in this case: | ||
* | ||
* { | ||
* recipient_id: <id_of_user> | ||
* } | ||
* ``` | ||
* i.e. it has no message_id (or it is null/undefined) | ||
* | ||
* | ||
*/ | ||
@@ -497,0 +524,0 @@ sendIsTypingMessageTo(recipientId, sendOptions) { |
@@ -11,2 +11,6 @@ 'use strict'; | ||
/** | ||
* The Botmaster class to rule them all | ||
*/ | ||
class Botmaster extends EventEmitter { | ||
@@ -51,3 +55,3 @@ /** | ||
throw new Error( | ||
'If passing through settings, please specify exactly one of port ' + | ||
'If passing through settings, please specify exactly one of port or server' + | ||
'If you want botmaster to use its defaults, just use the constructor with no params'); | ||
@@ -197,4 +201,5 @@ } | ||
* | ||
* The middleware object is something that looks like this for incoming: | ||
* ```js | ||
* @example | ||
* | ||
* // The middleware param object is something that looks like this for incoming: | ||
* { | ||
@@ -207,7 +212,5 @@ * type: 'incoming', | ||
* } | ||
* ``` | ||
* | ||
* and like this for outgoing middleware | ||
* // and like this for outgoing middleware | ||
* | ||
* ```js | ||
* { | ||
@@ -220,5 +223,5 @@ * type: 'outgoing', | ||
* } | ||
* ``` | ||
* | ||
* @return {Botmaster} returns the botmaster object so you can chain middleware | ||
* | ||
*/ | ||
@@ -225,0 +228,0 @@ use(middleware) { |
@@ -23,2 +23,3 @@ 'use strict'; | ||
* See botmaster #use for more info. | ||
* @ignore | ||
*/ | ||
@@ -30,6 +31,6 @@ __use(middleware) { | ||
this.incomingMiddlewareStack.push(middleware); | ||
debug('added incoming middleware'); | ||
debug(`added ${middleware.name || 'nameless'} incoming middleware`); | ||
} else { | ||
this.outgoingMiddlewareStack.push(middleware); | ||
debug('added outgoing middleware'); | ||
debug(`added ${middleware.name || 'nameless'} outgoing middleware`); | ||
} | ||
@@ -43,3 +44,3 @@ | ||
* See botmaster #useWrapped for more info. | ||
* | ||
* @ignore | ||
* @param {object} params | ||
@@ -65,3 +66,4 @@ */ | ||
this.outgoingMiddlewareStack.push(outgoingMiddleware); | ||
debug('added wrapped middleware'); | ||
debug(`added wrapped ${incomingMiddleware.name || 'nameless'} incoming middleware`); | ||
debug(`added wrapped ${outgoingMiddleware.name || 'nameless'} outgoing middleware`); | ||
@@ -186,3 +188,4 @@ return this; | ||
* | ||
* options is an object that can contain any of: | ||
* @example | ||
* // options is an object that can contain any of: | ||
* { | ||
@@ -189,0 +192,0 @@ * includeEcho, // opt-in to get echo updates |
@@ -8,2 +8,6 @@ 'use strict'; | ||
/** | ||
* This class will help you compose sendable message objects. | ||
*/ | ||
class OutgoingMessage { | ||
@@ -14,4 +18,9 @@ | ||
* message object that it will use as its base to add the OutgoingMessage | ||
* methods to. | ||
* methods to. This constructor is not actually exposed in the public API. | ||
* In order to instantiate an OutgoingMessage object, you'll need to use the | ||
* createOutgoingMessage and createOutgoingMessageFor methods provided with | ||
* all classes that inherit from BaseBot. There are static and non-static | ||
* versions of both methods to make sure you can do so wherever as you wish | ||
* | ||
* @private | ||
* @param {object} [message] the base object to convert into an OutgoingMessage object | ||
@@ -18,0 +27,0 @@ */ |
{ | ||
"name": "botmaster", | ||
"version": "3.0.7", | ||
"version": "3.0.8", | ||
"description": "Framework allowing developers to write bots that are agnostic with respect to the channel used by their users (messenger, telegram etc...)", | ||
@@ -11,8 +11,9 @@ "main": "./lib/index.js", | ||
"postversion": "git push && git push --tags && rm -rf build/temp", | ||
"jsdoc": "jsdoc -r -d jsdoc ./lib", | ||
"report": "nyc report" | ||
"report": "nyc report", | ||
"botmaster-docs": "documentation build lib/botmaster.js -f md > api-reference/botmaster.md", | ||
"base-bot-docs": "documentation build lib/base_bot.js -f md > api-reference/base-bot.md", | ||
"outgoing-message-docs": "documentation build lib/outgoing_message.js -f md > api-reference/outgoing-message.md", | ||
"docs": "mkdir -p api-reference; yarn botmaster-docs; yarn base-bot-docs; yarn outgoing-message-docs", | ||
"docs-deploy": "yarn docs && cp -r api-reference ../botmasterai.github.io/docs" | ||
}, | ||
"directories": { | ||
"tests": "test" | ||
}, | ||
"ava": { | ||
@@ -71,2 +72,3 @@ "files": [ | ||
"coveralls": "^2.11.16", | ||
"documentation": "^4.0.0-beta.18", | ||
"eslint": "^3.17.0", | ||
@@ -79,3 +81,2 @@ "eslint-config-airbnb": "^14.1.0", | ||
"express": "^4.15.2", | ||
"jsdoc": "^3.4.2", | ||
"koa": "^2.0.1", | ||
@@ -82,0 +83,0 @@ "nyc": "^10.1.2", |
module.exports = { | ||
extends: 'airbnb', | ||
plugins: [ | ||
'ava' | ||
'ava', | ||
], | ||
rules: { | ||
'import/no-extraneous-dependencies': ['off'], | ||
'no-underscore-dangle': ["off"], | ||
'import/no-extraneous-dependencies': 'off', | ||
'no-underscore-dangle': 'off', | ||
semi: [2, 'always'], | ||
'no-param-reassign': 'off', | ||
'no-restricted-syntax': 'off', | ||
} | ||
'strict': 'off', | ||
}, | ||
}; |
@@ -109,3 +109,3 @@ import test from 'ava'; | ||
test('should throw and error when settings is an object and neither port nor settings is passed', (t) => { | ||
test('should throw and error when settings is an object and neither port nor server is passed', (t) => { | ||
t.plan(1); | ||
@@ -112,0 +112,0 @@ |
Sorry, the diff of this file is not supported yet
363630
32.03%38
8.57%3846
1.05%