Comparing version 0.25.0 to 0.25.1
{ | ||
"name": "botnaut", | ||
"version": "0.25.0", | ||
"version": "0.25.1", | ||
"description": "Facebook Messenger Chatbot Framework", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,3 +7,3 @@ /* | ||
const { marshalItem } = require('dynamodb-marshaler'); | ||
const uuidV1 = require('uuid/v1'); | ||
const uuidV1 = require('uuid').v1; | ||
@@ -10,0 +10,0 @@ |
@@ -8,5 +8,7 @@ /* | ||
constructor (onDone) { | ||
constructor (onDone, isTopLevel = true) { | ||
this.onDone = onDone; | ||
this.callToActions = []; | ||
this.menus = []; | ||
this.callToActions = null; | ||
this.isTopLevel = isTopLevel; | ||
} | ||
@@ -61,10 +63,11 @@ | ||
addNested (title) { | ||
return new MenuComposer((actions) => { | ||
const nested = new MenuComposer(([{ call_to_actions }]) => { | ||
this.callToActions.push({ | ||
type: 'nested', | ||
title, | ||
call_to_actions: actions | ||
call_to_actions | ||
}); | ||
return this; | ||
}); | ||
}, false); | ||
return nested.menu(); | ||
} | ||
@@ -78,7 +81,29 @@ | ||
done () { | ||
return this.onDone(this.callToActions); | ||
return this.onDone(this.menus); | ||
} | ||
/** | ||
* Finish the menu for the locale and starts a new menu | ||
* | ||
* @param {string} [locale] | ||
* @param {boolean} [inputDisabled] | ||
* @returns {MenuComposer} | ||
*/ | ||
menu (locale = 'default', inputDisabled = false) { | ||
if (!this.isTopLevel && this.menus.length !== 0) { | ||
throw new Error('Call the .done() on nested menu before new menu creation'); | ||
} | ||
this.callToActions = []; | ||
this.menus.push({ | ||
locale, | ||
composer_input_disabled: inputDisabled, | ||
call_to_actions: this.callToActions | ||
}); | ||
return this; | ||
} | ||
} | ||
module.exports = MenuComposer; |
@@ -141,4 +141,4 @@ /* | ||
* | ||
* @param {string} [locale] | ||
* @param {boolean} [inputDisabled] | ||
* @param {string} [locale=default] | ||
* @param {boolean} [inputDisabled=false] | ||
* @returns {MenuComposer} | ||
@@ -151,41 +151,44 @@ * @example | ||
* | ||
* settings.menu() | ||
* .addNested('Nested Menu') | ||
* .addUrl('Go to google', 'https://google.com') | ||
* .done() | ||
* .addPostBack('Do something', '/the/action') | ||
* .done(); | ||
* settings | ||
* .menu('fr_FR') | ||
* .addNested('Nested Menu') | ||
* .addUrl('Aller à google', 'https://google.com') | ||
* .done() | ||
* .addPostBack('Faire quelque chose', '/the/action') | ||
* .menu() // the default menu | ||
* .addNested('Nested Menu') | ||
* .addUrl('Go to google', 'https://google.com') | ||
* .done() | ||
* .addPostBack('Do something', '/the/action') | ||
* .done(); | ||
*/ | ||
menu (locale = 'default', inputDisabled = false) { | ||
return new MenuComposer((actions) => { | ||
this._get(['persistent_menu']) | ||
.then((result) => { | ||
const newMenu = [{ | ||
locale, | ||
composer_input_disabled: inputDisabled, | ||
call_to_actions: actions | ||
}]; | ||
const composer = new MenuComposer((newMenu) => { | ||
this._get(['persistent_menu']).then((result) => { | ||
let updateMenu; | ||
let updateMenu; | ||
if (result.data.length === 0) { | ||
updateMenu = true; | ||
} else { | ||
const existingMenu = result.data[0].persistent_menu; | ||
updateMenu = !deepEqual(newMenu, existingMenu); | ||
} | ||
if (result.data.length === 0) { | ||
updateMenu = true; | ||
} else { | ||
const existingMenu = result.data[0].persistent_menu; | ||
updateMenu = !deepEqual(newMenu, existingMenu); | ||
} | ||
if (!updateMenu) { | ||
return Promise.resolve(); | ||
} | ||
if (!updateMenu) { | ||
return Promise.resolve(); | ||
} | ||
return this._post({ | ||
persistent_menu: newMenu | ||
}); | ||
}).catch(e => this.log.error('Bot settings failed', e)); | ||
return this._post({ | ||
persistent_menu: newMenu | ||
}); | ||
}).catch(e => this.log.error('Bot settings failed', e)); | ||
return this; | ||
}); | ||
return composer.menu(locale, inputDisabled); | ||
} | ||
} | ||
module.exports = Settings; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
130
2878618
7078
7