@xapp/stentor-gbm 1.40.336
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/LICENSE.md +176 -0
- package/README.md +10 -0
- package/lib/Channel.d.ts +11 -0
- package/lib/Channel.js +42 -0
- package/lib/Channel.js.map +1 -0
- package/lib/ChatDataStore.d.ts +28 -0
- package/lib/ChatDataStore.js +56 -0
- package/lib/ChatDataStore.js.map +1 -0
- package/lib/Constants.d.ts +7 -0
- package/lib/Constants.js +8 -0
- package/lib/Constants.js.map +1 -0
- package/lib/GbmHandlerHook.d.ts +7 -0
- package/lib/GbmHandlerHook.js +226 -0
- package/lib/GbmHandlerHook.js.map +1 -0
- package/lib/Guards.d.ts +13 -0
- package/lib/Guards.js +23 -0
- package/lib/Guards.js.map +1 -0
- package/lib/Translators/TranslateRequest/helpers.d.ts +1 -0
- package/lib/Translators/TranslateRequest/helpers.js +2 -0
- package/lib/Translators/TranslateRequest/helpers.js.map +1 -0
- package/lib/Translators/TranslateRequest/index.d.ts +7 -0
- package/lib/Translators/TranslateRequest/index.js +57 -0
- package/lib/Translators/TranslateRequest/index.js.map +1 -0
- package/lib/Translators/TranslateResponse/helpers.d.ts +1 -0
- package/lib/Translators/TranslateResponse/helpers.js +2 -0
- package/lib/Translators/TranslateResponse/helpers.js.map +1 -0
- package/lib/Translators/TranslateResponse/index.d.ts +11 -0
- package/lib/Translators/TranslateResponse/index.js +205 -0
- package/lib/Translators/TranslateResponse/index.js.map +1 -0
- package/lib/Translators/index.d.ts +3 -0
- package/lib/Translators/index.js +20 -0
- package/lib/Translators/index.js.map +1 -0
- package/lib/Types.d.ts +3 -0
- package/lib/Types.js +3 -0
- package/lib/Types.js.map +1 -0
- package/lib/__tests__/Channel.test.d.ts +1 -0
- package/lib/__tests__/Channel.test.js +142 -0
- package/lib/__tests__/Channel.test.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/models/AgentMessage.d.ts +99 -0
- package/lib/models/AgentMessage.js +24 -0
- package/lib/models/AgentMessage.js.map +1 -0
- package/lib/models/UserMessage.d.ts +196 -0
- package/lib/models/UserMessage.js +76 -0
- package/lib/models/UserMessage.js.map +1 -0
- package/lib/models/index.d.ts +3 -0
- package/lib/models/index.js +20 -0
- package/lib/models/index.js.map +1 -0
- package/package.json +68 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
package/lib/Channel.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
+
import { Channel, Device, NLUService } from "stentor-models";
|
|
3
|
+
export interface GbmChannelProps {
|
|
4
|
+
botAvatarName?: string;
|
|
5
|
+
botAvatarImageUrl?: string;
|
|
6
|
+
sessionRegex?: RegExp;
|
|
7
|
+
sessionAgeMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function capabilities(_body: object): Device;
|
|
10
|
+
export declare const GOOGLE_BUSINESS_MESSAGE_CHANNEL: Channel;
|
|
11
|
+
export declare function GoogleBusinessMessages(nlu: NLUService, props?: GbmChannelProps): Channel;
|
package/lib/Channel.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleBusinessMessages = exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = exports.capabilities = void 0;
|
|
4
|
+
const Constants_1 = require("./Constants");
|
|
5
|
+
const Guards_1 = require("./Guards");
|
|
6
|
+
const GbmHandlerHook_1 = require("./GbmHandlerHook");
|
|
7
|
+
const Translators_1 = require("./Translators");
|
|
8
|
+
function capabilities(_body) {
|
|
9
|
+
return {
|
|
10
|
+
channel: Constants_1.GOOGLE_BUSINESS_MESSAGES_PLATFORM,
|
|
11
|
+
audioSupported: false,
|
|
12
|
+
canPlayVideo: false,
|
|
13
|
+
videoSupported: true,
|
|
14
|
+
canPlayAudio: false,
|
|
15
|
+
canSpeak: false,
|
|
16
|
+
canThrowCard: true,
|
|
17
|
+
hasScreen: true,
|
|
18
|
+
canTransferCall: true,
|
|
19
|
+
hasWebBrowser: true
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.capabilities = capabilities;
|
|
23
|
+
exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = {
|
|
24
|
+
name: Constants_1.GOOGLE_BUSINESS_MESSAGES_PLATFORM,
|
|
25
|
+
test: Guards_1.isGbmPayload,
|
|
26
|
+
handlerHook: GbmHandlerHook_1.handlerHook,
|
|
27
|
+
request: new Translators_1.TranslateRequest(),
|
|
28
|
+
response: new Translators_1.TranslateResponse(),
|
|
29
|
+
capabilities
|
|
30
|
+
};
|
|
31
|
+
function GoogleBusinessMessages(nlu, props) {
|
|
32
|
+
const defaultProps = {
|
|
33
|
+
botAvatarName: "XAPPY",
|
|
34
|
+
botAvatarImageUrl: "https://storage.googleapis.com/sample-avatars-for-bm/bot-avatar.jpg",
|
|
35
|
+
sessionAgeMs: -1,
|
|
36
|
+
sessionRegex: new RegExp("^hello$|^Hello$")
|
|
37
|
+
};
|
|
38
|
+
const finalProps = Object.assign(Object.assign({}, defaultProps), props);
|
|
39
|
+
return Object.assign(Object.assign({}, exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL), { response: new Translators_1.TranslateResponse(finalProps), handlerHook: GbmHandlerHook_1.handlerHook.bind({ props: finalProps }), nlu });
|
|
40
|
+
}
|
|
41
|
+
exports.GoogleBusinessMessages = GoogleBusinessMessages;
|
|
42
|
+
//# sourceMappingURL=Channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":";;;AAGA,2CAAgE;AAChE,qCAAwC;AACxC,qDAA+C;AAC/C,+CAAoE;AASpE,SAAgB,YAAY,CAAC,KAAa;IACtC,OAAO;QACH,OAAO,EAAE,6CAAiC;QAC1C,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,KAAK;QACnB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,IAAI;KACtB,CAAC;AACN,CAAC;AAbD,oCAaC;AAEY,QAAA,+BAA+B,GAAY;IACpD,IAAI,EAAE,6CAAiC;IACvC,IAAI,EAAE,qBAAY;IAClB,WAAW,EAAX,4BAAW;IACX,OAAO,EAAE,IAAI,8BAAgB,EAAE;IAC/B,QAAQ,EAAE,IAAI,+BAAiB,EAAE;IACjC,YAAY;CACf,CAAC;AAEF,SAAgB,sBAAsB,CAAC,GAAe,EAAE,KAAuB;IAC3E,MAAM,YAAY,GAAoB;QAClC,aAAa,EAAE,OAAO;QACtB,iBAAiB,EAAE,qEAAqE;QACxF,YAAY,EAAE,CAAC,CAAC;QAChB,YAAY,EAAE,IAAI,MAAM,CAAC,iBAAiB,CAAC;KAC9C,CAAA;IAED,MAAM,UAAU,mCAAQ,YAAY,GAAK,KAAK,CAAC,CAAC;IAEhD,uCACO,uCAA+B,KAClC,QAAQ,EAAE,IAAI,+BAAiB,CAAC,UAAU,CAAC,EAC3C,WAAW,EAAE,4BAAW,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,UAAU,EAAC,CAAC,EAClD,GAAG,IACL;AACN,CAAC;AAhBD,wDAgBC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
+
import { UserStorageService } from "stentor-models";
|
|
3
|
+
export interface ChatDataCache {
|
|
4
|
+
[token: string]: ChatData;
|
|
5
|
+
}
|
|
6
|
+
export interface ChatData {
|
|
7
|
+
visitorInfo: VisitorInfo;
|
|
8
|
+
chatInfo: ChatInfo;
|
|
9
|
+
}
|
|
10
|
+
export interface VisitorInfo {
|
|
11
|
+
displayName: string;
|
|
12
|
+
visitorId: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ChatInfo {
|
|
16
|
+
userId: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
handOff?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class ChatDataStore {
|
|
21
|
+
private readonly chatDataCache;
|
|
22
|
+
private readonly userStorageService;
|
|
23
|
+
constructor(userStorageService: UserStorageService);
|
|
24
|
+
get(id: string): Promise<ChatData>;
|
|
25
|
+
set(id: string, chatData: ChatData): Promise<void>;
|
|
26
|
+
flush(): Promise<void>;
|
|
27
|
+
delete(id: string): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ChatDataStore = void 0;
|
|
14
|
+
class ChatDataStore {
|
|
15
|
+
constructor(userStorageService) {
|
|
16
|
+
this.userStorageService = userStorageService;
|
|
17
|
+
this.chatDataCache = {};
|
|
18
|
+
}
|
|
19
|
+
get(id) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
let chatData = this.chatDataCache[id];
|
|
23
|
+
if (!chatData) {
|
|
24
|
+
const storage = yield this.userStorageService.get(id);
|
|
25
|
+
chatData = (_b = (_a = storage === null || storage === void 0 ? void 0 : storage.sessionStore) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ChatData;
|
|
26
|
+
if (chatData) {
|
|
27
|
+
this.chatDataCache[id] = chatData;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return chatData;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
set(id, chatData) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
this.chatDataCache[id] = chatData;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
flush() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
for (const id of Object.keys(this.chatDataCache)) {
|
|
41
|
+
const storage = yield this.userStorageService.get(id);
|
|
42
|
+
if (storage === null || storage === void 0 ? void 0 : storage.sessionStore) {
|
|
43
|
+
storage.sessionStore.data.ChatData = this.chatDataCache[id];
|
|
44
|
+
}
|
|
45
|
+
yield this.userStorageService.update(id, storage);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
delete(id) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
delete this.chatDataCache[id];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ChatDataStore = ChatDataStore;
|
|
56
|
+
//# sourceMappingURL=ChatDataStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatDataStore.js","sourceRoot":"","sources":["../src/ChatDataStore.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;AAyBpC,MAAa,aAAa;IAItB,YAAY,kBAAsC;QAC9C,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC5B,CAAC;IAEY,GAAG,CAAC,EAAU;;;YACvB,IAAI,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,QAAQ,EAAE;gBACX,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACtD,QAAQ,GAAG,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,0CAAE,IAAI,0CAAE,QAAQ,CAAC;gBACjD,IAAI,QAAQ,EAAE;oBACV,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;iBACrC;aACJ;YACD,OAAO,QAAQ,CAAC;;KACnB;IAEY,GAAG,CAAC,EAAU,EAAE,QAAkB;;YAC3C,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;QACtC,CAAC;KAAA;IAEY,KAAK;;YACd,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;gBAC9C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACtD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,EAAE;oBACvB,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;iBAC/D;gBACD,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;aACrD;QACL,CAAC;KAAA;IAEY,MAAM,CAAC,EAAU;;YAC1B,OAAO,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAClC,CAAC;KAAA;CACJ;AAtCD,sCAsCC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
+
import { GbmChannel, GbmPlatform } from "./Types";
|
|
3
|
+
export declare const GOOGLE_BUSINESS_MESSAGES_PLATFORM: GbmPlatform;
|
|
4
|
+
export declare const GOOGLE_BUSINESS_MESSAGES_CHANNEL: GbmChannel;
|
|
5
|
+
export declare const INTENT_TRANSLATION: {
|
|
6
|
+
[intent: string]: string;
|
|
7
|
+
};
|
package/lib/Constants.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.INTENT_TRANSLATION = exports.GOOGLE_BUSINESS_MESSAGES_CHANNEL = exports.GOOGLE_BUSINESS_MESSAGES_PLATFORM = void 0;
|
|
5
|
+
exports.GOOGLE_BUSINESS_MESSAGES_PLATFORM = "google-business-messages-platform";
|
|
6
|
+
exports.GOOGLE_BUSINESS_MESSAGES_CHANNEL = "google-business-messages";
|
|
7
|
+
exports.INTENT_TRANSLATION = {};
|
|
8
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAIvB,QAAA,iCAAiC,GAAgB,mCAAmC,CAAC;AACrF,QAAA,gCAAgC,GAAe,0BAA0B,CAAC;AAE1E,QAAA,kBAAkB,GAAiC,EAC/D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RuntimeContext, UserStorageService } from "stentor-models";
|
|
2
|
+
import { UserMessage } from "./models";
|
|
3
|
+
import { Callback } from "aws-lambda";
|
|
4
|
+
export declare function handlerHook(handler: (event: UserMessage, context: RuntimeContext, callback: Callback) => Promise<void>, event: any, context: RuntimeContext, callback: Callback, services: {
|
|
5
|
+
userStorageService?: UserStorageService;
|
|
6
|
+
appService?: any;
|
|
7
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.handlerHook = void 0;
|
|
13
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
14
|
+
const stentor_constants_1 = require("stentor-constants");
|
|
15
|
+
const stentor_logger_1 = require("stentor-logger");
|
|
16
|
+
const Guards_1 = require("./Guards");
|
|
17
|
+
const uuid_1 = require("uuid");
|
|
18
|
+
const ChatDataStore_1 = require("./ChatDataStore");
|
|
19
|
+
const { google } = require("googleapis");
|
|
20
|
+
const businessmessages = require("businessmessages");
|
|
21
|
+
const bmApi = new businessmessages.businessmessages_v1.Businessmessages({});
|
|
22
|
+
function handlerHook(handler, event, context, callback, services) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
// Safety wrapper
|
|
25
|
+
yield _handlerHook(handler, event, context, callback, services, this.props).catch(reason => {
|
|
26
|
+
(0, stentor_logger_1.log)().error(`GBM main processing hook failed: ${reason}`);
|
|
27
|
+
let finalResponse = { error: reason };
|
|
28
|
+
if (context.buildResponse) {
|
|
29
|
+
finalResponse = context.buildResponse(stentor_constants_1.HTTP_500_INTERNAL_SERVICE_ERROR, { error: reason });
|
|
30
|
+
}
|
|
31
|
+
// tslint:disable-next-line:no-null-keyword
|
|
32
|
+
callback(null, finalResponse);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.handlerHook = handlerHook;
|
|
37
|
+
function _handlerHook(handler, event, context, callback, _services, props) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const chatDataStore = new ChatDataStore_1.ChatDataStore(_services.userStorageService);
|
|
41
|
+
// Webhook verification call
|
|
42
|
+
if (event.secret && event.clientToken) {
|
|
43
|
+
let finalResponse = event.secret;
|
|
44
|
+
if (context.buildResponse) {
|
|
45
|
+
finalResponse = context.buildResponse(stentor_constants_1.HTTP_200_OK, finalResponse);
|
|
46
|
+
}
|
|
47
|
+
// tslint:disable-next-line:no-null-keyword
|
|
48
|
+
callback(null, finalResponse);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const botResponses = [];
|
|
52
|
+
const hookCallback = (error, result) => {
|
|
53
|
+
botResponses.push({ error, result });
|
|
54
|
+
};
|
|
55
|
+
// Check the webhook payload
|
|
56
|
+
if ((0, Guards_1.isGbmPayload)(event)) {
|
|
57
|
+
if (event.userStatus) {
|
|
58
|
+
(0, stentor_logger_1.log)().debug(`GBM user status: ${event.conversationId} - ${JSON.stringify(event.userStatus)}`);
|
|
59
|
+
}
|
|
60
|
+
else if (event.receipts) {
|
|
61
|
+
(0, stentor_logger_1.log)().debug(`GBM user receipts: ${event.conversationId} - ${JSON.stringify(event.receipts)}`);
|
|
62
|
+
}
|
|
63
|
+
else if ((0, Guards_1.isGbmMessage)(event)) {
|
|
64
|
+
(0, stentor_logger_1.log)().info(`GBM: user message: ${JSON.stringify(event)}`);
|
|
65
|
+
const userId = event.conversationId;
|
|
66
|
+
let isNewSession = false;
|
|
67
|
+
// Session "management" stuff
|
|
68
|
+
let chatData = yield chatDataStore.get(userId);
|
|
69
|
+
if (!chatData) {
|
|
70
|
+
// Add a messenger visitor (user)
|
|
71
|
+
const visitorInfo = {
|
|
72
|
+
displayName: event.context.userInfo.displayName,
|
|
73
|
+
visitorId: userId
|
|
74
|
+
};
|
|
75
|
+
const chatInfo = {
|
|
76
|
+
handOff: false,
|
|
77
|
+
userId,
|
|
78
|
+
sessionId: generateSessionId()
|
|
79
|
+
};
|
|
80
|
+
chatData = {
|
|
81
|
+
visitorInfo,
|
|
82
|
+
chatInfo
|
|
83
|
+
};
|
|
84
|
+
yield chatDataStore.set(userId, chatData);
|
|
85
|
+
isNewSession = true;
|
|
86
|
+
(0, stentor_logger_1.log)().info(`GBM: new session: ${chatInfo.sessionId}`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Force restart session with "safe word" (or session age)?
|
|
90
|
+
if (props.sessionRegex) {
|
|
91
|
+
const rawQuery = (_a = event.message) === null || _a === void 0 ? void 0 : _a.text; // could be postback. we only watch text.
|
|
92
|
+
if (rawQuery && props.sessionRegex.test(rawQuery)) {
|
|
93
|
+
chatData.chatInfo.sessionId = generateSessionId();
|
|
94
|
+
chatData.chatInfo.handOff = false;
|
|
95
|
+
yield chatDataStore.set(userId, chatData);
|
|
96
|
+
isNewSession = true;
|
|
97
|
+
(0, stentor_logger_1.log)().info(`GBM: session was reset. safe word: ${rawQuery}, sessionId: ${chatData.chatInfo.sessionId}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (props.sessionAgeMs) {
|
|
101
|
+
// TODO
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Add the "synthetic" payload
|
|
105
|
+
event._chat = {
|
|
106
|
+
userId,
|
|
107
|
+
sessionId: chatData.chatInfo.sessionId,
|
|
108
|
+
isNewSession
|
|
109
|
+
};
|
|
110
|
+
// Send the event to the bot
|
|
111
|
+
yield handler(event, context, hookCallback);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
(0, stentor_logger_1.log)().error(`GBM: sent something we don't expect. Check payload: ${JSON.stringify(event, null, 2)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
(0, stentor_logger_1.log)().error(`GBM: (?) to Bot (full payload) was ignored: ${JSON.stringify(event, null, 2)}`);
|
|
119
|
+
}
|
|
120
|
+
// We should have all the responses here (the callback hopefully collected them)
|
|
121
|
+
for (const botResponse of botResponses) {
|
|
122
|
+
const conversationId = event.conversationId;
|
|
123
|
+
if (!botResponse.error) {
|
|
124
|
+
let messageObject;
|
|
125
|
+
if ((_b = botResponse.result) === null || _b === void 0 ? void 0 : _b.body) {
|
|
126
|
+
try {
|
|
127
|
+
messageObject = JSON.parse(botResponse.result.body); // lambda
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
(0, stentor_logger_1.log)().error(`GBM: bad response body: ${botResponse.result.body}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
messageObject = botResponse.result; // express
|
|
135
|
+
}
|
|
136
|
+
yield sendResponse(messageObject, conversationId).catch((reason) => {
|
|
137
|
+
(0, stentor_logger_1.log)().error(`GBM: response POST failed: ${reason}`);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// flush chatDataStore
|
|
142
|
+
if (botResponses.length > 0) {
|
|
143
|
+
yield chatDataStore.flush();
|
|
144
|
+
}
|
|
145
|
+
// We just acknowledge the receipt
|
|
146
|
+
let finalResponse = { status: "OK" }; // I just made this up. Only the status matters.
|
|
147
|
+
if (context.buildResponse) {
|
|
148
|
+
finalResponse = context.buildResponse(stentor_constants_1.HTTP_200_OK, finalResponse);
|
|
149
|
+
}
|
|
150
|
+
// tslint:disable-next-line:no-null-keyword
|
|
151
|
+
callback(null, finalResponse);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function sendResponse(messageObject, conversationId) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
if (!messageObject) {
|
|
157
|
+
(0, stentor_logger_1.log)().error("GBM: send was called with empty message!");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
(0, stentor_logger_1.log)().info(`GBM: sending message: ${JSON.stringify(messageObject)}`);
|
|
161
|
+
if (!messageObject.messageId) {
|
|
162
|
+
(0, stentor_logger_1.log)().error("GBM: send was called with no message id!");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const authClient = yield initCredentials();
|
|
166
|
+
// Create the payload for sending a typing started event
|
|
167
|
+
const apiEventParams = {
|
|
168
|
+
auth: authClient,
|
|
169
|
+
parent: 'conversations/' + conversationId,
|
|
170
|
+
resource: {
|
|
171
|
+
eventType: 'TYPING_STARTED',
|
|
172
|
+
representative: messageObject.representative,
|
|
173
|
+
},
|
|
174
|
+
eventId: (0, uuid_1.v4)(),
|
|
175
|
+
};
|
|
176
|
+
// Send the typing started event
|
|
177
|
+
bmApi.conversations.events.create(apiEventParams, { auth: authClient }, (err, response) => {
|
|
178
|
+
if (err) {
|
|
179
|
+
(0, stentor_logger_1.log)().error(err);
|
|
180
|
+
}
|
|
181
|
+
const apiParams = {
|
|
182
|
+
auth: authClient,
|
|
183
|
+
parent: 'conversations/' + conversationId,
|
|
184
|
+
resource: messageObject,
|
|
185
|
+
};
|
|
186
|
+
// Call the message create function using the Business Messages client library
|
|
187
|
+
bmApi.conversations.messages.create(apiParams, { auth: authClient }, (err, response) => {
|
|
188
|
+
if (err) {
|
|
189
|
+
(0, stentor_logger_1.log)().error(err);
|
|
190
|
+
}
|
|
191
|
+
// Update the event parameters
|
|
192
|
+
apiEventParams.resource.eventType = 'TYPING_STOPPED';
|
|
193
|
+
apiEventParams.eventId = (0, uuid_1.v4)();
|
|
194
|
+
// Send the typing stopped event
|
|
195
|
+
bmApi.conversations.events.create(apiEventParams, { auth: authClient }, (err, response) => {
|
|
196
|
+
if (err) {
|
|
197
|
+
(0, stentor_logger_1.log)().error(err);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Initializes the Google credentials for calling the
|
|
206
|
+
* Business Messages API.
|
|
207
|
+
*/
|
|
208
|
+
function initCredentials() {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const authClient = new google.auth.JWT(process.env.GOOGLE_BUSINESS_MESSAGES_EMAIL, null, process.env.GOOGLE_BUSINESS_MESSAGES_SECRET, ['https://www.googleapis.com/auth/businessmessages']);
|
|
211
|
+
return new Promise(function (resolve, reject) {
|
|
212
|
+
authClient.authorize(function (err, tokens) {
|
|
213
|
+
if (err) {
|
|
214
|
+
reject(false);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
resolve(authClient);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function generateSessionId() {
|
|
224
|
+
return `gbm-session-${(0, uuid_1.v4)()}`;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=GbmHandlerHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbmHandlerHook.js","sourceRoot":"","sources":["../src/GbmHandlerHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAAiF;AAEjF,mDAAqC;AAErC,qCAAsD;AAGtD,+BAAoC;AAEpC,mDAAuE;AAGvE,MAAM,EAAC,MAAM,EAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACvC,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACrD,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAE5E,SAAsB,WAAW,CAAC,OAA2F,EAC3F,KAAU,EAAE,OAAuB,EAAE,QAAkB,EACvD,QAAuE;;QACvG,iBAAiB;QACjB,MAAM,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACzF,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,oCAAoC,MAAM,EAAE,CAAC,CAAC;YAE1D,IAAI,aAAa,GAAW,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;YAC5C,IAAI,OAAO,CAAC,aAAa,EAAE;gBACzB,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,mDAA+B,EAAE,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC,CAAC;aACzF;YAED,2CAA2C;YAC3C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;CAAA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AAM,UAAU,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CACpC,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAC1C,IAAI,EACJ,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAC3C,CAAC,kDAAkD,CAAC,CACrD,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;YAC1C,UAAU,CAAC,SAAS,CAAC,UAAU,GAAQ,EAAE,MAAW;gBAClD,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,KAAK,CAAC,CAAC;iBACf;qBAAM;oBACL,OAAO,CAAC,UAAU,CAAC,CAAC;iBACrB;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AAED,SAAS,iBAAiB;IACxB,OAAO,eAAe,IAAA,SAAM,GAAE,EAAE,CAAC;AACnC,CAAC"}
|
package/lib/Guards.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|