@quintype/framework 7.18.8-webengage.0 → 7.18.8-webengage.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/handlers/webengage.js +10 -17
- package/server/routes.js +8 -6
package/package.json
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
1
|
const get = require("lodash/get");
|
|
2
2
|
const request = require("request-promise");
|
|
3
3
|
|
|
4
|
-
exports.
|
|
4
|
+
exports.triggerWebengageNotifications = async function triggerWebengageNotifications(
|
|
5
|
+
req,
|
|
6
|
+
res,
|
|
7
|
+
next,
|
|
8
|
+
{ apiKey, licenseCode }
|
|
9
|
+
) {
|
|
5
10
|
const eventName = get(req, ["body", "v1", "event", "name"], "");
|
|
6
|
-
|
|
11
|
+
const url = `https://api.webengage.com/v2/accounts/${licenseCode}/business/save-event`;
|
|
7
12
|
|
|
8
|
-
switch (eventName) {
|
|
9
|
-
case "story-publish":
|
|
10
|
-
const { "author-name": author, headline } = req.body;
|
|
11
|
-
eventData = { author, headline };
|
|
12
|
-
break;
|
|
13
|
-
case "push-notification-triggered":
|
|
14
|
-
const { title, message } = req.body;
|
|
15
|
-
eventData = { title, message };
|
|
16
|
-
break;
|
|
17
|
-
default:
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
const url = `https://api.webengage.com/v2/accounts/${webengageLicenseCode}/business/save-event`;
|
|
21
13
|
try {
|
|
22
14
|
await request({
|
|
23
15
|
uri: url,
|
|
24
16
|
method: "POST",
|
|
25
17
|
headers: {
|
|
26
|
-
Authorization: `Bearer ${
|
|
18
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27
19
|
"content-type": "application/json",
|
|
28
20
|
},
|
|
29
|
-
body: { eventName: eventName, eventData: {
|
|
21
|
+
body: { eventName: eventName, eventData: { ...req.body, user_type: "malibu_user" } },
|
|
30
22
|
json: true,
|
|
31
23
|
});
|
|
32
24
|
res.status(200).send("webengage event triggered successfully");
|
|
33
25
|
return;
|
|
34
26
|
} catch (error) {
|
|
27
|
+
console.log("webengage event failed");
|
|
35
28
|
res.status(500).send("webengage event failed");
|
|
36
29
|
return;
|
|
37
30
|
}
|
package/server/routes.js
CHANGED
|
@@ -23,7 +23,7 @@ const { redirectStory } = require("./handlers/story-redirect");
|
|
|
23
23
|
const { simpleJsonHandler } = require("./handlers/simple-json-handler");
|
|
24
24
|
const { makePickComponentSync } = require("../isomorphic/impl/make-pick-component-sync");
|
|
25
25
|
const { registerFCMTopic } = require("./handlers/fcm-registration-handler");
|
|
26
|
-
const {
|
|
26
|
+
const { triggerWebengageNotifications } = require("./handlers/webengage");
|
|
27
27
|
const rp = require("request-promise");
|
|
28
28
|
const bodyParser = require("body-parser");
|
|
29
29
|
const get = require("lodash/get");
|
|
@@ -333,9 +333,7 @@ exports.isomorphicRoutes = function isomorphicRoutes(
|
|
|
333
333
|
sMaxAge = 900,
|
|
334
334
|
appLoadingPlaceholder = "",
|
|
335
335
|
fcmServerKey = "",
|
|
336
|
-
|
|
337
|
-
webengageLicenseCode,
|
|
338
|
-
webengageApiKey,
|
|
336
|
+
webengageConfig = {},
|
|
339
337
|
}
|
|
340
338
|
) {
|
|
341
339
|
const withConfig = withConfigPartial(getClient, logError, publisherConfig, configWrapper);
|
|
@@ -430,8 +428,12 @@ exports.isomorphicRoutes = function isomorphicRoutes(
|
|
|
430
428
|
|
|
431
429
|
app.post("/register-fcm-topic", bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServerKey }));
|
|
432
430
|
|
|
433
|
-
if (enableWebengage) {
|
|
434
|
-
app.post(
|
|
431
|
+
if (webengageConfig.enableWebengage) {
|
|
432
|
+
app.post(
|
|
433
|
+
"/webengage/trigger-notification",
|
|
434
|
+
bodyParser.json(),
|
|
435
|
+
withConfig(triggerWebengageNotifications, webengageConfig)
|
|
436
|
+
);
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
if (manifestFn) {
|