From 7fa53532e18fa6f0777a061664239469ad6303d8 Mon Sep 17 00:00:00 2001 From: Sylvain Perron Date: Fri, 15 Mar 2019 08:42:13 -0400 Subject: [PATCH] fix(messenger): typings of config --- build/module-builder/src/build.ts | 6 ++- modules/channel-messenger/package.json | 2 +- modules/channel-messenger/src/config.ts | 65 ++++++++++++------------- modules/channel-messenger/yarn.lock | 2 +- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/build/module-builder/src/build.ts b/build/module-builder/src/build.ts index 5ecfd4acc17..14aa3234724 100644 --- a/build/module-builder/src/build.ts +++ b/build/module-builder/src/build.ts @@ -113,11 +113,15 @@ export async function buildConfigSchema(modulePath: string) { const settings = { required: true, - ignoreErrors: true + ignoreErrors: true, + noExtraProps: true, + validationKeywords: ['see', 'example', 'pattern'] } const program = getProgramFromFiles([config]) const definition = generateSchema(program, 'Config', settings) + definition.properties.$schema = { type: 'string' } + const schema = JSON.stringify(definition, undefined, 2) + os.EOL + os.EOL mkdirp.sync(path.resolve(modulePath, 'assets')) diff --git a/modules/channel-messenger/package.json b/modules/channel-messenger/package.json index d473523ab22..7b351f7a80d 100755 --- a/modules/channel-messenger/package.json +++ b/modules/channel-messenger/package.json @@ -7,7 +7,7 @@ "license": "AGPL-3.0-only", "main": "dist/backend/index.js", "devDependencies": { - "module-builder": "file:../../build/module-builder" + "module-builder": "../../build/module-builder" }, "scripts": { "build": "./node_modules/.bin/module-builder build", diff --git a/modules/channel-messenger/src/config.ts b/modules/channel-messenger/src/config.ts index 675daf1a4e9..8df78b91479 100644 --- a/modules/channel-messenger/src/config.ts +++ b/modules/channel-messenger/src/config.ts @@ -1,3 +1,4 @@ +/** #TopLevel */ export interface Config { /** * This this in the LOCAL config (unique to every bot/page) @@ -19,50 +20,48 @@ export interface Config { /** * Set this in the GLOBAL config (same for all the bots) * The verify token, should be a random string unique to your server. This is a random (hard to guess) string of your choosing. - * @see https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup/#verify_webhook + * Docs: https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup/#verify_webhook */ verifyToken: string /** * The greeting message people will see on the welcome screen - * @see https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/greeting + * Docs: https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/greeting */ greeting?: string /** * The message of the welcome screen "Get Started" button - * @see https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/get-started-button + * Docs: https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/get-started-button */ getStarted?: string /** * The raw persistent menu object - * @see https://developers.facebook.com/docs/messenger-platform/send-messages/persistent-menu/ - * @example - * { - * "persistent_menu":[ - * { - * "locale":"default", - * "composer_input_disabled": true, - * "call_to_actions":[ - * { - * "title":"My Account", - * "type":"nested", - * "call_to_actions":[ - * { - * "title":"Pay Bill", - * "type":"postback", - * "payload":"PAYBILL_PAYLOAD" - * }, - * { - * "type":"web_url", - * "title":"Latest News", - * "url":"https://www.messenger.com/", - * "webview_height_ratio":"full" - * } - * ] - * } - * ] - * } - * ] - * } + * Docs: https://developers.facebook.com/docs/messenger-platform/send-messages/persistent-menu */ - persistentMenu?: any // TODO Type me + persistentMenu?: PersistentMenuItem[] +} + +export interface PersistentMenuItem { + locale: string + composer_input_disabled?: boolean + call_to_actions?: CallToAction[] +} + +export type CallToAction = WebUrlButton | PostbackButton | NestedButton + +export interface WebUrlButton { + type: 'web_url' + url: string + title: string +} + +export interface PostbackButton { + type: 'postback' + title: string + payload: string +} + +export interface NestedButton { + type: 'nested' + title: string + call_to_actions: CallToAction[] } diff --git a/modules/channel-messenger/yarn.lock b/modules/channel-messenger/yarn.lock index 2454b9f1dad..34a31b80834 100644 --- a/modules/channel-messenger/yarn.lock +++ b/modules/channel-messenger/yarn.lock @@ -3289,7 +3289,7 @@ mixin-object@^2.0.1: dependencies: minimist "0.0.8" -"module-builder@file:../../build/module-builder": +module-builder@../../build/module-builder: version "1.0.0" dependencies: "@babel/cli" "^7.1.0"