wingbot 3.67.31 → 3.68.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.67.31",
3
+ "version": "3.68.0-alpha.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -10,7 +10,7 @@
10
10
  "doc": "npm run doc:gql && node ./bin/makeApiDoc.js && cpy ./CHANGELOG.md ./doc && gitbook install ./doc && gitbook build ./doc && rimraf -rf ./docs && rimraf --rf ./doc/CHANGELOG.md && move-cli ./doc/_book ./docs",
11
11
  "test": "npm run test:lint && npm run test:coverage && npm run test:coverage:threshold",
12
12
  "test:coverage": "nyc --reporter=html mocha ./test && nyc report",
13
- "test:coverage:threshold": "nyc check-coverage --lines 89 --functions 89 --branches 80",
13
+ "test:coverage:threshold": "nyc check-coverage --lines 89 --functions 88 --branches 80",
14
14
  "test:backend": "mocha ./test",
15
15
  "test:lint": "eslint --ext .js src test *.js plugins"
16
16
  },
package/src/Responder.js CHANGED
@@ -38,11 +38,19 @@ const EXCEPTION_HOPCOUNT_THRESHOLD = 5;
38
38
  const ExpectedInput = {
39
39
  TYPE_PASSWORD: 'password',
40
40
  TYPE_NONE: 'none',
41
- TYPE_UPLOAD: 'upload'
41
+ TYPE_UPLOAD: 'upload',
42
+ TYPE_WEBVIEW: 'webview'
42
43
  };
43
44
 
44
45
  Object.freeze(ExpectedInput);
45
46
 
47
+ /**
48
+ * @typedef {object} ExpectedInputOptions
49
+ * @prop {string} [url]
50
+ * @prop {string} [webview_height_ratio]
51
+ * @prop {string} [on_close_payload]
52
+ */
53
+
46
54
  /**
47
55
  * @typedef {object} QuickReply
48
56
  * @prop {string} title
@@ -891,15 +899,16 @@ class Responder {
891
899
  /**
892
900
  *
893
901
  * @param {ExpectedInput} type
902
+ * @param {ExpectedInputOptions} [options]
894
903
  * @returns {this}
895
904
  * @example
896
905
  * bot.use((req, res) => {
897
906
  * res.expectedInput(res.ExpectedInputTypes.TYPE_PASSWORD)
898
907
  * });
899
908
  */
900
- expectedInput (type) {
909
+ expectedInput (type, options = {}) {
901
910
  this._messageSender.send({
902
- expectedIntentsAndEntities: [{ type }]
911
+ expectedIntentsAndEntities: [{ type, ...options }]
903
912
  });
904
913
  return this;
905
914
  }
@@ -83,18 +83,35 @@ class ButtonTemplate extends BaseTemplate {
83
83
  * @param {string} linkUrl - button url
84
84
  * @param {boolean} hasExtension - includes token in url
85
85
  * @param {string} [webviewHeight=null] - compact|tall|full
86
+ * @param {string} [onCloseAction] - close action for webview
87
+ * @param {object} [onCloseData] - data
86
88
  * @returns {this}
87
89
  *
88
90
  * @memberOf ButtonTemplate
89
91
  */
90
- urlButton (title, linkUrl, hasExtension = false, webviewHeight = null) {
91
- this.buttons.push({
92
+ urlButton (
93
+ title,
94
+ linkUrl,
95
+ hasExtension = false,
96
+ webviewHeight = null,
97
+ onCloseAction = null,
98
+ onCloseData = {}
99
+ ) {
100
+ const btn = {
92
101
  type: 'web_url',
93
102
  title: this._t(title),
94
103
  url: this._makeExtensionUrl(linkUrl, hasExtension),
95
104
  webview_height_ratio: webviewHeight || (hasExtension ? 'tall' : 'full'),
96
105
  messenger_extensions: hasExtension
97
- });
106
+ };
107
+ // on_close_payload
108
+ if (onCloseAction) {
109
+ Object.assign(btn, {
110
+ on_close_payload: this._createPayload(onCloseAction, onCloseData)
111
+ });
112
+ }
113
+
114
+ this.buttons.push(btn);
98
115
  return this;
99
116
  }
100
117
 
@@ -110,23 +127,27 @@ class ButtonTemplate extends BaseTemplate {
110
127
  * @memberOf ButtonTemplate
111
128
  */
112
129
  postBackButton (title, action, data = {}, setState = null) {
113
- const hasSetState = setState && Object.keys(setState).length !== 0;
114
-
115
130
  this.buttons.push({
116
131
  type: 'postback',
117
132
  title: this._t(title),
118
- payload: JSON.stringify({
119
- action: makeAbsolute(action, this.context.path),
120
- data: {
121
- _ca: this.context.currentAction,
122
- ...data
123
- },
124
- ...(hasSetState ? { setState } : {})
125
- })
133
+ payload: this._createPayload(action, data, setState)
126
134
  });
127
135
  return this;
128
136
  }
129
137
 
138
+ _createPayload (action, data, setState = null) {
139
+ const hasSetState = setState && Object.keys(setState).length !== 0;
140
+
141
+ return JSON.stringify({
142
+ action: makeAbsolute(action, this.context.path),
143
+ data: {
144
+ _ca: this.context.currentAction,
145
+ ...data
146
+ },
147
+ ...(hasSetState ? { setState } : {})
148
+ });
149
+ }
150
+
130
151
  /**
131
152
  * Adds button, which opens a popup with content on click.
132
153
  *