@almaviacx/gge-toolkit-service 1.0.5 → 1.0.6

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.
@@ -3,6 +3,7 @@ export declare type Context = AlmContext & {
3
3
  SYNCSERVICE_SID: string;
4
4
  SYNC_CALL_MAP_SID: string;
5
5
  SYNC_INPHONE_MAP_SID: string;
6
+ SYNC_PHONE_MAP_SID: string;
6
7
  WORKSPACE_SID: string;
7
8
  SYNC_WORKER_EMAIL_MAP_SID: string;
8
9
  SYNC_MESSAGE_SERVICE_SID: string;
@@ -7,3 +7,8 @@ export interface FlexFlow {
7
7
  channelType: string;
8
8
  chatServiceSid: string;
9
9
  }
10
+ export interface PhoneFlowConfig {
11
+ id: string;
12
+ phone: string;
13
+ studioFlow: string;
14
+ }
@@ -0,0 +1,4 @@
1
+ import { Twilio } from "twilio";
2
+ import { Context } from "../models";
3
+ export declare const getFlowsConfiguration: (context: Context, client: Twilio, phone: string, channelType: string) => Promise<any>;
4
+ export declare const getWechatFlexFlowSid: (context: Context, client: Twilio, accountId: string) => Promise<any>;
@@ -0,0 +1,117 @@
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
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getWechatFlexFlowSid = exports.getFlowsConfiguration = void 0;
40
+ var getDoc = function (context, client) { return __awaiter(void 0, void 0, void 0, function () {
41
+ return __generator(this, function (_a) {
42
+ switch (_a.label) {
43
+ case 0: return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID)
44
+ .documents(context.CONFIG_SYNC_SID)
45
+ .fetch()];
46
+ case 1: return [2 /*return*/, _a.sent()];
47
+ }
48
+ });
49
+ }); };
50
+ var getFlexFlow = function (list, phone) {
51
+ var conf = list.find(function (p) { return p.phone === phone; });
52
+ return conf === null || conf === void 0 ? void 0 : conf.studioFlow;
53
+ };
54
+ var getFlowsConfiguration = function (context, client, phone, channelType) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var camp, _a, doc, doc, doc, item;
56
+ var _b, _c;
57
+ return __generator(this, function (_d) {
58
+ switch (_d.label) {
59
+ case 0:
60
+ camp = phone;
61
+ _a = channelType;
62
+ switch (_a) {
63
+ case "video": return [3 /*break*/, 1];
64
+ case "facebook": return [3 /*break*/, 4];
65
+ case "wechat": return [3 /*break*/, 6];
66
+ }
67
+ return [3 /*break*/, 8];
68
+ case 1:
69
+ if (!(phone === "default" && channelType === "video")) return [3 /*break*/, 3];
70
+ return [4 /*yield*/, getDoc(context, client)];
71
+ case 2:
72
+ doc = _d.sent();
73
+ camp = (_c = (_b = doc === null || doc === void 0 ? void 0 : doc.data) === null || _b === void 0 ? void 0 : _b.video) === null || _c === void 0 ? void 0 : _c.defaultPhone;
74
+ _d.label = 3;
75
+ case 3: return [3 /*break*/, 8];
76
+ case 4: return [4 /*yield*/, getDoc(context, client)];
77
+ case 5:
78
+ doc = _d.sent();
79
+ if (doc && doc.data && doc.data.facebook && doc.data.facebook.pages) {
80
+ return [2 /*return*/, { studioFlow: getFlexFlow(doc.data.facebook.pages, phone) }];
81
+ }
82
+ return [2 /*return*/, undefined];
83
+ case 6: return [4 /*yield*/, getDoc(context, client)];
84
+ case 7:
85
+ doc = _d.sent();
86
+ if (doc && doc.data && doc.data.wechat && doc.data.wechat.accounts) {
87
+ return [2 /*return*/, { studioFlow: getFlexFlow(doc.data.wechat.accounts, phone) }];
88
+ }
89
+ return [2 /*return*/, undefined];
90
+ case 8: return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID)
91
+ .syncMaps(context.SYNC_PHONE_MAP_SID)
92
+ .syncMapItems(camp)
93
+ .fetch()];
94
+ case 9:
95
+ item = _d.sent();
96
+ return [2 /*return*/, item === null || item === void 0 ? void 0 : item.data[channelType]];
97
+ }
98
+ });
99
+ }); };
100
+ exports.getFlowsConfiguration = getFlowsConfiguration;
101
+ var getWechatFlexFlowSid = function (context, client, accountId) { return __awaiter(void 0, void 0, void 0, function () {
102
+ var doc, account;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0: return [4 /*yield*/, getDoc(context, client)];
106
+ case 1:
107
+ doc = _a.sent();
108
+ if (doc && doc.data && doc.data.wechat && doc.data.wechat.accounts) {
109
+ account = doc.data.wechat.accounts.find(function (a) { return a.id === accountId; });
110
+ return [2 /*return*/, account === null || account === void 0 ? void 0 : account.flexFlow];
111
+ }
112
+ return [2 /*return*/, undefined];
113
+ }
114
+ });
115
+ }); };
116
+ exports.getWechatFlexFlowSid = getWechatFlexFlowSid;
117
+ //# sourceMappingURL=flexFlows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flexFlows.js","sourceRoot":"","sources":["../../src/utils/flexFlows.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,MAAM,GAAG,UAAO,OAAgB,EAAE,MAAc;;;oBAC7C,qBAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC;qBACvD,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC;qBAClC,KAAK,EAAE,EAAA;oBAFV,sBAAO,SAEG,EAAC;;;KACZ,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAuB,EAAE,KAAa;IACzD,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAC,CAAkB,IAAK,OAAA,CAAC,CAAC,KAAK,KAAK,KAAK,EAAjB,CAAiB,CAAC,CAAC;IAClE,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAC;AAC1B,CAAC,CAAC;AAEK,IAAM,qBAAqB,GAAG,UAAO,OAAgB,EAAE,MAAc,EAAE,KAAa,EAAE,WAAmB;;;;;;gBAC1G,IAAI,GAAG,KAAK,CAA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