@telia-ace/widget-conversation 1.0.0
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.txt +6 -0
- package/README.md +256 -0
- package/lib/agent.d.ts +17 -0
- package/lib/agent.js +37 -0
- package/lib/conversation-controller.d.ts +87 -0
- package/lib/conversation-controller.js +298 -0
- package/lib/conversation-form-adapter.d.ts +7 -0
- package/lib/conversation-form-adapter.js +88 -0
- package/lib/conversation-platform.d.ts +49 -0
- package/lib/conversation-platform.js +295 -0
- package/lib/conversation-provider.d.ts +22 -0
- package/lib/conversation-provider.js +73 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +15 -0
- package/lib/resolve-entity-value.d.ts +10 -0
- package/lib/resolve-entity-value.js +22 -0
- package/lib/types.d.ts +35 -0
- package/lib/types.js +2 -0
- package/lib/ui/conversation/conversation-component.d.ts +32 -0
- package/lib/ui/conversation/conversation-component.js +152 -0
- package/lib/ui/conversation/conversation-content.d.ts +11 -0
- package/lib/ui/conversation/conversation-content.js +100 -0
- package/lib/ui/conversation/conversation-input.d.ts +6 -0
- package/lib/ui/conversation/conversation-input.js +154 -0
- package/lib/ui/conversation/conversation-loader.d.ts +8 -0
- package/lib/ui/conversation/conversation-loader.js +18 -0
- package/lib/ui/conversation/conversation-message.d.ts +7 -0
- package/lib/ui/conversation/conversation-message.js +141 -0
- package/lib/ui/conversation/conversation-styles.d.ts +9 -0
- package/lib/ui/conversation/conversation-styles.js +63 -0
- package/lib/ui/conversation/conversation.d.ts +6 -0
- package/lib/ui/conversation/conversation.js +139 -0
- package/lib/ui/conversation/index.d.ts +2 -0
- package/lib/ui/conversation/index.js +7 -0
- package/lib/ui/conversation/message-types/agent.d.ts +11 -0
- package/lib/ui/conversation/message-types/agent.js +54 -0
- package/lib/ui/conversation/message-types/custom.d.ts +9 -0
- package/lib/ui/conversation/message-types/custom.js +26 -0
- package/lib/ui/conversation/message-types/index.d.ts +5 -0
- package/lib/ui/conversation/message-types/index.js +16 -0
- package/lib/ui/conversation/message-types/system.d.ts +12 -0
- package/lib/ui/conversation/message-types/system.js +26 -0
- package/lib/ui/conversation/message-types/timestamp.d.ts +8 -0
- package/lib/ui/conversation/message-types/timestamp.js +36 -0
- package/lib/ui/conversation/message-types/user.d.ts +8 -0
- package/lib/ui/conversation/message-types/user.js +24 -0
- package/lib/ui/index.d.ts +2 -0
- package/lib/ui/index.js +10 -0
- package/lib/ui/return-button/index.d.ts +2 -0
- package/lib/ui/return-button/index.js +7 -0
- package/lib/ui/return-button/return-button-component.d.ts +19 -0
- package/lib/ui/return-button/return-button-component.js +70 -0
- package/lib/ui/return-button/return-button.d.ts +6 -0
- package/lib/ui/return-button/return-button.js +82 -0
- package/lib/user.d.ts +7 -0
- package/lib/user.js +16 -0
- package/lib/utils/custom-message.d.ts +3 -0
- package/lib/utils/custom-message.js +56 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -0
- package/lib/utils/open-chat-widget.d.ts +4 -0
- package/lib/utils/open-chat-widget.js +148 -0
- package/lib-esm/agent.d.ts +17 -0
- package/lib-esm/agent.js +34 -0
- package/lib-esm/conversation-controller.d.ts +87 -0
- package/lib-esm/conversation-controller.js +294 -0
- package/lib-esm/conversation-form-adapter.d.ts +7 -0
- package/lib-esm/conversation-form-adapter.js +85 -0
- package/lib-esm/conversation-platform.d.ts +49 -0
- package/lib-esm/conversation-platform.js +292 -0
- package/lib-esm/conversation-provider.d.ts +22 -0
- package/lib-esm/conversation-provider.js +70 -0
- package/lib-esm/index.d.ts +8 -0
- package/lib-esm/index.js +5 -0
- package/lib-esm/resolve-entity-value.d.ts +10 -0
- package/lib-esm/resolve-entity-value.js +18 -0
- package/lib-esm/types.d.ts +35 -0
- package/lib-esm/types.js +1 -0
- package/lib-esm/ui/conversation/conversation-component.d.ts +32 -0
- package/lib-esm/ui/conversation/conversation-component.js +127 -0
- package/lib-esm/ui/conversation/conversation-content.d.ts +11 -0
- package/lib-esm/ui/conversation/conversation-content.js +72 -0
- package/lib-esm/ui/conversation/conversation-input.d.ts +6 -0
- package/lib-esm/ui/conversation/conversation-input.js +129 -0
- package/lib-esm/ui/conversation/conversation-loader.d.ts +8 -0
- package/lib-esm/ui/conversation/conversation-loader.js +13 -0
- package/lib-esm/ui/conversation/conversation-message.d.ts +7 -0
- package/lib-esm/ui/conversation/conversation-message.js +113 -0
- package/lib-esm/ui/conversation/conversation-styles.d.ts +9 -0
- package/lib-esm/ui/conversation/conversation-styles.js +37 -0
- package/lib-esm/ui/conversation/conversation.d.ts +6 -0
- package/lib-esm/ui/conversation/conversation.js +111 -0
- package/lib-esm/ui/conversation/index.d.ts +2 -0
- package/lib-esm/ui/conversation/index.js +2 -0
- package/lib-esm/ui/conversation/message-types/agent.d.ts +11 -0
- package/lib-esm/ui/conversation/message-types/agent.js +25 -0
- package/lib-esm/ui/conversation/message-types/custom.d.ts +9 -0
- package/lib-esm/ui/conversation/message-types/custom.js +21 -0
- package/lib-esm/ui/conversation/message-types/index.d.ts +5 -0
- package/lib-esm/ui/conversation/message-types/index.js +5 -0
- package/lib-esm/ui/conversation/message-types/system.d.ts +12 -0
- package/lib-esm/ui/conversation/message-types/system.js +20 -0
- package/lib-esm/ui/conversation/message-types/timestamp.d.ts +8 -0
- package/lib-esm/ui/conversation/message-types/timestamp.js +31 -0
- package/lib-esm/ui/conversation/message-types/user.d.ts +8 -0
- package/lib-esm/ui/conversation/message-types/user.js +19 -0
- package/lib-esm/ui/index.d.ts +2 -0
- package/lib-esm/ui/index.js +2 -0
- package/lib-esm/ui/return-button/index.d.ts +2 -0
- package/lib-esm/ui/return-button/index.js +2 -0
- package/lib-esm/ui/return-button/return-button-component.d.ts +19 -0
- package/lib-esm/ui/return-button/return-button-component.js +44 -0
- package/lib-esm/ui/return-button/return-button.d.ts +6 -0
- package/lib-esm/ui/return-button/return-button.js +54 -0
- package/lib-esm/user.d.ts +7 -0
- package/lib-esm/user.js +13 -0
- package/lib-esm/utils/custom-message.d.ts +3 -0
- package/lib-esm/utils/custom-message.js +52 -0
- package/lib-esm/utils/index.d.ts +1 -0
- package/lib-esm/utils/index.js +1 -0
- package/lib-esm/utils/open-chat-widget.d.ts +4 -0
- package/lib-esm/utils/open-chat-widget.js +142 -0
- package/package.json +43 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
30
|
+
var t = {};
|
|
31
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
32
|
+
t[p] = s[p];
|
|
33
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
34
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
35
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
36
|
+
t[p[i]] = s[p[i]];
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
// import { Component } from '@telia-ace/widget-types-grid';
|
|
45
|
+
var widget_ui_1 = require("@telia-ace/widget-ui");
|
|
46
|
+
var react_1 = __importDefault(require("react"));
|
|
47
|
+
var styled_components_1 = __importStar(require("styled-components"));
|
|
48
|
+
var ReturnButton = function (_a) {
|
|
49
|
+
var className = _a.className, other = __rest(_a, ["className"]);
|
|
50
|
+
var _b = (0, widget_ui_1.useProperties)(), label = _b.label, active = _b.active, _c = _b.mode, mode = _c === void 0 ? 'flat' : _c, _d = _b.alert, alert = _d === void 0 ? {} : _d;
|
|
51
|
+
var symbol = alert.symbol, alertLabel = alert.label, showAlert = alert.show;
|
|
52
|
+
// const [showAlert, setShowAlert] = useState(show);
|
|
53
|
+
var dispatch = (0, widget_ui_1.useDispatch)();
|
|
54
|
+
if (!active) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return (react_1.default.createElement(StyledHighlightedButton, { className: className, mode: mode, "aria-label": label, onClick: function () {
|
|
58
|
+
dispatch('toggle');
|
|
59
|
+
} },
|
|
60
|
+
react_1.default.createElement(StyledLabel, null, label),
|
|
61
|
+
symbol && (react_1.default.createElement(StyledIconHolder, { showAlert: showAlert },
|
|
62
|
+
react_1.default.createElement(widget_ui_1.SymbolBadge, { symbol: symbol, title: alertLabel, size: 20 })))));
|
|
63
|
+
};
|
|
64
|
+
var FlashingColorAnimation = function (props) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
return (0, styled_components_1.keyframes)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% {\n background-color: ", ";\n }\n 50% {\n background-color: ", ";\n }\n 100 {\n background-color: ", ";\n }\n"], ["\n 0% {\n background-color: ", ";\n }\n 50% {\n background-color: ", ";\n }\n 100 {\n background-color: ", ";\n }\n"])), (_a = props.theme.colors) === null || _a === void 0 ? void 0 : _a.primary, (_b = props.theme.colors) === null || _b === void 0 ? void 0 : _b.accent, (_c = props.theme.colors) === null || _c === void 0 ? void 0 : _c.primary);
|
|
67
|
+
};
|
|
68
|
+
var ScrollingGradientAnimation = function (props) { return (0, styled_components_1.keyframes)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n 0% {\n background-position:0% 51%\n }\n 50% {\n background-position:100% 0%\n }\n 100% {\n background-position:0% 51%\n }\n"], ["\n 0% {\n background-position:0% 51%\n }\n 50% {\n background-position:100% 0%\n }\n 100% {\n background-position:0% 51%\n }\n"]))); };
|
|
69
|
+
var PulsatingIcon = (0, styled_components_1.keyframes)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n 0% {\n transform: rotate(0deg) scale(1.00);\n }\n 50% {\n transform: rotate(0deg) scale(1.00);\n }\n 55% {\n transform: rotate(-3deg) scale(0.80);\n }\n 60% {\n transform: rotate(-3deg) scale(0.80);\n }\n 65% {\n transform: rotate(3deg) scale(1.20);\n }\n 70% {\n transform: rotate(-3deg) scale(1.20);\n }\n 75% {\n transform: rotate(3deg) scale(1.20);\n }\n 80% {\n transform: rotate(-3deg) scale(1.20);\n }\n 85% {\n transform: rotate(3deg) scale(1.20);\n }\n 90% {\n transform: rotate(-3deg) scale(1.20);\n }\n 95% {\n transform: rotate(3deg) scale(1.20);\n }\n 100% {\n transform: rotate(0deg) scale(1);\n }\n"], ["\n 0% {\n transform: rotate(0deg) scale(1.00);\n }\n 50% {\n transform: rotate(0deg) scale(1.00);\n }\n 55% {\n transform: rotate(-3deg) scale(0.80);\n }\n 60% {\n transform: rotate(-3deg) scale(0.80);\n }\n 65% {\n transform: rotate(3deg) scale(1.20);\n }\n 70% {\n transform: rotate(-3deg) scale(1.20);\n }\n 75% {\n transform: rotate(3deg) scale(1.20);\n }\n 80% {\n transform: rotate(-3deg) scale(1.20);\n }\n 85% {\n transform: rotate(3deg) scale(1.20);\n }\n 90% {\n transform: rotate(-3deg) scale(1.20);\n }\n 95% {\n transform: rotate(3deg) scale(1.20);\n }\n 100% {\n transform: rotate(0deg) scale(1);\n }\n"])));
|
|
70
|
+
var StyledIconHolder = styled_components_1.default.span(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n flex-grow: 0;\n transform: translateX(", ");\n opacity: ", ";\n transition: transform 0.5s ease, opacity 0.3s ease;\n"], ["\n flex-grow: 0;\n transform: translateX(", ");\n opacity: ", ";\n transition: transform 0.5s ease, opacity 0.3s ease;\n"])), function (p) { return (p.showAlert ? '0px' : '50px'); }, function (p) { return (p.showAlert ? 1 : 0); });
|
|
71
|
+
var StyledLabel = styled_components_1.default.span(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n flex: 1;\n font-weight: 300;\n"], ["\n flex: 1;\n font-weight: 300;\n"])));
|
|
72
|
+
var flashingStyle = (0, styled_components_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n animation: ", " 1s ease infinite;\n"], ["\n animation: ", " 1s ease infinite;\n"])), FlashingColorAnimation);
|
|
73
|
+
var flashingGradientStyle = (0, styled_components_1.css)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n background: linear-gradient(\n 155deg,\n ", ",\n ", "\n );\n background-position: 0px 0px;\n background-size: 200% 200%;\n animation: ", " 1.5s ease infinite;\n"], ["\n background: linear-gradient(\n 155deg,\n ", ",\n ", "\n );\n background-position: 0px 0px;\n background-size: 200% 200%;\n animation: ", " 1.5s ease infinite;\n"])), function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.accent; }, ScrollingGradientAnimation);
|
|
74
|
+
var StyledHighlightedButton = (0, styled_components_1.default)(widget_ui_1.Button)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n overflow: hidden;\n padding: ", ";\n border-radius: ", ";\n color: ", ";\n ", "\n background-color: ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n i,\n svg {\n animation: ", " 3s ease infinite;\n }\n\n &:focus {\n ", "\n background: ", ";\n color: ", ";\n }\n"], ["\n overflow: hidden;\n padding: ", ";\n border-radius: ", ";\n color: ", ";\n ", "\n background-color: ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n i,\n svg {\n animation: ", " 3s ease infinite;\n }\n\n &:focus {\n ", "\n background: ", ";\n color: ", ";\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.large; }, function (p) { return p.theme.borderRadius; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) {
|
|
75
|
+
return p.mode === 'flashing'
|
|
76
|
+
? flashingStyle
|
|
77
|
+
: p.mode === 'flashingGradient'
|
|
78
|
+
? flashingGradientStyle
|
|
79
|
+
: '';
|
|
80
|
+
}, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, PulsatingIcon, function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && widget_ui_1.borderTabStyle; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; });
|
|
81
|
+
exports.default = ReturnButton;
|
|
82
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
|
package/lib/user.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConversationController, ConversationEntry } from './conversation-controller';
|
|
2
|
+
import { ConversationMessageSettings } from './types';
|
|
3
|
+
export declare class User {
|
|
4
|
+
private controller;
|
|
5
|
+
constructor(controller: ConversationController);
|
|
6
|
+
print: (settings: string | ConversationMessageSettings) => ConversationEntry;
|
|
7
|
+
}
|
package/lib/user.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
var conversation_controller_1 = require("./conversation-controller");
|
|
5
|
+
var User = /** @class */ (function () {
|
|
6
|
+
function User(controller) {
|
|
7
|
+
var _this = this;
|
|
8
|
+
this.controller = controller;
|
|
9
|
+
this.print = function (settings) {
|
|
10
|
+
var normalized = (0, conversation_controller_1.getNormalizedMessageSettings)(settings);
|
|
11
|
+
return _this.controller.createEntry(normalized.key, normalized.content, conversation_controller_1.ConversationMessageType.User, undefined, normalized.timestamp);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return User;
|
|
15
|
+
}());
|
|
16
|
+
exports.User = User;
|
|
@@ -0,0 +1,56 @@
|
|
|
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.registerCustomMessageComponent = void 0;
|
|
40
|
+
var react_1 = require("react");
|
|
41
|
+
var __1 = require("..");
|
|
42
|
+
var registerCustomMessageComponent = function (container, type, component) {
|
|
43
|
+
return container.getAsync('componentResolver').then(function (o) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
var platform;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0: return [4 /*yield*/, __1.ConversationPlatform.getInstance(container)];
|
|
48
|
+
case 1:
|
|
49
|
+
platform = _a.sent();
|
|
50
|
+
platform.addSubscription(o.registerComponent(type, (0, react_1.lazy)(function () { return component; })));
|
|
51
|
+
return [2 /*return*/];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}); });
|
|
55
|
+
};
|
|
56
|
+
exports.registerCustomMessageComponent = registerCustomMessageComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { navigateToConversation, openChatWidget, shouldPreventDefault } from './open-chat-widget';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldPreventDefault = exports.openChatWidget = exports.navigateToConversation = void 0;
|
|
4
|
+
var open_chat_widget_1 = require("./open-chat-widget");
|
|
5
|
+
Object.defineProperty(exports, "navigateToConversation", { enumerable: true, get: function () { return open_chat_widget_1.navigateToConversation; } });
|
|
6
|
+
Object.defineProperty(exports, "openChatWidget", { enumerable: true, get: function () { return open_chat_widget_1.openChatWidget; } });
|
|
7
|
+
Object.defineProperty(exports, "shouldPreventDefault", { enumerable: true, get: function () { return open_chat_widget_1.shouldPreventDefault; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
2
|
+
export declare const shouldPreventDefault: (container: Container) => boolean;
|
|
3
|
+
export declare const openChatWidget: (container: Container, contactMethod: any, triggerDOMTarget?: HTMLElement | undefined) => boolean | Promise<void> | Promise<boolean>;
|
|
4
|
+
export declare const navigateToConversation: (container: Container, contactMethod: any, routeName?: string) => any;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.navigateToConversation = exports.openChatWidget = exports.shouldPreventDefault = void 0;
|
|
4
|
+
var widget_plugins_1 = require("@telia-ace/widget-plugins");
|
|
5
|
+
var widget_services_1 = require("@telia-ace/widget-services");
|
|
6
|
+
var __1 = require("../");
|
|
7
|
+
var getParentWidget = function (widgetName, implementation) {
|
|
8
|
+
var mainWidgetName = widgetName.split('_contact');
|
|
9
|
+
return implementation.widgets.get(mainWidgetName[0]);
|
|
10
|
+
};
|
|
11
|
+
var getSeparateWidget = function (container) {
|
|
12
|
+
var originWidget = container.get('$widget');
|
|
13
|
+
var _a = container.get('$widget'), name = _a.name, implementation = _a.implementation;
|
|
14
|
+
var mainWidget = name.indexOf('_contact') > -1 ? getParentWidget(name, implementation) : originWidget;
|
|
15
|
+
var data = container.get('$settings').data;
|
|
16
|
+
var trigger = mainWidget.container.get('$settings').trigger;
|
|
17
|
+
var chatWidgetName = "".concat(name
|
|
18
|
+
.replace('_contact-method', '')
|
|
19
|
+
.replace('_contact', ''), "_contact-method");
|
|
20
|
+
var chatWidget = implementation.widgets.get(chatWidgetName);
|
|
21
|
+
if (chatWidget && !trigger) {
|
|
22
|
+
return { chatWidget: chatWidget, mainWidget: mainWidget, data: data };
|
|
23
|
+
}
|
|
24
|
+
return { mainWidget: mainWidget, data: data };
|
|
25
|
+
};
|
|
26
|
+
var shouldPreventDefault = function (container) {
|
|
27
|
+
var chatWidget = getSeparateWidget(container).chatWidget;
|
|
28
|
+
return !!chatWidget;
|
|
29
|
+
};
|
|
30
|
+
exports.shouldPreventDefault = shouldPreventDefault;
|
|
31
|
+
var openChatWidget = function (container, contactMethod /*ContactMethodType*/, triggerDOMTarget) {
|
|
32
|
+
var _a = getSeparateWidget(container), mainWidget = _a.mainWidget, data = _a.data, chatWidget = _a.chatWidget;
|
|
33
|
+
if (chatWidget) {
|
|
34
|
+
if (chatWidget.state === 'activated') {
|
|
35
|
+
return chatWidget.invoke('open').then(function () {
|
|
36
|
+
chatWidget.container.getAsync('conversation').then(function (conversation) {
|
|
37
|
+
conversation
|
|
38
|
+
.navigateToConversationIfActive(contactMethod.id)
|
|
39
|
+
.then(function () { return (0, widget_plugins_1.closeAllModals)(container); });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return chatWidget
|
|
44
|
+
.activate()
|
|
45
|
+
.then(function () {
|
|
46
|
+
var trigger = chatWidget.container.get('$settings').trigger;
|
|
47
|
+
trigger.action = 'hide'; // could be default in configuration
|
|
48
|
+
return chatWidget
|
|
49
|
+
.invoke('setSettings', function () { return ({
|
|
50
|
+
data: data,
|
|
51
|
+
trigger: trigger,
|
|
52
|
+
activate: true,
|
|
53
|
+
}); })
|
|
54
|
+
.then(function () {
|
|
55
|
+
return chatWidget.container
|
|
56
|
+
.getAsync('components')
|
|
57
|
+
.then(function (components) {
|
|
58
|
+
/**
|
|
59
|
+
* Could cause issues if target widget is no longer as specific for this use case
|
|
60
|
+
*/
|
|
61
|
+
var contactMethodsQuery = components
|
|
62
|
+
.components()
|
|
63
|
+
.ofType('contact-method');
|
|
64
|
+
components.write({
|
|
65
|
+
key: 'setContactMethodId',
|
|
66
|
+
attributes: {
|
|
67
|
+
properties: {
|
|
68
|
+
id: contactMethod.id,
|
|
69
|
+
guideId: contactMethod.guideId,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
target: contactMethodsQuery,
|
|
73
|
+
provider: 'localStorage',
|
|
74
|
+
});
|
|
75
|
+
var conversationsQuery = components
|
|
76
|
+
.components()
|
|
77
|
+
.ofType('conversation');
|
|
78
|
+
components.write({
|
|
79
|
+
key: 'setConversationProvider',
|
|
80
|
+
attributes: {
|
|
81
|
+
properties: { providers: [contactMethod.clientName] },
|
|
82
|
+
},
|
|
83
|
+
target: conversationsQuery,
|
|
84
|
+
provider: 'localStorage',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
})
|
|
89
|
+
.then(function () {
|
|
90
|
+
return chatWidget.invoke('attach', {
|
|
91
|
+
key: 'contact-method',
|
|
92
|
+
triggerDOMElement: triggerDOMTarget,
|
|
93
|
+
withRenderState: 'open',
|
|
94
|
+
});
|
|
95
|
+
})
|
|
96
|
+
.then(function () {
|
|
97
|
+
(0, widget_services_1.createStorageWriter)(chatWidget.container, 'activeStickyWidget', widget_services_1.StorageCategory.Necessary, {
|
|
98
|
+
medium: widget_services_1.StorageMedium.Local,
|
|
99
|
+
scope: widget_services_1.StorageScope.Implementation,
|
|
100
|
+
}).then(function (write) { return write(chatWidget.name); });
|
|
101
|
+
return chatWidget.container
|
|
102
|
+
.getAsync('conversation')
|
|
103
|
+
.then(function (platform) {
|
|
104
|
+
platform.setConversationEndedBehavior(__1.ConversationEndedBehavior.Deactivate);
|
|
105
|
+
})
|
|
106
|
+
.then(function () { return (0, widget_plugins_1.closeAllModals)(container); })
|
|
107
|
+
.then(function () { return false; });
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
mainWidget.container.getAsync('conversation').then(function (platform) {
|
|
111
|
+
return platform
|
|
112
|
+
.navigateToConversationIfActive(contactMethod.id)
|
|
113
|
+
.then(function () { return platform.setConversationEndedBehavior(__1.ConversationEndedBehavior.Navigate); });
|
|
114
|
+
});
|
|
115
|
+
return chatWidget ? false : true;
|
|
116
|
+
};
|
|
117
|
+
exports.openChatWidget = openChatWidget;
|
|
118
|
+
var navigateToConversation = function (container, contactMethod /*ContactMethodType*/, routeName) {
|
|
119
|
+
if (routeName === void 0) { routeName = 'conversation'; }
|
|
120
|
+
var _a = getSeparateWidget(container), mainWidget = _a.mainWidget, chatWidget = _a.chatWidget;
|
|
121
|
+
if (chatWidget) {
|
|
122
|
+
return chatWidget.container.getAsync('router').then(function (router) {
|
|
123
|
+
router.navigate(routeName, { id: contactMethod.id });
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return mainWidget.container.getAsync('conversation').then(function (platform) {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = platform.setConversationEndedBehavior(__1.ConversationEndedBehavior.Navigate)) === null || _a === void 0 ? void 0 : _a.then(function () {
|
|
129
|
+
mainWidget.container.getAsync('router').then(function (router) {
|
|
130
|
+
mainWidget.container
|
|
131
|
+
.getAsync('components')
|
|
132
|
+
.then(function (components) {
|
|
133
|
+
var conversationQuery = components.components().ofType('conversation');
|
|
134
|
+
components.write({
|
|
135
|
+
key: 'setConversationProvider',
|
|
136
|
+
attributes: { properties: { providers: [contactMethod.clientName] } },
|
|
137
|
+
target: conversationQuery,
|
|
138
|
+
provider: 'localStorage',
|
|
139
|
+
});
|
|
140
|
+
})
|
|
141
|
+
.then(function () {
|
|
142
|
+
router.navigate(routeName, { id: contactMethod.id });
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
exports.navigateToConversation = navigateToConversation;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Symbol } from '@telia-ace/widget-ui';
|
|
2
|
+
import { ConversationEntry } from './conversation-controller';
|
|
3
|
+
import { ConversationProvider } from './conversation-provider';
|
|
4
|
+
import { ConversationMessageSettings } from './types';
|
|
5
|
+
export declare type AgentSettings = {
|
|
6
|
+
name?: string;
|
|
7
|
+
avatar?: string | Symbol;
|
|
8
|
+
};
|
|
9
|
+
export declare class Agent {
|
|
10
|
+
private provider;
|
|
11
|
+
name?: string;
|
|
12
|
+
avatar?: string | Symbol;
|
|
13
|
+
constructor(provider: ConversationProvider, settings: AgentSettings);
|
|
14
|
+
print: (settings: string | ConversationMessageSettings) => ConversationEntry | undefined;
|
|
15
|
+
typing: () => (() => void) | undefined;
|
|
16
|
+
update(settings: AgentSettings): void;
|
|
17
|
+
}
|
package/lib-esm/agent.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ConversationMessageType, getNormalizedMessageSettings, } from './conversation-controller';
|
|
2
|
+
var Agent = /** @class */ (function () {
|
|
3
|
+
function Agent(provider, settings) {
|
|
4
|
+
var _this = this;
|
|
5
|
+
this.provider = provider;
|
|
6
|
+
this.print = function (settings) {
|
|
7
|
+
var sender = { name: _this.name, avatar: _this.avatar };
|
|
8
|
+
var normalized = getNormalizedMessageSettings(settings);
|
|
9
|
+
return _this.provider.createEntry(normalized.key, normalized.content, ConversationMessageType.Agent, sender, normalized.timestamp);
|
|
10
|
+
};
|
|
11
|
+
this.typing = function () {
|
|
12
|
+
return _this.provider.setTypingState({ name: _this.name, avatar: _this.avatar });
|
|
13
|
+
};
|
|
14
|
+
this.name = settings.name;
|
|
15
|
+
this.avatar = settings.avatar;
|
|
16
|
+
}
|
|
17
|
+
Agent.prototype.update = function (settings) {
|
|
18
|
+
var name = settings.name, avatar = settings.avatar;
|
|
19
|
+
if (avatar === null) {
|
|
20
|
+
this.avatar = undefined;
|
|
21
|
+
}
|
|
22
|
+
else if (avatar) {
|
|
23
|
+
this.avatar = avatar;
|
|
24
|
+
}
|
|
25
|
+
if (name === null) {
|
|
26
|
+
this.name = undefined;
|
|
27
|
+
}
|
|
28
|
+
else if (name) {
|
|
29
|
+
this.name = name;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return Agent;
|
|
33
|
+
}());
|
|
34
|
+
export { Agent };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Container, EventListener, EventManager } from '@webprovisions/platform';
|
|
2
|
+
import { ConversationProvider } from './conversation-provider';
|
|
3
|
+
import { ConversationMessageContent, ConversationMessageSender, ConversationMessageSettings, ConversationMessageUpdateSettings, NormalizedMessageSettings } from './types';
|
|
4
|
+
import { User } from './user';
|
|
5
|
+
export declare type ValidateHandler = (formValues: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}) => Promise<any>;
|
|
8
|
+
export declare type SubmitHandler = (formValues: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}) => Promise<any>;
|
|
11
|
+
export declare type Print = (content: string | ConversationMessageContent) => ConversationEntry;
|
|
12
|
+
export declare type FormHandlers = {
|
|
13
|
+
[key: string]: FormHandler;
|
|
14
|
+
};
|
|
15
|
+
export declare type FormHandler = {
|
|
16
|
+
validate?: ValidateHandler;
|
|
17
|
+
submit: SubmitHandler;
|
|
18
|
+
};
|
|
19
|
+
export declare type CancelLoaderDelegate = () => void;
|
|
20
|
+
export declare class ConversationEntry {
|
|
21
|
+
private writer;
|
|
22
|
+
constructor(writer: EntryWriter);
|
|
23
|
+
update(content: string | ConversationMessageUpdateSettings): void;
|
|
24
|
+
remove(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare enum ConversationMessageType {
|
|
27
|
+
User = "user",
|
|
28
|
+
Agent = "agent",
|
|
29
|
+
System = "system"
|
|
30
|
+
}
|
|
31
|
+
export declare type ConversationMessage = {
|
|
32
|
+
key: string;
|
|
33
|
+
timestamp: number | null;
|
|
34
|
+
content: ConversationMessageContent | null;
|
|
35
|
+
sender: ConversationMessageSender | null;
|
|
36
|
+
type: ConversationMessageType;
|
|
37
|
+
};
|
|
38
|
+
export declare type EntryWriter = (content: ConversationMessageUpdateSettings | null) => void;
|
|
39
|
+
export declare const getNormalizedMessageSettings: (settings: string | ConversationMessageSettings) => NormalizedMessageSettings;
|
|
40
|
+
/**
|
|
41
|
+
* Manages the stream of messages inside a `ConversationComponent` and provides external read-write
|
|
42
|
+
* access to it as well as exposing emitted actions.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ConversationController {
|
|
45
|
+
container: Container;
|
|
46
|
+
id: string;
|
|
47
|
+
formHandlers: FormHandlers;
|
|
48
|
+
/**
|
|
49
|
+
* Represents the current end user.
|
|
50
|
+
*/
|
|
51
|
+
user: User;
|
|
52
|
+
events: EventManager;
|
|
53
|
+
providers: string[];
|
|
54
|
+
active: boolean;
|
|
55
|
+
private registeredProviders;
|
|
56
|
+
private loaders;
|
|
57
|
+
private componentMounted;
|
|
58
|
+
messages: ConversationMessage[];
|
|
59
|
+
private typingActors;
|
|
60
|
+
constructor(container: Container, id: string);
|
|
61
|
+
setProviders(providers: string[]): void;
|
|
62
|
+
createProvider(name: string): ConversationProvider;
|
|
63
|
+
providerIndex(name: string): number;
|
|
64
|
+
dispose(): void;
|
|
65
|
+
onDispose(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
66
|
+
onStarted(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
67
|
+
disposeProvider(target: ConversationProvider): void;
|
|
68
|
+
onProvidersChange(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
69
|
+
setComponentMountedState(mounted: boolean): void;
|
|
70
|
+
getComponentMountedState(): boolean;
|
|
71
|
+
onUnreadMessage(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
72
|
+
createEntry(key: string, content: ConversationMessageContent, type: ConversationMessageType, sender?: ConversationMessageSender, timestamp?: number | null): ConversationEntry;
|
|
73
|
+
print: (settings: string | ConversationMessageSettings) => ConversationEntry;
|
|
74
|
+
update(): void;
|
|
75
|
+
getMessageStream(): {
|
|
76
|
+
messages: ConversationMessage[];
|
|
77
|
+
loading: boolean;
|
|
78
|
+
typingActors: ConversationMessageSender[];
|
|
79
|
+
};
|
|
80
|
+
setTypingState(sender: ConversationMessageSender, type?: ConversationMessageType): () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Displays a loader in the conversation.
|
|
83
|
+
*/
|
|
84
|
+
loader(): CancelLoaderDelegate;
|
|
85
|
+
submitForm(key: string, handler: SubmitHandler): void;
|
|
86
|
+
validateForm(key: string, handler: ValidateHandler): void;
|
|
87
|
+
}
|