Skip to content

Commit

Permalink
fix(messenger): typings of config
Browse files Browse the repository at this point in the history
  • Loading branch information
slvnperron committed Mar 15, 2019
1 parent 3ab6b11 commit 7fa5353
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
6 changes: 5 additions & 1 deletion build/module-builder/src/build.ts
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion modules/channel-messenger/package.json
Expand Up @@ -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",
Expand Down
65 changes: 32 additions & 33 deletions 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)
Expand All @@ -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[]
}
2 changes: 1 addition & 1 deletion modules/channel-messenger/yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit 7fa5353

Please sign in to comment.