@xapp/stentor-gbm 1.45.32 → 1.45.37
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 +29 -0
- package/lib/ApiPoster.js +138 -0
- package/lib/ApiPoster.js.map +1 -0
- package/lib/ChatDataStore.d.ts +1 -0
- package/lib/ChatDataStore.js.map +1 -1
- package/lib/GbmHandlerHook.d.ts +0 -1
- package/lib/GbmHandlerHook.js +85 -97
- package/lib/GbmHandlerHook.js.map +1 -1
- package/lib/Translators/TranslateResponse/index.d.ts +2 -2
- package/lib/Translators/TranslateResponse/index.js +65 -58
- package/lib/Translators/TranslateResponse/index.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/models/AgentMessage.d.ts +1 -3
- package/lib/models/AgentMessage.js +0 -1
- package/lib/models/AgentMessage.js.map +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
|
+
import { AgentMessage, Representative } from "./models";
|
|
3
|
+
export declare enum GmbEventType {
|
|
4
|
+
EVENT_TYPE_UNSPECIFIED = "EVENT_TYPE_UNSPECIFIED",
|
|
5
|
+
TYPING_STARTED = "TYPING_STARTED",
|
|
6
|
+
TYPING_STOPPED = "TYPING_STOPPED",
|
|
7
|
+
REPRESENTATIVE_JOINED = "REPRESENTATIVE_JOINED",
|
|
8
|
+
REPRESENTATIVE_LEFT = "REPRESENTATIVE_LEFT"
|
|
9
|
+
}
|
|
10
|
+
export declare enum GmbReceiptType {
|
|
11
|
+
RECEIPT_TYPE_UNSPECIFIED = "RECEIPT_TYPE_UNSPECIFIED",
|
|
12
|
+
READ = "READ"
|
|
13
|
+
}
|
|
14
|
+
export interface AgentEvent {
|
|
15
|
+
eventType: GmbEventType;
|
|
16
|
+
representative: Representative;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentReceipt {
|
|
19
|
+
receiptType: GmbReceiptType;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatPostResult {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
error?: "TIMEOUT" | "UNKNOWN_ERROR";
|
|
24
|
+
message?: string;
|
|
25
|
+
response?: any;
|
|
26
|
+
}
|
|
27
|
+
export declare function sendGbmMessage(messageObject: AgentMessage, connectionUrl: string, conversationId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
|
28
|
+
export declare function sendGbmEvent(messageObject: AgentEvent, connectionUrl: string, conversationId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
|
29
|
+
export declare function sendGbmAck(messageObject: AgentReceipt, connectionUrl: string, conversationId: string, messageId: string, timeoutMs?: number): Promise<ChatPostResult>;
|
package/lib/ApiPoster.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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.sendGbmAck = exports.sendGbmEvent = exports.sendGbmMessage = exports.GmbReceiptType = exports.GmbEventType = void 0;
|
|
14
|
+
const node_fetch_1 = require("node-fetch");
|
|
15
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
16
|
+
const stentor_utils_1 = require("stentor-utils");
|
|
17
|
+
const stentor_logger_1 = require("stentor-logger");
|
|
18
|
+
const GBM_DEFAULT_TIMEOUT_MS = 3000;
|
|
19
|
+
const GBM_CLIENT_SCOPE = "https://www.googleapis.com/auth/businessmessages";
|
|
20
|
+
const GBM_TOKEN_AGE_MS = 60 * 60 * 1000;
|
|
21
|
+
var GmbEventType;
|
|
22
|
+
(function (GmbEventType) {
|
|
23
|
+
GmbEventType["EVENT_TYPE_UNSPECIFIED"] = "EVENT_TYPE_UNSPECIFIED";
|
|
24
|
+
GmbEventType["TYPING_STARTED"] = "TYPING_STARTED";
|
|
25
|
+
GmbEventType["TYPING_STOPPED"] = "TYPING_STOPPED";
|
|
26
|
+
GmbEventType["REPRESENTATIVE_JOINED"] = "REPRESENTATIVE_JOINED";
|
|
27
|
+
GmbEventType["REPRESENTATIVE_LEFT"] = "REPRESENTATIVE_LEFT";
|
|
28
|
+
})(GmbEventType = exports.GmbEventType || (exports.GmbEventType = {}));
|
|
29
|
+
var GmbReceiptType;
|
|
30
|
+
(function (GmbReceiptType) {
|
|
31
|
+
GmbReceiptType["RECEIPT_TYPE_UNSPECIFIED"] = "RECEIPT_TYPE_UNSPECIFIED";
|
|
32
|
+
GmbReceiptType["READ"] = "READ";
|
|
33
|
+
})(GmbReceiptType = exports.GmbReceiptType || (exports.GmbReceiptType = {}));
|
|
34
|
+
let gbmAuthToken;
|
|
35
|
+
let gbmAuthTokenCreateTimeMs;
|
|
36
|
+
function sendGbmMessage(messageObject, connectionUrl, conversationId, timeoutMs) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (!messageObject.messageId) {
|
|
39
|
+
throw new Error(`GBM: message send was called with no message id. Conversation id: ${conversationId}`);
|
|
40
|
+
}
|
|
41
|
+
const url = `${connectionUrl}/conversations/${conversationId}/messages`;
|
|
42
|
+
const payload = JSON.stringify(messageObject);
|
|
43
|
+
(0, stentor_logger_1.log)().info(`GBM: agent message: conversation id: ${conversationId} Message: ${payload}`);
|
|
44
|
+
return _post(url, "POST", payload, conversationId, timeoutMs);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.sendGbmMessage = sendGbmMessage;
|
|
48
|
+
function sendGbmEvent(messageObject, connectionUrl, conversationId, timeoutMs) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!messageObject.eventType) {
|
|
51
|
+
throw new Error(`GBM: event send was called with no event Type. Conversation id: ${conversationId}`);
|
|
52
|
+
}
|
|
53
|
+
const url = `${connectionUrl}/conversations/${conversationId}/events?eventId=${(0, stentor_utils_1.uuid)()}`;
|
|
54
|
+
const payload = JSON.stringify(messageObject);
|
|
55
|
+
(0, stentor_logger_1.log)().info(`GBM: event post. Conversation id: ${conversationId} Message: ${payload}`);
|
|
56
|
+
return _post(url, "POST", payload, conversationId, timeoutMs);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.sendGbmEvent = sendGbmEvent;
|
|
60
|
+
function sendGbmAck(messageObject, connectionUrl, conversationId, messageId, timeoutMs) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (!messageObject.receiptType) {
|
|
63
|
+
throw new Error(`GBM: receipt send was called with no receipt Type. Conversation id: ${conversationId} Message id: ${messageId}`);
|
|
64
|
+
}
|
|
65
|
+
const url = `${connectionUrl}/conversations/${conversationId}/messages/${messageId}/receipt`;
|
|
66
|
+
const payload = JSON.stringify(messageObject);
|
|
67
|
+
(0, stentor_logger_1.log)().info(`GBM: receipt post. Conversation id: ${conversationId} Message: ${payload} Message id: ${messageId}`);
|
|
68
|
+
return _post(url, "PATCH", payload, conversationId, timeoutMs);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.sendGbmAck = sendGbmAck;
|
|
72
|
+
function _post(url, method, payload, conversationId, timeoutMs) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const authToken = yield initCredentials();
|
|
75
|
+
let response;
|
|
76
|
+
try {
|
|
77
|
+
response = yield (0, node_fetch_1.default)(url, {
|
|
78
|
+
method: method,
|
|
79
|
+
headers: {
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
Authorization: `Bearer ${authToken}`,
|
|
82
|
+
"User-Agent": "Stentor Chat Server",
|
|
83
|
+
},
|
|
84
|
+
body: payload,
|
|
85
|
+
timeout: timeoutMs || GBM_DEFAULT_TIMEOUT_MS,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
(0, stentor_logger_1.log)().error(`GBM: post failed (exception). HTTP ${method} Conversation id: ${conversationId} Full Payload: ${payload}`);
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: err.type === "request-timeout" ? "TIMEOUT" : "UNKNOWN_ERROR",
|
|
93
|
+
message: err.message,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
(0, stentor_logger_1.log)().error(`GBM: post failed (error). Conversation id: ${conversationId} Full Payload: ${payload}`);
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
error: "UNKNOWN_ERROR",
|
|
101
|
+
message: `GBM: post failed: status ${response.status}, text: ${response.statusText}`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { ok: true, response: yield response.json() };
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function initCredentials() {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const email = process.env.GOOGLE_BUSINESS_MESSAGES_EMAIL;
|
|
110
|
+
const key = process.env.GOOGLE_BUSINESS_MESSAGES_SECRET;
|
|
111
|
+
if (!email || !key) {
|
|
112
|
+
throw new Error(`GMB: Environment variables GOOGLE_BUSINESS_MESSAGES_[EMAIL|SECRET] are required`);
|
|
113
|
+
}
|
|
114
|
+
const now = new Date().getTime();
|
|
115
|
+
// Cached?
|
|
116
|
+
if (gbmAuthToken) {
|
|
117
|
+
const ageMs = now - gbmAuthTokenCreateTimeMs;
|
|
118
|
+
if (ageMs < GBM_TOKEN_AGE_MS) {
|
|
119
|
+
return gbmAuthToken;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
(0, stentor_logger_1.log)().info("GBM: Creating auth token");
|
|
123
|
+
const authClient = new google_auth_library_1.JWT(email, null, key.replace(/\\n/g, "\n"), [GBM_CLIENT_SCOPE]);
|
|
124
|
+
return new Promise(function (resolve, reject) {
|
|
125
|
+
authClient.authorize(function (err, tokens) {
|
|
126
|
+
if (err) {
|
|
127
|
+
reject(err);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
gbmAuthToken = authClient.credentials.access_token;
|
|
131
|
+
gbmAuthTokenCreateTimeMs = now;
|
|
132
|
+
resolve(authClient.credentials.access_token);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=ApiPoster.js.map
|
|
@@ -0,0 +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,GAAZ,oBAAY,KAAZ,oBAAY,QAMvB;AAED,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,uEAAqD,CAAA;IACrD,+BAAa,CAAA;AACjB,CAAC,EAH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AS,CAAC,UAAU,GAAQ,EAAE,MAAW;gBAChD,IAAI,GAAG,EAAE;oBACL,MAAM,CAAC,GAAG,CAAC,CAAC;iBACf;qBAAM;oBACH,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,YAAY,CAAC;oBACnD,wBAAwB,GAAG,GAAG,CAAC;oBAC/B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;iBAChD;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CAAA"}
|
package/lib/ChatDataStore.d.ts
CHANGED
package/lib/ChatDataStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatDataStore.js","sourceRoot":"","sources":["../src/ChatDataStore.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ChatDataStore.js","sourceRoot":"","sources":["../src/ChatDataStore.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;AA0BpC,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"}
|
package/lib/GbmHandlerHook.d.ts
CHANGED
package/lib/GbmHandlerHook.js
CHANGED
|
@@ -9,21 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
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
16
|
const Guards_1 = require("./Guards");
|
|
17
|
+
const models_1 = require("./models");
|
|
17
18
|
const uuid_1 = require("uuid");
|
|
18
19
|
const ChatDataStore_1 = require("./ChatDataStore");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const ApiPoster_1 = require("./ApiPoster");
|
|
21
|
+
const delay = (waitTimeInMs) => new Promise((resolve) => {
|
|
22
|
+
(0, stentor_logger_1.log)().info(`GBM: waiting for ${waitTimeInMs} ms...`);
|
|
23
|
+
setTimeout(resolve, waitTimeInMs);
|
|
24
|
+
});
|
|
25
|
+
const GMB_API_URL = "https://businessmessages.googleapis.com/v1";
|
|
22
26
|
function handlerHook(handler, event, context, callback, services) {
|
|
23
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
28
|
// 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}`);
|
|
29
|
+
yield _handlerHook(handler, event, context, callback, services, this.props).catch((reason) => {
|
|
30
|
+
(0, stentor_logger_1.log)().error(`GBM main processing hook failed: ${reason} ${reason.stack}`);
|
|
27
31
|
let finalResponse = { error: reason };
|
|
28
32
|
if (context.buildResponse) {
|
|
29
33
|
finalResponse = context.buildResponse(stentor_constants_1.HTTP_500_INTERNAL_SERVICE_ERROR, { error: reason });
|
|
@@ -35,7 +39,7 @@ function handlerHook(handler, event, context, callback, services) {
|
|
|
35
39
|
}
|
|
36
40
|
exports.handlerHook = handlerHook;
|
|
37
41
|
function _handlerHook(handler, event, context, callback, _services, props) {
|
|
38
|
-
var _a, _b;
|
|
42
|
+
var _a, _b, _c;
|
|
39
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
44
|
const chatDataStore = new ChatDataStore_1.ChatDataStore(_services.userStorageService);
|
|
41
45
|
// Webhook verification call
|
|
@@ -54,6 +58,7 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
54
58
|
};
|
|
55
59
|
// Check the webhook payload
|
|
56
60
|
if ((0, Guards_1.isGbmPayload)(event)) {
|
|
61
|
+
const conversationId = event.conversationId;
|
|
57
62
|
if (event.userStatus) {
|
|
58
63
|
(0, stentor_logger_1.log)().debug(`GBM user status: ${event.conversationId} - ${JSON.stringify(event.userStatus)}`);
|
|
59
64
|
}
|
|
@@ -62,7 +67,8 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
62
67
|
}
|
|
63
68
|
else if ((0, Guards_1.isGbmMessage)(event)) {
|
|
64
69
|
(0, stentor_logger_1.log)().info(`GBM: user message: ${JSON.stringify(event)}`);
|
|
65
|
-
const
|
|
70
|
+
const messageId = (_a = event.message) === null || _a === void 0 ? void 0 : _a.messageId;
|
|
71
|
+
const userId = conversationId;
|
|
66
72
|
let isNewSession = false;
|
|
67
73
|
// Session "management" stuff
|
|
68
74
|
let chatData = yield chatDataStore.get(userId);
|
|
@@ -70,25 +76,43 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
70
76
|
// Add a messenger visitor (user)
|
|
71
77
|
const visitorInfo = {
|
|
72
78
|
displayName: event.context.userInfo.displayName,
|
|
73
|
-
visitorId: userId
|
|
79
|
+
visitorId: userId,
|
|
74
80
|
};
|
|
75
81
|
const chatInfo = {
|
|
76
82
|
handOff: false,
|
|
77
83
|
userId,
|
|
78
|
-
sessionId: generateSessionId()
|
|
84
|
+
sessionId: generateSessionId(),
|
|
85
|
+
messageIdsSent: [],
|
|
79
86
|
};
|
|
80
87
|
chatData = {
|
|
81
88
|
visitorInfo,
|
|
82
|
-
chatInfo
|
|
89
|
+
chatInfo,
|
|
83
90
|
};
|
|
84
91
|
yield chatDataStore.set(userId, chatData);
|
|
85
92
|
isNewSession = true;
|
|
86
93
|
(0, stentor_logger_1.log)().info(`GBM: new session: ${chatInfo.sessionId}`);
|
|
87
94
|
}
|
|
88
95
|
else {
|
|
96
|
+
if (messageId) {
|
|
97
|
+
if (!chatData.chatInfo.messageIdsSent) {
|
|
98
|
+
chatData.chatInfo.messageIdsSent = [];
|
|
99
|
+
}
|
|
100
|
+
if (chatData.chatInfo.messageIdsSent.indexOf(messageId) !== -1) {
|
|
101
|
+
(0, stentor_logger_1.log)().info(`GMB: Found duplicate message (ignored). Conversation id: ${conversationId} Message id: ${messageId}`);
|
|
102
|
+
let finalResponse = { status: "OK" };
|
|
103
|
+
if (context.buildResponse) {
|
|
104
|
+
finalResponse = context.buildResponse(stentor_constants_1.HTTP_200_OK, finalResponse);
|
|
105
|
+
}
|
|
106
|
+
// tslint:disable-next-line:no-null-keyword
|
|
107
|
+
callback(null, finalResponse);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
chatData.chatInfo.messageIdsSent.push(messageId);
|
|
111
|
+
yield chatDataStore.flush();
|
|
112
|
+
}
|
|
89
113
|
// Force restart session with "safe word" (or session age)?
|
|
90
114
|
if (props.sessionRegex) {
|
|
91
|
-
const rawQuery = (
|
|
115
|
+
const rawQuery = (_b = event.message) === null || _b === void 0 ? void 0 : _b.text; // could be postback. we only watch text.
|
|
92
116
|
if (rawQuery && props.sessionRegex.test(rawQuery)) {
|
|
93
117
|
chatData.chatInfo.sessionId = generateSessionId();
|
|
94
118
|
chatData.chatInfo.handOff = false;
|
|
@@ -105,10 +129,33 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
105
129
|
event._chat = {
|
|
106
130
|
userId,
|
|
107
131
|
sessionId: chatData.chatInfo.sessionId,
|
|
108
|
-
isNewSession
|
|
132
|
+
isNewSession,
|
|
109
133
|
};
|
|
134
|
+
// Ack the message - looks good in the widget
|
|
135
|
+
const resultReceipt = yield (0, ApiPoster_1.sendGbmAck)({ receiptType: ApiPoster_1.GmbReceiptType.READ }, GMB_API_URL, event.conversationId, messageId);
|
|
136
|
+
if (!resultReceipt.ok) {
|
|
137
|
+
(0, stentor_logger_1.log)().error(`GMB: Posting receipt failed. Error: ${resultReceipt.error}) Message: ${resultReceipt.message || ""}`);
|
|
138
|
+
}
|
|
139
|
+
// Who is typing
|
|
140
|
+
const representative = {
|
|
141
|
+
avatarImage: props.botAvatarImageUrl,
|
|
142
|
+
displayName: props.botAvatarName,
|
|
143
|
+
representativeType: models_1.RepresentativeType.BOT,
|
|
144
|
+
};
|
|
145
|
+
// Typing starts
|
|
146
|
+
const resultTypingStarted = yield (0, ApiPoster_1.sendGbmEvent)({ eventType: ApiPoster_1.GmbEventType.TYPING_STARTED, representative }, GMB_API_URL, conversationId);
|
|
147
|
+
if (!resultTypingStarted.ok) {
|
|
148
|
+
(0, stentor_logger_1.log)().error(resultTypingStarted.message ||
|
|
149
|
+
`GMB: Event post (typing on) failed (${resultTypingStarted.error}): ${resultTypingStarted.message || ""}`);
|
|
150
|
+
}
|
|
110
151
|
// Send the event to the bot
|
|
111
152
|
yield handler(event, context, hookCallback);
|
|
153
|
+
// Typing ends
|
|
154
|
+
const resultTypingStopped = yield (0, ApiPoster_1.sendGbmEvent)({ eventType: ApiPoster_1.GmbEventType.TYPING_STOPPED, representative }, GMB_API_URL, conversationId);
|
|
155
|
+
if (!resultTypingStopped.ok) {
|
|
156
|
+
(0, stentor_logger_1.log)().error(resultTypingStopped.message ||
|
|
157
|
+
`GMB: Event post (typing off) failed (${resultTypingStopped.error}): ${resultTypingStopped.message || ""}`);
|
|
158
|
+
}
|
|
112
159
|
}
|
|
113
160
|
else {
|
|
114
161
|
(0, stentor_logger_1.log)().error(`GBM: sent something we don't expect. Check payload: ${JSON.stringify(event, null, 2)}`);
|
|
@@ -122,7 +169,7 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
122
169
|
const conversationId = event.conversationId;
|
|
123
170
|
if (!botResponse.error) {
|
|
124
171
|
let messageObject;
|
|
125
|
-
if ((
|
|
172
|
+
if ((_c = botResponse.result) === null || _c === void 0 ? void 0 : _c.body) {
|
|
126
173
|
try {
|
|
127
174
|
messageObject = JSON.parse(botResponse.result.body); // lambda
|
|
128
175
|
}
|
|
@@ -133,9 +180,30 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
133
180
|
else {
|
|
134
181
|
messageObject = botResponse.result; // express
|
|
135
182
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
183
|
+
// It maybe more then one - for example we need to send text/chips separately from list/card
|
|
184
|
+
let i = 1;
|
|
185
|
+
if (Array.isArray(messageObject)) {
|
|
186
|
+
for (const gbmMessage of messageObject) {
|
|
187
|
+
const result = yield (0, ApiPoster_1.sendGbmMessage)(gbmMessage, GMB_API_URL, conversationId);
|
|
188
|
+
// Just report
|
|
189
|
+
if (!result.ok) {
|
|
190
|
+
(0, stentor_logger_1.log)().error(result.message ||
|
|
191
|
+
`GMB: combined (#${i}) post failed (${result.error}): ${result.message || ""}`);
|
|
192
|
+
}
|
|
193
|
+
// Wait a bit before sending the next
|
|
194
|
+
if (i < messageObject.length) {
|
|
195
|
+
yield delay(300);
|
|
196
|
+
}
|
|
197
|
+
i++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const result = yield (0, ApiPoster_1.sendGbmMessage)(messageObject, GMB_API_URL, conversationId);
|
|
202
|
+
// Just report
|
|
203
|
+
if (!result.ok) {
|
|
204
|
+
(0, stentor_logger_1.log)().error(result.message || `GMB: single post failed (${result.error}): ${result.message || ""}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
139
207
|
}
|
|
140
208
|
}
|
|
141
209
|
// flush chatDataStore
|
|
@@ -151,86 +219,6 @@ function _handlerHook(handler, event, context, callback, _services, props) {
|
|
|
151
219
|
callback(null, finalResponse);
|
|
152
220
|
});
|
|
153
221
|
}
|
|
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
|
-
exports.sendResponse = sendResponse;
|
|
205
|
-
/**
|
|
206
|
-
* Initializes the Google credentials for calling the
|
|
207
|
-
* Business Messages API.
|
|
208
|
-
*/
|
|
209
|
-
function initCredentials() {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
const email = process.env.GOOGLE_BUSINESS_MESSAGES_EMAIL;
|
|
212
|
-
const key = process.env.GOOGLE_BUSINESS_MESSAGES_SECRET;
|
|
213
|
-
if (!email) {
|
|
214
|
-
throw new Error(`Environment variable GOOGLE_BUSINESS_MESSAGES_EMAIL required for GBM Channel.`);
|
|
215
|
-
}
|
|
216
|
-
if (!key) {
|
|
217
|
-
throw new Error(`Environment variable GOOGLE_BUSINESS_MESSAGES_SECRET required for GBM Channel.`);
|
|
218
|
-
}
|
|
219
|
-
const authClient = new google_auth_library_1.JWT(email, null,
|
|
220
|
-
// Help from this by https://github.com/theoephraim/node-google-spreadsheet/issues/244#issuecomment-616031349
|
|
221
|
-
key.replace(/\\n/g, "\n"), ['https://www.googleapis.com/auth/businessmessages']);
|
|
222
|
-
return new Promise(function (resolve, reject) {
|
|
223
|
-
authClient.authorize(function (err, tokens) {
|
|
224
|
-
if (err) {
|
|
225
|
-
reject(err);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
resolve(authClient);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
222
|
function generateSessionId() {
|
|
235
223
|
return `gbm-session-${(0, uuid_1.v4)()}`;
|
|
236
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbmHandlerHook.js","sourceRoot":"","sources":["../src/GbmHandlerHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAAiF;AAEjF,mDAAqC;AAErC,qCAAsD;
|
|
1
|
+
{"version":3,"file":"GbmHandlerHook.js","sourceRoot":"","sources":["../src/GbmHandlerHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAAiF;AAEjF,mDAAqC;AAErC,qCAAsD;AACtD,qCAAyF;AAEzF,+BAAoC;AAEpC,mDAAuE;AAEvE,2CAAqG;AAErG,MAAM,KAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CACnC,IAAI,OAAO,CAAC,CAAC,O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G,MAAM,IAAA,0BAAc,EAAC,aAAa,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;oBAEhF,cAAc;oBACd,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;wBACZ,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,4BAA4B,MAAM,CAAC,KAAK,MAAM,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC,CAAC;qBACvG;iBACJ;aACJ;SACJ;QAED,sBAAsB;QACtB,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YACzB,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;SAC/B;QAED,kCAAkC;QAClC,IAAI,aAAa,GAAW,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,gDAAgD;QAC9F,IAAI,OAAO,CAAC,aAAa,EAAE;YACvB,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,+BAAW,EAAE,aAAa,CAAC,CAAC;SACrE;QAED,2CAA2C;QAC3C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;;CACjC;AAED,SAAS,iBAAiB;IACtB,OAAO,eAAe,IAAA,SAAM,GAAE,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -3,9 +3,9 @@ import { Translator } from "@xapp/patterns/lib";
|
|
|
3
3
|
import { RequestResponse } from "stentor-models";
|
|
4
4
|
import { AgentMessage } from "../../models";
|
|
5
5
|
import { GbmChannelProps } from "../../Channel";
|
|
6
|
-
export declare class TranslateResponse extends Translator<RequestResponse, AgentMessage> {
|
|
6
|
+
export declare class TranslateResponse extends Translator<RequestResponse, AgentMessage | AgentMessage[]> {
|
|
7
7
|
protected readonly props?: GbmChannelProps;
|
|
8
8
|
constructor(props?: GbmChannelProps);
|
|
9
|
-
translate(requestResponse: RequestResponse): AgentMessage;
|
|
9
|
+
translate(requestResponse: RequestResponse): AgentMessage | AgentMessage[];
|
|
10
10
|
private getRepresentative;
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
13
13
|
this.props = props;
|
|
14
14
|
}
|
|
15
15
|
translate(requestResponse) {
|
|
16
|
-
|
|
16
|
+
const gbmResponses = [];
|
|
17
17
|
const botResponse = requestResponse.response;
|
|
18
18
|
(0, stentor_logger_1.log)().debug(`GBM: BOT SAYS ${JSON.stringify(botResponse)}`);
|
|
19
19
|
if (botResponse) {
|
|
@@ -33,79 +33,84 @@ class TranslateResponse extends lib_1.Translator {
|
|
|
33
33
|
list = display;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
const messageId = (0, uuid_1.v4)();
|
|
37
36
|
const representative = this.getRepresentative();
|
|
38
37
|
const suggestions = convertSuggestions(outputSpeech.suggestions);
|
|
39
38
|
if (text) {
|
|
40
|
-
|
|
41
|
-
messageId,
|
|
39
|
+
gbmResponses.push({
|
|
40
|
+
messageId: (0, uuid_1.v4)(),
|
|
42
41
|
representative,
|
|
43
42
|
text,
|
|
44
43
|
suggestions,
|
|
45
|
-
containsRichText: true
|
|
46
|
-
};
|
|
44
|
+
containsRichText: true,
|
|
45
|
+
});
|
|
47
46
|
}
|
|
48
47
|
if (card) {
|
|
49
48
|
const imageUrl = card.smallImageUrl || card.largeImageUrl;
|
|
50
|
-
|
|
51
|
-
messageId,
|
|
49
|
+
gbmResponses.push({
|
|
50
|
+
messageId: (0, uuid_1.v4)(),
|
|
52
51
|
representative,
|
|
53
52
|
richCard: {
|
|
54
53
|
standaloneCard: {
|
|
55
54
|
cardContent: {
|
|
56
55
|
title: card.title,
|
|
57
56
|
description: card.content,
|
|
58
|
-
media: imageUrl
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
media: imageUrl
|
|
58
|
+
? {
|
|
59
|
+
height: models_1.Height.MEDIUM,
|
|
60
|
+
contentInfo: {
|
|
61
|
+
fileUrl: imageUrl,
|
|
62
|
+
forceRefresh: false,
|
|
63
|
+
},
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
suggestions
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
65
|
+
: undefined,
|
|
66
|
+
suggestions,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
70
71
|
}
|
|
71
72
|
if (list) {
|
|
72
|
-
|
|
73
|
-
messageId,
|
|
73
|
+
gbmResponses.push({
|
|
74
|
+
messageId: (0, uuid_1.v4)(),
|
|
74
75
|
representative,
|
|
75
76
|
richCard: {
|
|
76
77
|
carouselCard: list.items.length > 1 ? convertList(list) : undefined,
|
|
77
|
-
standaloneCard: list.items.length === 1
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
standaloneCard: list.items.length === 1
|
|
79
|
+
? {
|
|
80
|
+
cardContent: {
|
|
81
|
+
title: list.items[0].title,
|
|
82
|
+
description: list.items[0].description,
|
|
83
|
+
media: list.items[0].image
|
|
84
|
+
? {
|
|
85
|
+
height: models_1.Height.MEDIUM,
|
|
86
|
+
contentInfo: {
|
|
87
|
+
fileUrl: list.items[0].image.url,
|
|
88
|
+
forceRefresh: false,
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
: undefined,
|
|
92
|
+
suggestions,
|
|
93
|
+
},
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
};
|
|
95
|
+
: undefined,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
else {
|
|
96
|
-
|
|
101
|
+
gbmResponses.push({
|
|
97
102
|
messageId: (0, uuid_1.v4)(),
|
|
98
103
|
representative: this.getRepresentative(),
|
|
99
|
-
text: "Something went wrong. The gremlins were fed after midnight. Try later!"
|
|
100
|
-
};
|
|
104
|
+
text: "Something went wrong. The gremlins were fed after midnight. Try later!",
|
|
105
|
+
});
|
|
101
106
|
}
|
|
102
|
-
return
|
|
107
|
+
return gbmResponses.length === 1 ? gbmResponses[0] : gbmResponses;
|
|
103
108
|
}
|
|
104
109
|
getRepresentative() {
|
|
105
110
|
return {
|
|
106
111
|
representativeType: models_1.RepresentativeType.BOT,
|
|
107
112
|
displayName: this.props.botAvatarName,
|
|
108
|
-
avatarImage: this.props.botAvatarImageUrl
|
|
113
|
+
avatarImage: this.props.botAvatarImageUrl,
|
|
109
114
|
};
|
|
110
115
|
}
|
|
111
116
|
}
|
|
@@ -125,8 +130,8 @@ function convertSuggestions(suggestions) {
|
|
|
125
130
|
gbmSuggestions.push({
|
|
126
131
|
reply: {
|
|
127
132
|
text: suggestion,
|
|
128
|
-
postbackData: suggestion
|
|
129
|
-
}
|
|
133
|
+
postbackData: suggestion,
|
|
134
|
+
},
|
|
130
135
|
});
|
|
131
136
|
}
|
|
132
137
|
else if (suggestion.title && suggestion.url) {
|
|
@@ -139,8 +144,8 @@ function convertSuggestions(suggestions) {
|
|
|
139
144
|
text: suggestion.title,
|
|
140
145
|
postbackData: url,
|
|
141
146
|
dialAction: {
|
|
142
|
-
phoneNumber
|
|
143
|
-
}
|
|
147
|
+
phoneNumber,
|
|
148
|
+
},
|
|
144
149
|
},
|
|
145
150
|
});
|
|
146
151
|
}
|
|
@@ -150,9 +155,9 @@ function convertSuggestions(suggestions) {
|
|
|
150
155
|
text: suggestion.title,
|
|
151
156
|
postbackData: url,
|
|
152
157
|
openUrlAction: {
|
|
153
|
-
url
|
|
154
|
-
}
|
|
155
|
-
}
|
|
158
|
+
url,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
156
161
|
});
|
|
157
162
|
}
|
|
158
163
|
}
|
|
@@ -160,8 +165,8 @@ function convertSuggestions(suggestions) {
|
|
|
160
165
|
gbmSuggestions.push({
|
|
161
166
|
reply: {
|
|
162
167
|
text: suggestion.title,
|
|
163
|
-
postbackData: suggestion.title
|
|
164
|
-
}
|
|
168
|
+
postbackData: suggestion.title,
|
|
169
|
+
},
|
|
165
170
|
});
|
|
166
171
|
}
|
|
167
172
|
}
|
|
@@ -182,8 +187,8 @@ function convertButtonSuggestions(buttons) {
|
|
|
182
187
|
gbmSuggestions.push({
|
|
183
188
|
action: {
|
|
184
189
|
text: button.title,
|
|
185
|
-
postbackData: button.title
|
|
186
|
-
}
|
|
190
|
+
postbackData: button.title,
|
|
191
|
+
},
|
|
187
192
|
});
|
|
188
193
|
}
|
|
189
194
|
}
|
|
@@ -203,13 +208,15 @@ function convertList(list) {
|
|
|
203
208
|
title: listItem.title,
|
|
204
209
|
description: listItem.description,
|
|
205
210
|
suggestions: convertButtonSuggestions(listItem.buttons),
|
|
206
|
-
media: imageUrl
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
media: imageUrl
|
|
212
|
+
? {
|
|
213
|
+
height: models_1.Height.MEDIUM,
|
|
214
|
+
contentInfo: {
|
|
215
|
+
fileUrl: imageUrl,
|
|
216
|
+
forceRefresh: false,
|
|
217
|
+
},
|
|
211
218
|
}
|
|
212
|
-
|
|
219
|
+
: undefined,
|
|
213
220
|
});
|
|
214
221
|
}
|
|
215
222
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Translators/TranslateResponse/index.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,4CAAgD;AAGhD,uDAAkD;AAClD,mDAAqC;AAErC,+BAAoC;AAEpC,yCAQsB;AAGtB,MAAa,iBAAkB,SAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Translators/TranslateResponse/index.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,4CAAgD;AAGhD,uDAAkD;AAClD,mDAAqC;AAErC,+BAAoC;AAEpC,yCAQsB;AAGtB,MAAa,iBAAkB,SAAQ,gBAA0D;IAG7F,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AK,EAAE;QAC/B,MAAM,QAAQ,GAAG,MAAA,QAAQ,CAAC,KAAK,0CAAE,GAAG,CAAC;QAErC,YAAY,CAAC,IAAI,CAAC;YACd,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,WAAW,EAAE,wBAAwB,CAAC,QAAQ,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,QAAQ;gBACX,CAAC,CAAC;oBACI,MAAM,EAAE,eAAM,CAAC,MAAM;oBACrB,WAAW,EAAE;wBACT,OAAO,EAAE,QAAQ;wBACjB,YAAY,EAAE,KAAK;qBACtB;iBACJ;gBACH,CAAC,CAAC,SAAS;SAClB,CAAC,CAAC;KACN;IAED,OAAO;QACH,SAAS,EAAE,kBAAS,CAAC,MAAM;QAC3B,YAAY,EAAE,YAAY;KAC7B,CAAC;AACN,CAAC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,5 +22,6 @@ __exportStar(require("./Constants"), exports);
|
|
|
22
22
|
__exportStar(require("./Guards"), exports);
|
|
23
23
|
__exportStar(require("./Translators"), exports);
|
|
24
24
|
__exportStar(require("./Types"), exports);
|
|
25
|
+
__exportStar(require("./ApiPoster"), exports);
|
|
25
26
|
__exportStar(require("./models"), exports);
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,qCAAmD;AAA1C,iHAAA,sBAAsB,OAAA;AAC/B,8CAA4B;AAC5B,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,qCAAmD;AAA1C,iHAAA,sBAAsB,OAAA;AAC/B,8CAA4B;AAC5B,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB"}
|
|
@@ -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":";;;AAYA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC1B,yFAAmE,CAAA;IACnE,iCAAW,CAAA;IACX,qCAAe,CAAA;AACnB,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAyCD,IAAY,MAKX;AALD,WAAY,MAAM;IACd,mDAAyC,CAAA;IACzC,yBAAe,CAAA;IACf,2BAAiB,CAAA;IACjB,uBAAa,CAAA;AACjB,CAAC,EALW,MAAM,GAAN,cAAM,KAAN,cAAM,QAKjB;AAcD,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,8DAAiD,CAAA;IACjD,4BAAe,CAAA;IACf,8BAAiB,CAAA;AACrB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.45.
|
|
7
|
+
"version": "1.45.37",
|
|
8
8
|
"description": "Google Business Messages channel for stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/aws-lambda": "8.10.113",
|
|
19
19
|
"@types/chai": "4.3.4",
|
|
20
|
-
"@types/node-fetch": "2.6.
|
|
20
|
+
"@types/node-fetch": "2.6.3",
|
|
21
21
|
"@types/sinon": "4.3.3",
|
|
22
22
|
"@types/sinon-chai": "3.2.9",
|
|
23
23
|
"@types/uuid": "9.0.1",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"@xapp/patterns": "2.0.1",
|
|
45
45
|
"@xapp/stentor-actions-on-google": "1.45.32",
|
|
46
46
|
"@xapp/stentor-app": "1.45.32",
|
|
47
|
-
"businessmessages": "1.0.4",
|
|
48
47
|
"google-auth-library": "8.7.0",
|
|
49
48
|
"googleapis-common": "6.0.4",
|
|
50
49
|
"node-fetch": "2.6.9"
|
|
@@ -66,5 +65,5 @@
|
|
|
66
65
|
"clean": "rm -rf ./lib/*",
|
|
67
66
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
68
67
|
},
|
|
69
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "2fb9b5f67ab69cff6cb85dfb29c0a00956c2fbe2"
|
|
70
69
|
}
|