wingbot 3.67.31 → 3.68.0-alpha.2
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 +2 -2
- package/src/Responder.js +29 -9
- package/src/templates/ButtonTemplate.js +34 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.68.0-alpha.2",
|
|
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
|
|
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,20 @@ 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} [onCloseAction]
|
|
52
|
+
* @prop {string} [onCloseActionData]
|
|
53
|
+
*/
|
|
54
|
+
|
|
46
55
|
/**
|
|
47
56
|
* @typedef {object} QuickReply
|
|
48
57
|
* @prop {string} title
|
|
@@ -891,15 +900,22 @@ class Responder {
|
|
|
891
900
|
/**
|
|
892
901
|
*
|
|
893
902
|
* @param {ExpectedInput} type
|
|
903
|
+
* @param {ExpectedInputOptions} [options]
|
|
894
904
|
* @returns {this}
|
|
895
905
|
* @example
|
|
896
906
|
* bot.use((req, res) => {
|
|
897
907
|
* res.expectedInput(res.ExpectedInputTypes.TYPE_PASSWORD)
|
|
898
908
|
* });
|
|
899
909
|
*/
|
|
900
|
-
expectedInput (type) {
|
|
910
|
+
expectedInput (type, options = {}) {
|
|
911
|
+
const { onCloseAction, onCloseActionData = {}, ...rest } = options;
|
|
912
|
+
if (onCloseAction) {
|
|
913
|
+
Object.assign(rest, {
|
|
914
|
+
on_close_payload: this._makePayload(onCloseAction, onCloseActionData)
|
|
915
|
+
});
|
|
916
|
+
}
|
|
901
917
|
this._messageSender.send({
|
|
902
|
-
expectedIntentsAndEntities: [{ type }]
|
|
918
|
+
expectedIntentsAndEntities: [{ type, ...rest }]
|
|
903
919
|
});
|
|
904
920
|
return this;
|
|
905
921
|
}
|
|
@@ -1054,16 +1070,20 @@ class Responder {
|
|
|
1054
1070
|
return this.template({
|
|
1055
1071
|
template_type: 'one_time_notif_req',
|
|
1056
1072
|
title: this._t(title),
|
|
1057
|
-
payload:
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
...data,
|
|
1061
|
-
_ntfTag: tag
|
|
1062
|
-
}
|
|
1073
|
+
payload: this._makePayload(action, {
|
|
1074
|
+
...data,
|
|
1075
|
+
_ntfTag: tag
|
|
1063
1076
|
})
|
|
1064
1077
|
});
|
|
1065
1078
|
}
|
|
1066
1079
|
|
|
1080
|
+
_makePayload (action, data) {
|
|
1081
|
+
return JSON.stringify({
|
|
1082
|
+
action: makeAbsolute(action, this.path),
|
|
1083
|
+
data
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1067
1087
|
template (payload) {
|
|
1068
1088
|
const messageData = {
|
|
1069
1089
|
message: {
|
|
@@ -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 (
|
|
91
|
-
|
|
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:
|
|
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
|
*
|