@xapp/stentor-gbm 1.52.61 → 1.52.66
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/lib/ApiPoster.d.ts +2 -2
- package/lib/ApiPoster.js.map +1 -1
- package/lib/Channel.js +2 -2
- package/lib/GbmHandlerHook.js +3 -3
- package/lib/GbmHandlerHook.js.map +1 -1
- package/lib/Translators/TranslateResponse/index.d.ts +4 -4
- package/lib/Translators/TranslateResponse/index.js +9 -114
- package/lib/Translators/TranslateResponse/index.js.map +1 -1
- package/lib/Translators/convert.d.ts +26 -0
- package/lib/Translators/convert.js +128 -0
- package/lib/Translators/convert.js.map +1 -0
- package/lib/__tests__/Channel.test.js +3 -3
- package/lib/__tests__/Channel.test.js.map +1 -1
- package/lib/__tests__/guards.test.d.ts +1 -0
- package/lib/__tests__/guards.test.js +166 -0
- package/lib/__tests__/guards.test.js.map +1 -0
- package/lib/guards.d.ts +35 -0
- package/lib/guards.js +60 -0
- package/lib/guards.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/models/AgentMessage.d.ts +75 -15
- package/lib/models/AgentMessage.js +1 -0
- package/lib/models/AgentMessage.js.map +1 -1
- package/package.json +11 -11
- package/lib/Guards.d.ts +0 -13
- package/lib/Guards.js +0 -23
- package/lib/Guards.js.map +0 -1
package/lib/ApiPoster.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
-
import {
|
|
2
|
+
import { AgentMessageBase, Representative } from "./models";
|
|
3
3
|
export declare enum GmbEventType {
|
|
4
4
|
EVENT_TYPE_UNSPECIFIED = "EVENT_TYPE_UNSPECIFIED",
|
|
5
5
|
TYPING_STARTED = "TYPING_STARTED",
|
|
@@ -24,6 +24,6 @@ export interface ChatPostResult {
|
|
|
24
24
|
message?: string;
|
|
25
25
|
response?: any;
|
|
26
26
|
}
|
|
27
|
-
export declare function sendGbmMessage(messageObject:
|
|
27
|
+
export declare function sendGbmMessage(messageObject: AgentMessageBase, connectionUrl: string, conversationId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
|
28
28
|
export declare function sendGbmEvent(messageObject: AgentEvent, connectionUrl: string, conversationId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
|
29
29
|
export declare function sendGbmAck(messageObject: AgentReceipt, connectionUrl: string, conversationId: string, messageId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
package/lib/ApiPoster.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiPoster.js","sourceRoot":"","sources":["../src/ApiPoster.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;AAEpC,2CAA+B;AAC/B,6DAA0C;AAC1C,iDAAqC;AAErC,mDAAqC;AAErC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,gBAAgB,GAAG,kDAAkD,CAAC;AAC5E,MAAM,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAExC,IAAY,YAMX;AAND,WAAY,YAAY;IACpB,iEAAiD,CAAA;IACjD,iDAAiC,CAAA;IACjC,iDAAiC,CAAA;IACjC,+DAA+C,CAAA;IAC/C,2DAA2C,CAAA;AAC/C,CAAC,EANW,YAAY,4BAAZ,YAAY,QAMvB;AAED,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,uEAAqD,CAAA;IACrD,+BAAa,CAAA;AACjB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAkBD,IAAI,YAAoB,CAAC;AACzB,IAAI,wBAAgC,CAAC;AAErC,SAAsB,cAAc,CAChC,
|
|
1
|
+
{"version":3,"file":"ApiPoster.js","sourceRoot":"","sources":["../src/ApiPoster.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;AAEpC,2CAA+B;AAC/B,6DAA0C;AAC1C,iDAAqC;AAErC,mDAAqC;AAErC,MAAM,sBAAsB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EAAE,CAAC;QAEjC,UAAU;QACV,IAAI,YAAY,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,GAAG,GAAG,wBAAwB,CAAC;YAC7C,IAAI,KAAK,GAAG,gBAAgB,EAAE,CAAC;gBAC3B,OAAO,YAAY,CAAC;YACxB,CAAC;QACL,CAAC;QAED,IAAA,oBAAG,GAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAEvC,MAAM,UAAU,GAAG,IAAI,yBAAG,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEvF,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;YACxC,UAAU,CAAC,SAAS,CAAC,UAAU,GAAQ,EAAE,MAAW;gBAChD,IAAI,GAAG,EAAE,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACJ,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,YAAY,CAAC;oBACnD,wBAAwB,GAAG,GAAG,CAAC;oBAC/B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;gBACjD,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CAAA"}
|
package/lib/Channel.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.GoogleBusinessMessages = exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = exports.capabilities = void 0;
|
|
5
5
|
const Constants_1 = require("./Constants");
|
|
6
|
-
const
|
|
6
|
+
const guards_1 = require("./guards");
|
|
7
7
|
const GbmHandlerHook_1 = require("./GbmHandlerHook");
|
|
8
8
|
const Translators_1 = require("./Translators");
|
|
9
9
|
const PreResponseHook_1 = require("./PreResponseHook");
|
|
@@ -24,7 +24,7 @@ function capabilities(_body) {
|
|
|
24
24
|
exports.capabilities = capabilities;
|
|
25
25
|
exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = {
|
|
26
26
|
name: Constants_1.GOOGLE_BUSINESS_MESSAGES_PLATFORM,
|
|
27
|
-
test:
|
|
27
|
+
test: guards_1.isGbmPayload,
|
|
28
28
|
handlerHook: GbmHandlerHook_1.handlerHook,
|
|
29
29
|
request: new Translators_1.TranslateRequest(),
|
|
30
30
|
response: new Translators_1.TranslateResponse(),
|
package/lib/GbmHandlerHook.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.handlerHook = void 0;
|
|
|
13
13
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
14
14
|
const stentor_constants_1 = require("stentor-constants");
|
|
15
15
|
const stentor_logger_1 = require("stentor-logger");
|
|
16
|
-
const
|
|
16
|
+
const guards_1 = require("./guards");
|
|
17
17
|
const models_1 = require("./models");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
19
|
const ChatDataStore_1 = require("./ChatDataStore");
|
|
@@ -57,7 +57,7 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
57
57
|
botResponses.push({ error, result });
|
|
58
58
|
};
|
|
59
59
|
// Check the webhook payload
|
|
60
|
-
if ((0,
|
|
60
|
+
if ((0, guards_1.isGbmPayload)(event)) {
|
|
61
61
|
const conversationId = event.conversationId;
|
|
62
62
|
if (event.userStatus) {
|
|
63
63
|
(0, stentor_logger_1.log)().debug(`GBM user status: ${event.conversationId} - ${JSON.stringify(event.userStatus)}`);
|
|
@@ -65,7 +65,7 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
65
65
|
else if (event.receipts) {
|
|
66
66
|
(0, stentor_logger_1.log)().debug(`GBM user receipts: ${event.conversationId} - ${JSON.stringify(event.receipts)}`);
|
|
67
67
|
}
|
|
68
|
-
else if ((0,
|
|
68
|
+
else if ((0, guards_1.isGbmMessage)(event)) {
|
|
69
69
|
(0, stentor_logger_1.log)().info(`GBM: user message: ${JSON.stringify(event)}`);
|
|
70
70
|
const messageId = (_a = event.message) === null || _a === void 0 ? void 0 : _a.messageId;
|
|
71
71
|
const userId = conversationId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbmHandlerHook.js","sourceRoot":"","sources":["../src/GbmHandlerHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAAiF;AAEjF,mDAAqC;AAErC,qCAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"GbmHandlerHook.js","sourceRoot":"","sources":["../src/GbmHandlerHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAAiF;AAEjF,mDAAqC;AAErC,qCAAsD;AACtD,qCAA6F;AAE7F,+BAAoC;AAEpC,mDAAuE;AAEvE,2CAAqG;AAErG,MAAM,KAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CACnC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACpB,IAAA,oBAAG,GAAE,CAAC,IAAI,CAAC,oBAAoB,YAAY,QAAQ,CAAC,CAAC;IACrD,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEP,MAAM,WAAW,GAAG,4CAA4C,CAAC;AAEjE,SAAsB,WAAW,CAC7B,OAA2F,EAC3F,KAAU,EACV,OAAuB,EACvB,QAAkB,EAClB,QAAuE;;QAEvE,iBAAiB;QACjB,MAAM,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YACzF,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,oCAAoC,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAE1E,IAAI,aAAa,GAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAC9C,I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EAAE,CAAC,CAAC;oBACxG,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;QAED,sBAAsB;QACtB,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC;QAED,kCAAkC;QAClC,IAAI,aAAa,GAAW,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,gDAAgD;QAC9F,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YACxB,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,+BAAW,EAAE,aAAa,CAAC,CAAC;QACtE,CAAC;QAED,2CAA2C;QAC3C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;;CACjC;AAED,SAAS,iBAAiB;IACtB,OAAO,eAAe,IAAA,SAAM,GAAE,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
-
import { Translator } from "@xapp/patterns
|
|
2
|
+
import { Translator } from "@xapp/patterns";
|
|
3
3
|
import { RequestResponse } from "stentor-models";
|
|
4
|
-
import {
|
|
4
|
+
import { AgentMessageBase } from "../../models";
|
|
5
5
|
import { GbmChannelProps } from "../../Channel";
|
|
6
|
-
export declare class TranslateResponse extends Translator<RequestResponse,
|
|
6
|
+
export declare class TranslateResponse extends Translator<RequestResponse, AgentMessageBase | AgentMessageBase[]> {
|
|
7
7
|
protected readonly props?: GbmChannelProps;
|
|
8
8
|
constructor(props?: GbmChannelProps);
|
|
9
|
-
translate(requestResponse: RequestResponse):
|
|
9
|
+
translate(requestResponse: RequestResponse): AgentMessageBase | AgentMessageBase[];
|
|
10
10
|
private getRepresentative;
|
|
11
11
|
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TranslateResponse = void 0;
|
|
4
4
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
5
|
-
const
|
|
5
|
+
const patterns_1 = require("@xapp/patterns");
|
|
6
6
|
const stentor_response_1 = require("stentor-response");
|
|
7
7
|
const stentor_logger_1 = require("stentor-logger");
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
9
|
const RemoveMarkdown = require("remove-markdown");
|
|
10
|
+
const convert_1 = require("../convert");
|
|
10
11
|
const models_1 = require("../../models");
|
|
11
|
-
class TranslateResponse extends
|
|
12
|
+
class TranslateResponse extends patterns_1.Translator {
|
|
12
13
|
constructor(props) {
|
|
13
14
|
super();
|
|
14
15
|
this.props = props;
|
|
@@ -35,7 +36,7 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
const representative = this.getRepresentative();
|
|
38
|
-
const suggestions = convertSuggestions(outputSpeech.suggestions);
|
|
39
|
+
const suggestions = (0, convert_1.convertSuggestions)(outputSpeech.suggestions);
|
|
39
40
|
if (text) {
|
|
40
41
|
const supportMarkdown = process.env.GMB_SUPPORT_MARKDOWN === "true";
|
|
41
42
|
let containsRichText = false;
|
|
@@ -55,6 +56,9 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
55
56
|
}
|
|
56
57
|
if (card) {
|
|
57
58
|
const imageUrl = card.smallImageUrl || card.largeImageUrl;
|
|
59
|
+
// Card Content cannot have more than 4 suggestions with it
|
|
60
|
+
// https://developers.google.com/business-communications/business-messages/guides/how-to/message/send#rich-cards
|
|
61
|
+
const cardSuggestions = suggestions && suggestions.length > 4 ? suggestions.slice(0, 4) : suggestions;
|
|
58
62
|
gbmResponses.push({
|
|
59
63
|
messageId: (0, uuid_1.v4)(),
|
|
60
64
|
representative,
|
|
@@ -72,7 +76,7 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
: undefined,
|
|
75
|
-
suggestions
|
|
79
|
+
suggestions: cardSuggestions
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
@@ -83,7 +87,7 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
83
87
|
messageId: (0, uuid_1.v4)(),
|
|
84
88
|
representative,
|
|
85
89
|
richCard: {
|
|
86
|
-
carouselCard: list.items.length > 1 ? convertList(list) : undefined,
|
|
90
|
+
carouselCard: list.items.length > 1 ? (0, convert_1.convertList)(list) : undefined,
|
|
87
91
|
standaloneCard: list.items.length === 1
|
|
88
92
|
? {
|
|
89
93
|
cardContent: {
|
|
@@ -124,113 +128,4 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
exports.TranslateResponse = TranslateResponse;
|
|
127
|
-
/**
|
|
128
|
-
* Convert suggestions
|
|
129
|
-
*
|
|
130
|
-
* @param suggestions
|
|
131
|
-
*/
|
|
132
|
-
function convertSuggestions(suggestions) {
|
|
133
|
-
if (!suggestions || suggestions.length === 0) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
const gbmSuggestions = [];
|
|
137
|
-
for (const suggestion of suggestions) {
|
|
138
|
-
if (typeof suggestion === "string") {
|
|
139
|
-
gbmSuggestions.push({
|
|
140
|
-
reply: {
|
|
141
|
-
text: suggestion,
|
|
142
|
-
postbackData: suggestion
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
else if (suggestion.title && suggestion.url) {
|
|
147
|
-
const url = suggestion.url;
|
|
148
|
-
// Phone dial is separate - check the url of the action (<a href="tel:123-456-7890">Call</a>)
|
|
149
|
-
if (url.toLowerCase().startsWith("tel:")) {
|
|
150
|
-
const phoneNumber = url.substring(4);
|
|
151
|
-
gbmSuggestions.push({
|
|
152
|
-
action: {
|
|
153
|
-
text: suggestion.title,
|
|
154
|
-
postbackData: url,
|
|
155
|
-
dialAction: {
|
|
156
|
-
phoneNumber
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
gbmSuggestions.push({
|
|
163
|
-
action: {
|
|
164
|
-
text: suggestion.title,
|
|
165
|
-
postbackData: url,
|
|
166
|
-
openUrlAction: {
|
|
167
|
-
url
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else if (suggestion.title) {
|
|
174
|
-
gbmSuggestions.push({
|
|
175
|
-
reply: {
|
|
176
|
-
text: suggestion.title,
|
|
177
|
-
postbackData: suggestion.title
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return gbmSuggestions;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Convert stentor buttons to chips
|
|
186
|
-
*
|
|
187
|
-
* @param buttons
|
|
188
|
-
*/
|
|
189
|
-
function convertButtonSuggestions(buttons) {
|
|
190
|
-
if (!buttons || buttons.length === 0) {
|
|
191
|
-
return undefined;
|
|
192
|
-
}
|
|
193
|
-
const gbmSuggestions = [];
|
|
194
|
-
for (const button of buttons) {
|
|
195
|
-
if (button.title) {
|
|
196
|
-
gbmSuggestions.push({
|
|
197
|
-
reply: {
|
|
198
|
-
text: button.title,
|
|
199
|
-
postbackData: button.title
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return gbmSuggestions;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Create individual cards for the carousel
|
|
208
|
-
*
|
|
209
|
-
* @param list
|
|
210
|
-
*/
|
|
211
|
-
function convertList(list) {
|
|
212
|
-
var _a;
|
|
213
|
-
const cardContents = [];
|
|
214
|
-
for (const listItem of list.items) {
|
|
215
|
-
const imageUrl = (_a = listItem.image) === null || _a === void 0 ? void 0 : _a.url;
|
|
216
|
-
cardContents.push({
|
|
217
|
-
title: listItem.title,
|
|
218
|
-
description: listItem.description,
|
|
219
|
-
suggestions: convertButtonSuggestions(listItem.buttons),
|
|
220
|
-
media: imageUrl
|
|
221
|
-
? {
|
|
222
|
-
height: models_1.Height.MEDIUM,
|
|
223
|
-
contentInfo: {
|
|
224
|
-
fileUrl: imageUrl,
|
|
225
|
-
forceRefresh: false
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
: undefined
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return {
|
|
232
|
-
cardWidth: models_1.CardWidth.MEDIUM,
|
|
233
|
-
cardContents: cardContents
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
131
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Translators/TranslateResponse/index.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Translators/TranslateResponse/index.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,6CAA4C;AAG5C,uDAAkD;AAClD,mDAAqC;AAErC,+BAAoC;AACpC,kDAAmD;AAEnD,wCAA6D;AAC7D,yCAOsB;AAGtB,MAAa,iBAAkB,SAAQ,qBAAkE;IAGrG,YAAY,KAAuB;QAC/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEM,SAAS,CAAC,eAAgC;QAC7C,MAAM,YAAY,GAAuB,EAAE,CAAC;QAE5C,MAAM,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC;QAE7C,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE5D,IAAI,WAAW,EAAE,CAAC;YACd,IAAI,IAAY,CAAC;YACjB,IAAI,IAAI,CAAC;YACT,IAAI,IAAI,CAAC;YAET,MAAM,YAAY,GAAG,WAAW,CAAC,YAA8B,CAAC;YAEhE,IAAI,YAAY,EAAE,CAAC;gBACf,IA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AC,CAAC,CAAC,KAAK,CAAC,GAAG;gDAChC,YAAY,EAAE,KAAK;6CACtB;yCACJ;wCACD,CAAC,CAAC,SAAS;oCACf,WAAW;iCACd;6BACJ;4BACD,CAAC,CAAC,SAAS;qBACtB;iBACoB,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,YAAY,CAAC,IAAI,CAAC;gBACd,SAAS,EAAE,IAAA,SAAM,GAAE;gBACnB,cAAc,EAAE,IAAI,CAAC,iBAAiB,EAAE;gBACxC,IAAI,EAAE,wEAAwE;aAC7D,CAAC,CAAC;QAC3B,CAAC;QAED,OAAO,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IACtE,CAAC;IAEO,iBAAiB;QACrB,OAAO;YACH,kBAAkB,EAAE,2BAAkB,CAAC,GAAG;YAC1C,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;YACrC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB;SAC5C,CAAC;IACN,CAAC;CACJ;AAxID,8CAwIC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
+
import { ListButton, SuggestionTypes } from "stentor-models";
|
|
3
|
+
import { List } from "stentor-models/lib/Display/List/List";
|
|
4
|
+
import { CarouselCard, Suggestion } from "../models";
|
|
5
|
+
/**
|
|
6
|
+
* Convert suggestions
|
|
7
|
+
*
|
|
8
|
+
* We will also remove any suggestions over 25 characters and limit this initial list to 13, the max for TextAgentMessages.
|
|
9
|
+
*
|
|
10
|
+
* @see https://developers.google.com/business-communications/business-messages/guides/how-to/message/send#text:~:text=Suggested%20replies%20have%20a%20maximum%20of%2025%20characters%2C%20and%20a%20message%20has%20a%20maximum%20of%2013%20suggestions.
|
|
11
|
+
*
|
|
12
|
+
* @param suggestions
|
|
13
|
+
*/
|
|
14
|
+
export declare function convertSuggestions(suggestions: SuggestionTypes[]): Suggestion[];
|
|
15
|
+
/**
|
|
16
|
+
* Convert stentor buttons to chips
|
|
17
|
+
*
|
|
18
|
+
* @param buttons
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertButtonSuggestions(buttons: ListButton[]): Suggestion[];
|
|
21
|
+
/**
|
|
22
|
+
* Create individual cards for the carousel
|
|
23
|
+
*
|
|
24
|
+
* @param list
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertList(list: List): CarouselCard;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.convertList = exports.convertButtonSuggestions = exports.convertSuggestions = void 0;
|
|
5
|
+
const models_1 = require("../models");
|
|
6
|
+
/**
|
|
7
|
+
* Convert suggestions
|
|
8
|
+
*
|
|
9
|
+
* We will also remove any suggestions over 25 characters and limit this initial list to 13, the max for TextAgentMessages.
|
|
10
|
+
*
|
|
11
|
+
* @see https://developers.google.com/business-communications/business-messages/guides/how-to/message/send#text:~:text=Suggested%20replies%20have%20a%20maximum%20of%2025%20characters%2C%20and%20a%20message%20has%20a%20maximum%20of%2013%20suggestions.
|
|
12
|
+
*
|
|
13
|
+
* @param suggestions
|
|
14
|
+
*/
|
|
15
|
+
function convertSuggestions(suggestions) {
|
|
16
|
+
if (!suggestions || suggestions.length === 0) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const gbmSuggestions = [];
|
|
20
|
+
for (const suggestion of suggestions) {
|
|
21
|
+
// only push if it is less than 25 characters
|
|
22
|
+
if (typeof suggestion === "string") {
|
|
23
|
+
if (suggestion.length <= 25) {
|
|
24
|
+
gbmSuggestions.push({
|
|
25
|
+
reply: {
|
|
26
|
+
text: suggestion,
|
|
27
|
+
postbackData: suggestion
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (suggestion.title && suggestion.url) {
|
|
33
|
+
// skip if over 25 characters
|
|
34
|
+
if (suggestion.title.length <= 25) {
|
|
35
|
+
const url = suggestion.url;
|
|
36
|
+
// Phone dial is separate - check the url of the action (<a href="tel:123-456-7890">Call</a>)
|
|
37
|
+
if (url.toLowerCase().startsWith("tel:")) {
|
|
38
|
+
const phoneNumber = url.substring(4);
|
|
39
|
+
gbmSuggestions.push({
|
|
40
|
+
action: {
|
|
41
|
+
text: suggestion.title,
|
|
42
|
+
postbackData: url,
|
|
43
|
+
dialAction: {
|
|
44
|
+
phoneNumber
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
gbmSuggestions.push({
|
|
51
|
+
action: {
|
|
52
|
+
text: suggestion.title,
|
|
53
|
+
postbackData: url,
|
|
54
|
+
openUrlAction: {
|
|
55
|
+
url
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (suggestion.title) {
|
|
63
|
+
gbmSuggestions.push({
|
|
64
|
+
reply: {
|
|
65
|
+
text: suggestion.title,
|
|
66
|
+
postbackData: suggestion.title
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return gbmSuggestions.slice(0, 13);
|
|
72
|
+
}
|
|
73
|
+
exports.convertSuggestions = convertSuggestions;
|
|
74
|
+
/**
|
|
75
|
+
* Convert stentor buttons to chips
|
|
76
|
+
*
|
|
77
|
+
* @param buttons
|
|
78
|
+
*/
|
|
79
|
+
function convertButtonSuggestions(buttons) {
|
|
80
|
+
if (!buttons || buttons.length === 0) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const gbmSuggestions = [];
|
|
84
|
+
for (const button of buttons) {
|
|
85
|
+
if (button.title) {
|
|
86
|
+
gbmSuggestions.push({
|
|
87
|
+
reply: {
|
|
88
|
+
text: button.title,
|
|
89
|
+
postbackData: button.title
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return gbmSuggestions;
|
|
95
|
+
}
|
|
96
|
+
exports.convertButtonSuggestions = convertButtonSuggestions;
|
|
97
|
+
/**
|
|
98
|
+
* Create individual cards for the carousel
|
|
99
|
+
*
|
|
100
|
+
* @param list
|
|
101
|
+
*/
|
|
102
|
+
function convertList(list) {
|
|
103
|
+
var _a;
|
|
104
|
+
const cardContents = [];
|
|
105
|
+
for (const listItem of list.items) {
|
|
106
|
+
const imageUrl = (_a = listItem.image) === null || _a === void 0 ? void 0 : _a.url;
|
|
107
|
+
cardContents.push({
|
|
108
|
+
title: listItem.title,
|
|
109
|
+
description: listItem.description,
|
|
110
|
+
suggestions: convertButtonSuggestions(listItem.buttons),
|
|
111
|
+
media: imageUrl
|
|
112
|
+
? {
|
|
113
|
+
height: models_1.Height.MEDIUM,
|
|
114
|
+
contentInfo: {
|
|
115
|
+
fileUrl: imageUrl,
|
|
116
|
+
forceRefresh: false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
: undefined
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
cardWidth: models_1.CardWidth.MEDIUM,
|
|
124
|
+
cardContents: cardContents
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
exports.convertList = convertList;
|
|
128
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/Translators/convert.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAKpC,sCAKmB;AAEnB;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAAC,WAA8B;IAC7D,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3C,OAAO,SAAS,C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,YAAY,EAAE,KAAK;qBACtB;iBACJ;gBACD,CAAC,CAAC,SAAS;SAClB,CAAC,CAAC;IACP,CAAC;IAED,OAAO;QACH,SAAS,EAAE,kBAAS,CAAC,MAAM;QAC3B,YAAY,EAAE,YAAY;KAC7B,CAAC;AACN,CAAC;AA1BD,kCA0BC"}
|
|
@@ -5,7 +5,7 @@ const chai = require("chai");
|
|
|
5
5
|
const sinonChai = require("sinon-chai");
|
|
6
6
|
const Channel_1 = require("../Channel");
|
|
7
7
|
const Constants_1 = require("../Constants");
|
|
8
|
-
const
|
|
8
|
+
const guards_1 = require("../guards");
|
|
9
9
|
const Translators_1 = require("../Translators");
|
|
10
10
|
chai.use(sinonChai);
|
|
11
11
|
const expect = chai.expect;
|
|
@@ -59,7 +59,7 @@ describe("google business messages channel functions", () => {
|
|
|
59
59
|
expect(channel.name).to.equal(Constants_1.GOOGLE_BUSINESS_MESSAGES_PLATFORM);
|
|
60
60
|
expect(channel.request).to.be.an.instanceOf(Translators_1.TranslateRequest);
|
|
61
61
|
expect(channel.response).to.be.an.instanceOf(Translators_1.TranslateResponse);
|
|
62
|
-
expect(channel.test).to.equals(
|
|
62
|
+
expect(channel.test).to.equals(guards_1.isGbmPayload);
|
|
63
63
|
expect(channel.capabilities).to.equals(Channel_1.capabilities);
|
|
64
64
|
});
|
|
65
65
|
});
|
|
@@ -87,7 +87,7 @@ describe("google business messages channel functions", () => {
|
|
|
87
87
|
let isGbmChannel;
|
|
88
88
|
describe("for a request", () => {
|
|
89
89
|
beforeEach(() => {
|
|
90
|
-
isGbmChannel = (0,
|
|
90
|
+
isGbmChannel = (0, guards_1.isGbmPayload)(gbmRequest);
|
|
91
91
|
});
|
|
92
92
|
it("recognizes the channel", () => {
|
|
93
93
|
expect(isGbmChannel).to.be.true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Channel.test.js","sourceRoot":"","sources":["../../src/__tests__/Channel.test.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AA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AAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAqB,CAAC;oBAC3G,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC,oBAAoB;oBAChD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;wBACzB,gBAAgB,EAAE,KAAK;wBACvB,SAAS,EAAE,OAAO;wBAClB,cAAc,EAAE;4BACZ,WAAW,EAAE,gCAAgC;4BAC7C,WAAW,EAAE,aAAa;4BAC1B,kBAAkB,EAAE,KAAK;yBAC5B;wBACD,WAAW,EAAE,SAAS;wBACtB,IAAI,EAAE,UAAU;qBACnB,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const guards_1 = require("../guards");
|
|
6
|
+
const AgentMessage_1 = require("../models/AgentMessage");
|
|
7
|
+
const baseMessage = {
|
|
8
|
+
messageId: "messageId",
|
|
9
|
+
representative: {
|
|
10
|
+
displayName: "name",
|
|
11
|
+
avatarImage: "https://avatar.url",
|
|
12
|
+
representativeType: AgentMessage_1.RepresentativeType.BOT
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
describe("isTextAgentMessage", () => {
|
|
16
|
+
it("should return true for a TextAgentMessage", () => {
|
|
17
|
+
const message = Object.assign(Object.assign({}, baseMessage), { text: "Hello, world!" });
|
|
18
|
+
(0, chai_1.expect)((0, guards_1.isTextAgentMessage)(message)).to.be.true;
|
|
19
|
+
});
|
|
20
|
+
it("should return false for an ImageAgentMessage", () => {
|
|
21
|
+
const message = Object.assign(Object.assign({}, baseMessage), { image: {
|
|
22
|
+
contentInfo: {
|
|
23
|
+
fileUrl: "https://example.com/image.jpg",
|
|
24
|
+
forceRefresh: false
|
|
25
|
+
}
|
|
26
|
+
} });
|
|
27
|
+
(0, chai_1.expect)((0, guards_1.isTextAgentMessage)(message)).to.be.false;
|
|
28
|
+
});
|
|
29
|
+
it("should return false for a RichCardAgentMessage", () => {
|
|
30
|
+
const message = Object.assign(Object.assign({}, baseMessage), { richCard: {
|
|
31
|
+
standaloneCard: {
|
|
32
|
+
cardContent: {}
|
|
33
|
+
}
|
|
34
|
+
} });
|
|
35
|
+
(0, chai_1.expect)((0, guards_1.isTextAgentMessage)(message)).to.be.false;
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("isImageAgentMessage", () => {
|
|
39
|
+
it("should return true for an ImageAgentMessage", () => {
|
|
40
|
+
const message = Object.assign(Object.assign({}, baseMessage), { image: {
|
|
41
|
+
contentInfo: {
|
|
42
|
+
fileUrl: "https://example.com/image.jpg",
|
|
43
|
+
forceRefresh: false
|
|
44
|
+
}
|
|
45
|
+
} });
|
|
46
|
+
(0, chai_1.expect)((0, guards_1.isImageAgentMessage)(message)).to.be.true;
|
|
47
|
+
});
|
|
48
|
+
it("should return false for a TextAgentMessage", () => {
|
|
49
|
+
const message = Object.assign(Object.assign({}, baseMessage), { text: "Hello, world!" });
|
|
50
|
+
(0, chai_1.expect)((0, guards_1.isImageAgentMessage)(message)).to.be.false;
|
|
51
|
+
});
|
|
52
|
+
it("should return false for a RichCardAgentMessage", () => {
|
|
53
|
+
const message = Object.assign(Object.assign({}, baseMessage), { richCard: {
|
|
54
|
+
standaloneCard: {
|
|
55
|
+
cardContent: {}
|
|
56
|
+
}
|
|
57
|
+
} });
|
|
58
|
+
(0, chai_1.expect)((0, guards_1.isImageAgentMessage)(message)).to.be.false;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe("isRichCardAgentMessage", () => {
|
|
62
|
+
it("should return true for a RichCardAgentMessage", () => {
|
|
63
|
+
const message = Object.assign(Object.assign({}, baseMessage), { richCard: {
|
|
64
|
+
standaloneCard: {
|
|
65
|
+
cardContent: {}
|
|
66
|
+
}
|
|
67
|
+
} });
|
|
68
|
+
(0, chai_1.expect)((0, guards_1.isRichCardAgentMessage)(message)).to.be.true;
|
|
69
|
+
});
|
|
70
|
+
it("should return false for a TextAgentMessage", () => {
|
|
71
|
+
const message = Object.assign(Object.assign({}, baseMessage), { text: "Hello, world!" });
|
|
72
|
+
(0, chai_1.expect)((0, guards_1.isRichCardAgentMessage)(message)).to.be.false;
|
|
73
|
+
});
|
|
74
|
+
it("should return false for an ImageAgentMessage", () => {
|
|
75
|
+
const message = Object.assign(Object.assign({}, baseMessage), { image: {
|
|
76
|
+
contentInfo: {
|
|
77
|
+
fileUrl: "https://example.com/image.jpg",
|
|
78
|
+
forceRefresh: false
|
|
79
|
+
}
|
|
80
|
+
} });
|
|
81
|
+
(0, chai_1.expect)((0, guards_1.isRichCardAgentMessage)(message)).to.be.false;
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe("isGbmPayload", () => {
|
|
85
|
+
it("should return true for a GbmPayload", () => {
|
|
86
|
+
const requestBody = {
|
|
87
|
+
secret: "secret",
|
|
88
|
+
clientToken: "token",
|
|
89
|
+
requestId: "requestId",
|
|
90
|
+
conversationId: "conversationId",
|
|
91
|
+
agent: "agent",
|
|
92
|
+
context: {
|
|
93
|
+
userInfo: { displayName: "displayName", userDeviceLocale: "en-US" }
|
|
94
|
+
},
|
|
95
|
+
sendTime: "2022-10-18T16:18:58.252717Z"
|
|
96
|
+
};
|
|
97
|
+
(0, chai_1.expect)((0, guards_1.isGbmPayload)(requestBody)).to.be.true;
|
|
98
|
+
});
|
|
99
|
+
it("should return true for a GbmMessage", () => {
|
|
100
|
+
const requestBody = {
|
|
101
|
+
secret: "secret",
|
|
102
|
+
clientToken: "token",
|
|
103
|
+
requestId: "requestId",
|
|
104
|
+
conversationId: "conversationId",
|
|
105
|
+
agent: "agent",
|
|
106
|
+
context: {
|
|
107
|
+
userInfo: { displayName: "displayName", userDeviceLocale: "en-US" }
|
|
108
|
+
},
|
|
109
|
+
sendTime: "2022-10-18T16:18:58.252717Z"
|
|
110
|
+
};
|
|
111
|
+
(0, chai_1.expect)((0, guards_1.isGbmPayload)(requestBody)).to.be.true;
|
|
112
|
+
});
|
|
113
|
+
it("should return false for an empty object", () => {
|
|
114
|
+
const requestBody = {};
|
|
115
|
+
// @ts-expect-error Just for testing
|
|
116
|
+
(0, chai_1.expect)((0, guards_1.isGbmPayload)(requestBody)).to.be.false;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("isGbmMessage", () => {
|
|
120
|
+
it("should return true for a GbmMessage", () => {
|
|
121
|
+
const requestBody = {
|
|
122
|
+
secret: "secret",
|
|
123
|
+
clientToken: "token",
|
|
124
|
+
requestId: "requestId",
|
|
125
|
+
conversationId: "conversationId",
|
|
126
|
+
agent: "agent",
|
|
127
|
+
context: {
|
|
128
|
+
userInfo: { displayName: "displayName", userDeviceLocale: "en-US" }
|
|
129
|
+
},
|
|
130
|
+
message: {
|
|
131
|
+
messageId: "messageId",
|
|
132
|
+
name: "name",
|
|
133
|
+
createTime: "",
|
|
134
|
+
text: ""
|
|
135
|
+
},
|
|
136
|
+
sendTime: "2022-10-18T16:18:58.252717Z"
|
|
137
|
+
};
|
|
138
|
+
(0, chai_1.expect)((0, guards_1.isGbmMessage)(requestBody)).to.be.true;
|
|
139
|
+
});
|
|
140
|
+
it("should return true for a GbmPayload", () => {
|
|
141
|
+
const requestBody = {
|
|
142
|
+
secret: "secret",
|
|
143
|
+
clientToken: "token",
|
|
144
|
+
requestId: "requestId",
|
|
145
|
+
conversationId: "conversationId",
|
|
146
|
+
agent: "agent",
|
|
147
|
+
context: {
|
|
148
|
+
userInfo: { displayName: "displayName", userDeviceLocale: "en-US" }
|
|
149
|
+
},
|
|
150
|
+
message: {
|
|
151
|
+
messageId: "messageId",
|
|
152
|
+
name: "name",
|
|
153
|
+
createTime: "",
|
|
154
|
+
text: ""
|
|
155
|
+
},
|
|
156
|
+
sendTime: "2022-10-18T16:18:58.252717Z"
|
|
157
|
+
};
|
|
158
|
+
(0, chai_1.expect)((0, guards_1.isGbmMessage)(requestBody)).to.be.true;
|
|
159
|
+
});
|
|
160
|
+
it("should return false for an empty object", () => {
|
|
161
|
+
const requestBody = {};
|
|
162
|
+
// @ts-expect-error Just for testing
|
|
163
|
+
(0, chai_1.expect)((0, guards_1.isGbmMessage)(requestBody)).to.be.false;
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=guards.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.test.js","sourceRoot":"","sources":["../../src/__tests__/guards.test.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,+BAA8B;AAC9B,sCAAwH;AACxH,yDAAyI;AAGzI,MAAM,WAAW,GAAqB;IAClC,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE;QACZ,WAAW,EAAE,MAAM;QACnB,WAAW,EAAE,oBAAoB;QACjC,kBAAkB,EAAE,iCAAkB,CAAC,GAAG;KAC7C;CACJ,CAAA;AAED,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACjD,MAAM,OAAO,mCACN,WAAW,KACd,IAAI,EAAE,eAAe,GACxB,CAAC;QACF,IAAA,aAAM,EAAC,IAAA,2BAAkB,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,MAAM,OAAO,mCACN,WAAW,KACd,KAAK,EAAE;gBACH,WAAW,EAAE;oBACT,OAAO,EAAE,+BAA+B;o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D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/lib/guards.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
import { AgentMessage, TextAgentMessage, ImageAgentMessage, RichCardAgentMessage, RichCard, StandaloneRichCard, CarouselRichCard } from "./models/AgentMessage";
|
|
3
|
+
import { UserMessage } from "./models/UserMessage";
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given object is a TextAgentMessage.
|
|
6
|
+
* @param object - The object to check.
|
|
7
|
+
* @returns True if the object is a TextAgentMessage, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isTextAgentMessage(object: AgentMessage): object is TextAgentMessage;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the given object is an ImageAgentMessage.
|
|
12
|
+
* @param object - The object to check.
|
|
13
|
+
* @returns True if the object is an ImageAgentMessage, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isImageAgentMessage(object: AgentMessage): object is ImageAgentMessage;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the given object is a RichCardAgentMessage.
|
|
18
|
+
* @param object - The object to check.
|
|
19
|
+
* @returns True if the object is a RichCardAgentMessage, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isRichCardAgentMessage(object: AgentMessage): object is RichCardAgentMessage;
|
|
22
|
+
export declare function isStandaloneRichCard(object: RichCard): object is StandaloneRichCard;
|
|
23
|
+
export declare function isCarouselRichCard(object: RichCard): object is CarouselRichCard;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the given requestBody is a GbmPayload.
|
|
26
|
+
* @param requestBody - The requestBody to check.
|
|
27
|
+
* @returns True if the requestBody is a GbmPayload, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isGbmPayload(requestBody: UserMessage): requestBody is UserMessage;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the given requestBody is a GbmMessage.
|
|
32
|
+
* @param requestBody - The requestBody to check.
|
|
33
|
+
* @returns True if the requestBody is a GbmMessage, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isGbmMessage(requestBody: UserMessage): requestBody is UserMessage;
|
package/lib/guards.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isGbmMessage = exports.isGbmPayload = exports.isCarouselRichCard = exports.isStandaloneRichCard = exports.isRichCardAgentMessage = exports.isImageAgentMessage = exports.isTextAgentMessage = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given object is a TextAgentMessage.
|
|
7
|
+
* @param object - The object to check.
|
|
8
|
+
* @returns True if the object is a TextAgentMessage, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
function isTextAgentMessage(object) {
|
|
11
|
+
return 'text' in object;
|
|
12
|
+
}
|
|
13
|
+
exports.isTextAgentMessage = isTextAgentMessage;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the given object is an ImageAgentMessage.
|
|
16
|
+
* @param object - The object to check.
|
|
17
|
+
* @returns True if the object is an ImageAgentMessage, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
function isImageAgentMessage(object) {
|
|
20
|
+
return 'image' in object;
|
|
21
|
+
}
|
|
22
|
+
exports.isImageAgentMessage = isImageAgentMessage;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given object is a RichCardAgentMessage.
|
|
25
|
+
* @param object - The object to check.
|
|
26
|
+
* @returns True if the object is a RichCardAgentMessage, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
function isRichCardAgentMessage(object) {
|
|
29
|
+
return 'richCard' in object;
|
|
30
|
+
}
|
|
31
|
+
exports.isRichCardAgentMessage = isRichCardAgentMessage;
|
|
32
|
+
function isStandaloneRichCard(object) {
|
|
33
|
+
return 'standaloneCard' in object;
|
|
34
|
+
}
|
|
35
|
+
exports.isStandaloneRichCard = isStandaloneRichCard;
|
|
36
|
+
function isCarouselRichCard(object) {
|
|
37
|
+
return 'carouselCard' in object;
|
|
38
|
+
}
|
|
39
|
+
exports.isCarouselRichCard = isCarouselRichCard;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the given requestBody is a GbmPayload.
|
|
42
|
+
* @param requestBody - The requestBody to check.
|
|
43
|
+
* @returns True if the requestBody is a GbmPayload, false otherwise.
|
|
44
|
+
*/
|
|
45
|
+
function isGbmPayload(requestBody) {
|
|
46
|
+
return !!requestBody.secret && !!requestBody.clientToken // verification
|
|
47
|
+
|| !!requestBody.agent && !!requestBody.sendTime && !!requestBody.requestId; // message
|
|
48
|
+
}
|
|
49
|
+
exports.isGbmPayload = isGbmPayload;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the given requestBody is a GbmMessage.
|
|
52
|
+
* @param requestBody - The requestBody to check.
|
|
53
|
+
* @returns True if the requestBody is a GbmMessage, false otherwise.
|
|
54
|
+
*/
|
|
55
|
+
function isGbmMessage(requestBody) {
|
|
56
|
+
return !!requestBody.message || !!requestBody.suggestionResponse
|
|
57
|
+
|| !!requestBody.userStatus && !!requestBody.userStatus.requestedLiveAgent; // message
|
|
58
|
+
}
|
|
59
|
+
exports.isGbmMessage = isGbmMessage;
|
|
60
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAclC;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,MAAoB;IACnD,OAAO,MAAM,IAAI,MAAM,CAAC;AAC5B,CAAC;AAFD,gDAEC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,MAAoB;IACpD,OAAO,OAAO,IAAI,MAAM,CAAC;AAC7B,CAAC;AAFD,kDAEC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,MAAoB;IACvD,OAAO,UAAU,IAAI,MAAM,CAAC;AAChC,CAAC;AAFD,wDAEC;AAGD,SAAgB,oBAAoB,CAAC,MAAgB;IACjD,OAAO,gBAAgB,IAAI,MAAM,CAAC;AACtC,CAAC;AAFD,oDAEC;AAED,SAAgB,kBAAkB,CAAC,MAAgB;IAC/C,OAAO,cAAc,IAAI,MAAM,CAAC;AACpC,CAAC;AAFD,gDAEC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,WAAwB;IACjD,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,eAAe;WACjE,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,UAAU;AAC/F,CAAC;AAHD,oCAGC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,WAAwB;IACjD,OAAO,CAAC,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,CAAC,WAAW,CAAC,kBAAkB;WACzD,CAAC,CAAC,WAAW,CAAC,UAAU,IAAI,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,UAAU;AAC9F,CAAC;AAHD,oCAGC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
2
|
export { GoogleBusinessMessages } from "./Channel";
|
|
3
3
|
export * from "./Constants";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./guards";
|
|
5
5
|
export * from "./Translators";
|
|
6
6
|
export * from "./Types";
|
|
7
7
|
export * from "./ApiPoster";
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.GoogleBusinessMessages = void 0;
|
|
|
19
19
|
var Channel_1 = require("./Channel");
|
|
20
20
|
Object.defineProperty(exports, "GoogleBusinessMessages", { enumerable: true, get: function () { return Channel_1.GoogleBusinessMessages; } });
|
|
21
21
|
__exportStar(require("./Constants"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./guards"), exports);
|
|
23
23
|
__exportStar(require("./Translators"), exports);
|
|
24
24
|
__exportStar(require("./Types"), exports);
|
|
25
25
|
__exportStar(require("./ApiPoster"), exports);
|
|
@@ -1,23 +1,77 @@
|
|
|
1
1
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
-
export
|
|
2
|
+
export type AgentMessage = TextAgentMessage | ImageAgentMessage | RichCardAgentMessage;
|
|
3
|
+
export type TextAgentMessage = AgentMessageBase & {
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
export type ImageAgentMessage = AgentMessageBase & {
|
|
7
|
+
image: Image;
|
|
8
|
+
};
|
|
9
|
+
export type RichCardAgentMessage = AgentMessageBase & {
|
|
10
|
+
richCard: RichCard;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Primary Message object for GBM.
|
|
14
|
+
*
|
|
15
|
+
* Do not use this directly, instead use TextAgentMessage, ImageAgentMessage, or RichCardAgentMessage.
|
|
16
|
+
*
|
|
17
|
+
* @see https://developers.google.com/business-communications/business-messages/reference/rest/v1/conversations.messages#Message
|
|
18
|
+
*/
|
|
19
|
+
export interface AgentMessageBase {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the message, as set by Business Messages. Resolves to "conversations/{conversationId}/messages/{messageId}", where {conversationId} is the unique ID for the conversation and {messageId} is the unique ID for the message.
|
|
22
|
+
*/
|
|
23
|
+
name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Required. The unique identifier of the message, assigned by the agent. If a message attempts to use the same messageId as a previous message, the proper delivery of the message could be affected.
|
|
26
|
+
*/
|
|
3
27
|
messageId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Details about the representative (human or chatbot) that sent the message.
|
|
30
|
+
*/
|
|
4
31
|
representative: Representative;
|
|
32
|
+
/**
|
|
33
|
+
* A list of suggested replies that appear as a list of suggestion chips following the associated message. Maximum 13 suggestions.
|
|
34
|
+
*
|
|
35
|
+
* The chips only display when the associated message is the most recent message within the conversation (including both agent and user messages). The user can tap a suggested reply to send the text reply to the agent.
|
|
36
|
+
*/
|
|
5
37
|
suggestions?: Suggestion[];
|
|
38
|
+
/**
|
|
39
|
+
* Optional. Fallback text that displays if the user's device doesn't support the message type or content. Maximum 3,072 characters.
|
|
40
|
+
*/
|
|
6
41
|
fallback?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optional. If true, indicates that the message contains rich text. If the message contains invalid formatting, Business Messages returns an error.
|
|
44
|
+
*/
|
|
7
45
|
containsRichText?: boolean;
|
|
8
|
-
name?: string;
|
|
9
|
-
text?: string;
|
|
10
|
-
image?: Image;
|
|
11
|
-
richCard?: RichCard;
|
|
12
46
|
}
|
|
13
47
|
export declare enum RepresentativeType {
|
|
14
48
|
REPRESENTATIVE_TYPE_UNSPECIFIED = "REPRESENTATIVE_TYPE_UNSPECIFIED",
|
|
15
49
|
BOT = "BOT",
|
|
16
50
|
HUMAN = "HUMAN"
|
|
17
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Details about the representative (human or chatbot) that sent the message.
|
|
54
|
+
*
|
|
55
|
+
* @see https://developers.google.com/business-communications/business-messages/reference/rest/v1/Representative
|
|
56
|
+
*/
|
|
18
57
|
export interface Representative {
|
|
19
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Optional. Name of the representative.
|
|
60
|
+
*/
|
|
61
|
+
displayName?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional. The representative's avatar image, as a publicly available URL. Displays as a circle.
|
|
64
|
+
*
|
|
65
|
+
* Avatar images don't support personal information, such as depictions of representatives in photographs or illustrations. Use images that don't identify individuals, such as icons, logos, or fictitious illustrations. After an avatar image is used in a message, the image can't be modified or deleted.
|
|
66
|
+
*
|
|
67
|
+
* Images must be 1024x1024 px and have a maximum files size of 50 KB.
|
|
68
|
+
*/
|
|
20
69
|
avatarImage: string;
|
|
70
|
+
/**
|
|
71
|
+
* Required. The type of representative.
|
|
72
|
+
*
|
|
73
|
+
* @see https://developers.google.com/business-communications/business-messages/reference/rest/v1/Representative#RepresentativeType
|
|
74
|
+
*/
|
|
21
75
|
representativeType: RepresentativeType;
|
|
22
76
|
}
|
|
23
77
|
interface SuggestedReply {
|
|
@@ -66,13 +120,19 @@ interface Media {
|
|
|
66
120
|
height: Height;
|
|
67
121
|
contentInfo: ContentInfo;
|
|
68
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @see https://developers.google.com/business-communications/business-messages/reference/rest/v1/conversations.messages#cardcontent
|
|
125
|
+
*/
|
|
69
126
|
interface CardContent {
|
|
70
|
-
title
|
|
71
|
-
description
|
|
72
|
-
media
|
|
73
|
-
suggestions
|
|
127
|
+
title?: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
media?: Media;
|
|
130
|
+
suggestions?: Suggestion[];
|
|
74
131
|
}
|
|
75
|
-
|
|
132
|
+
export type StandaloneRichCard = {
|
|
133
|
+
standaloneCard: StandaloneCard;
|
|
134
|
+
};
|
|
135
|
+
export interface StandaloneCard {
|
|
76
136
|
cardContent: CardContent;
|
|
77
137
|
}
|
|
78
138
|
export declare enum CardWidth {
|
|
@@ -80,14 +140,14 @@ export declare enum CardWidth {
|
|
|
80
140
|
SMALL = "SMALL",
|
|
81
141
|
MEDIUM = "MEDIUM"
|
|
82
142
|
}
|
|
143
|
+
export type CarouselRichCard = {
|
|
144
|
+
carouselCard: CarouselCard;
|
|
145
|
+
};
|
|
83
146
|
export interface CarouselCard {
|
|
84
147
|
cardWidth: CardWidth;
|
|
85
148
|
cardContents: CardContent[];
|
|
86
149
|
}
|
|
87
|
-
export
|
|
88
|
-
standaloneCard?: StandaloneCard;
|
|
89
|
-
carouselCard?: CarouselCard;
|
|
90
|
-
}
|
|
150
|
+
export type RichCard = StandaloneRichCard | CarouselRichCard;
|
|
91
151
|
interface ContentInfo {
|
|
92
152
|
fileUrl: string;
|
|
93
153
|
thumbnailUrl?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentMessage.js","sourceRoot":"","sources":["../../src/models/AgentMessage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AgentMessage.js","sourceRoot":"","sources":["../../src/models/AgentMessage.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AA+CpC,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC1B,yFAAmE,CAAA;IACnE,iCAAW,CAAA;IACX,qCAAe,CAAA;AACnB,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B;AA8DD,IAAY,MAKX;AALD,WAAY,MAAM;IACd,mDAAyC,CAAA;IACzC,yBAAe,CAAA;IACf,2BAAiB,CAAA;IACjB,uBAAa,CAAA;AACjB,CAAC,EALW,MAAM,sBAAN,MAAM,QAKjB;AAqBD,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,8DAAiD,CAAA;IACjD,4BAAe,CAAA;IACf,8BAAiB,CAAA;AACrB,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.52.
|
|
7
|
+
"version": "1.52.66",
|
|
8
8
|
"description": "Google Business Messages channel for stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
"sinon": "16.1.3",
|
|
29
29
|
"sinon-chai": "3.7.0",
|
|
30
30
|
"stentor-constants": "1.58.79",
|
|
31
|
-
"stentor-guards": "1.58.
|
|
32
|
-
"stentor-interaction-model": "1.58.
|
|
33
|
-
"stentor-locales": "1.58.
|
|
34
|
-
"stentor-logger": "1.58.
|
|
35
|
-
"stentor-media": "1.58.
|
|
31
|
+
"stentor-guards": "1.58.81",
|
|
32
|
+
"stentor-interaction-model": "1.58.81",
|
|
33
|
+
"stentor-locales": "1.58.81",
|
|
34
|
+
"stentor-logger": "1.58.81",
|
|
35
|
+
"stentor-media": "1.58.81",
|
|
36
36
|
"stentor-models": "1.58.79",
|
|
37
|
-
"stentor-request": "1.58.
|
|
38
|
-
"stentor-response": "1.58.
|
|
39
|
-
"stentor-utils": "1.58.
|
|
37
|
+
"stentor-request": "1.58.81",
|
|
38
|
+
"stentor-response": "1.58.81",
|
|
39
|
+
"stentor-utils": "1.58.81",
|
|
40
40
|
"ts-node": "10.9.2",
|
|
41
41
|
"typescript": "5.3.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@xapp/patterns": "2.0.1",
|
|
45
|
-
"@xapp/stentor-app": "1.52.
|
|
45
|
+
"@xapp/stentor-app": "1.52.66",
|
|
46
46
|
"google-auth-library": "8.9.0",
|
|
47
47
|
"googleapis-common": "6.0.4",
|
|
48
48
|
"node-fetch": "2.7.0",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"clean": "rm -rf ./lib/*",
|
|
67
67
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8538bea354dfbb45a44f0b1d9283b5b4e69a1778"
|
|
70
70
|
}
|
package/lib/Guards.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
-
import { UserMessage } from "./models";
|
|
3
|
-
/**
|
|
4
|
-
* This is for the channel selector
|
|
5
|
-
*
|
|
6
|
-
* @param requestBody
|
|
7
|
-
*/
|
|
8
|
-
export declare function isGbmPayload(requestBody: UserMessage): requestBody is UserMessage;
|
|
9
|
-
/**
|
|
10
|
-
* This tells if it's a message for the bot
|
|
11
|
-
* @param requestBody
|
|
12
|
-
*/
|
|
13
|
-
export declare function isGbmMessage(requestBody: UserMessage): requestBody is UserMessage;
|
package/lib/Guards.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isGbmMessage = exports.isGbmPayload = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This is for the channel selector
|
|
6
|
-
*
|
|
7
|
-
* @param requestBody
|
|
8
|
-
*/
|
|
9
|
-
function isGbmPayload(requestBody) {
|
|
10
|
-
return !!requestBody.secret && !!requestBody.clientToken // verification
|
|
11
|
-
|| !!requestBody.agent && !!requestBody.sendTime && !!requestBody.requestId; // message
|
|
12
|
-
}
|
|
13
|
-
exports.isGbmPayload = isGbmPayload;
|
|
14
|
-
/**
|
|
15
|
-
* This tells if it's a message for the bot
|
|
16
|
-
* @param requestBody
|
|
17
|
-
*/
|
|
18
|
-
function isGbmMessage(requestBody) {
|
|
19
|
-
return !!requestBody.message || !!requestBody.suggestionResponse
|
|
20
|
-
|| !!requestBody.userStatus && !!requestBody.userStatus.requestedLiveAgent; // message
|
|
21
|
-
}
|
|
22
|
-
exports.isGbmMessage = isGbmMessage;
|
|
23
|
-
//# sourceMappingURL=Guards.js.map
|
package/lib/Guards.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Guards.js","sourceRoot":"","sources":["../src/Guards.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACH,SAAgB,YAAY,CAAC,WAAwB;IACjD,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,eAAe;WACnE,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,UAAU;AAC7F,CAAC;AAHD,oCAGC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,WAAwB;IACjD,OAAO,CAAC,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,CAAC,WAAW,CAAC,kBAAkB;WAC3D,CAAC,CAAC,WAAW,CAAC,UAAU,IAAI,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,UAAU;AAC5F,CAAC;AAHD,oCAGC"}
|