@telia-ace/widget-conversation 1.0.12 → 1.0.15
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 +5 -5
- package/README.md +256 -256
- package/{lib-esm → dist}/agent.d.ts +17 -17
- package/{lib-esm → dist}/conversation-controller.d.ts +88 -88
- package/{lib-esm → dist}/conversation-form-adapter.d.ts +7 -7
- package/{lib-esm → dist}/conversation-platform.d.ts +50 -49
- package/{lib-esm → dist}/conversation-provider.d.ts +22 -22
- package/dist/conversation.js +558 -0
- package/dist/conversation.js.map +1 -0
- package/{lib → dist}/index.d.ts +9 -9
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.js +1678 -0
- package/dist/index2.js.map +1 -0
- package/{lib-esm → dist}/resolve-entity-value.d.ts +10 -10
- package/dist/return-button.js +174 -0
- package/dist/return-button.js.map +1 -0
- package/{lib → dist}/types.d.ts +110 -110
- package/{lib-esm → dist}/ui/conversation/conversation-component.d.ts +37 -37
- package/{lib → dist}/ui/conversation/conversation-content.d.ts +12 -11
- package/{lib-esm → dist}/ui/conversation/conversation-input.d.ts +6 -6
- package/{lib → dist}/ui/conversation/conversation-loader.d.ts +8 -8
- package/{lib → dist}/ui/conversation/conversation-message.d.ts +7 -7
- package/{lib-esm → dist}/ui/conversation/conversation-styles.d.ts +11 -11
- package/{lib → dist}/ui/conversation/conversation.d.ts +6 -6
- package/{lib → dist}/ui/conversation/index.d.ts +3 -2
- package/{lib-esm → dist}/ui/conversation/message-types/agent.d.ts +11 -11
- package/{lib → dist}/ui/conversation/message-types/custom-message-list-item.d.ts +9 -9
- package/{lib → dist}/ui/conversation/message-types/custom.d.ts +9 -9
- package/{lib → dist}/ui/conversation/message-types/index.d.ts +5 -5
- package/{lib-esm → dist}/ui/conversation/message-types/system.d.ts +12 -12
- package/{lib → dist}/ui/conversation/message-types/timestamp.d.ts +8 -8
- package/{lib-esm → dist}/ui/conversation/message-types/user.d.ts +8 -8
- package/dist/ui/index.d.ts +2 -0
- package/{lib-esm → dist}/ui/return-button/index.d.ts +2 -2
- package/{lib → dist}/ui/return-button/return-button-component.d.ts +19 -19
- package/{lib → dist}/ui/return-button/return-button.d.ts +6 -6
- package/{lib → dist}/user.d.ts +7 -7
- package/{lib-esm → dist}/utils/custom-message.d.ts +3 -3
- package/{lib-esm → dist}/utils/index.d.ts +1 -1
- package/{lib-esm → dist}/utils/open-chat-widget.d.ts +4 -4
- package/package.json +15 -16
- package/lib/agent.d.ts +0 -17
- package/lib/agent.js +0 -37
- package/lib/conversation-controller.d.ts +0 -88
- package/lib/conversation-controller.js +0 -318
- package/lib/conversation-form-adapter.d.ts +0 -7
- package/lib/conversation-form-adapter.js +0 -88
- package/lib/conversation-platform.d.ts +0 -49
- package/lib/conversation-platform.js +0 -295
- package/lib/conversation-provider.d.ts +0 -22
- package/lib/conversation-provider.js +0 -73
- package/lib/index.js +0 -17
- package/lib/resolve-entity-value.d.ts +0 -10
- package/lib/resolve-entity-value.js +0 -22
- package/lib/types.js +0 -19
- package/lib/ui/conversation/conversation-component.d.ts +0 -37
- package/lib/ui/conversation/conversation-component.js +0 -152
- package/lib/ui/conversation/conversation-content.js +0 -240
- package/lib/ui/conversation/conversation-input.d.ts +0 -6
- package/lib/ui/conversation/conversation-input.js +0 -163
- package/lib/ui/conversation/conversation-loader.js +0 -18
- package/lib/ui/conversation/conversation-message.js +0 -141
- package/lib/ui/conversation/conversation-styles.d.ts +0 -11
- package/lib/ui/conversation/conversation-styles.js +0 -65
- package/lib/ui/conversation/conversation.js +0 -139
- package/lib/ui/conversation/index.js +0 -7
- package/lib/ui/conversation/message-types/agent.d.ts +0 -11
- package/lib/ui/conversation/message-types/agent.js +0 -54
- package/lib/ui/conversation/message-types/custom-message-list-item.js +0 -27
- package/lib/ui/conversation/message-types/custom.js +0 -50
- package/lib/ui/conversation/message-types/index.js +0 -16
- package/lib/ui/conversation/message-types/system.d.ts +0 -12
- package/lib/ui/conversation/message-types/system.js +0 -26
- package/lib/ui/conversation/message-types/timestamp.js +0 -36
- package/lib/ui/conversation/message-types/user.d.ts +0 -8
- package/lib/ui/conversation/message-types/user.js +0 -24
- package/lib/ui/index.d.ts +0 -2
- package/lib/ui/index.js +0 -10
- package/lib/ui/return-button/index.d.ts +0 -2
- package/lib/ui/return-button/index.js +0 -7
- package/lib/ui/return-button/return-button-component.js +0 -70
- package/lib/ui/return-button/return-button.js +0 -82
- package/lib/user.js +0 -16
- package/lib/utils/custom-message.d.ts +0 -3
- package/lib/utils/custom-message.js +0 -56
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -7
- package/lib/utils/open-chat-widget.d.ts +0 -4
- package/lib/utils/open-chat-widget.js +0 -148
- package/lib-esm/agent.js +0 -34
- package/lib-esm/conversation-controller.js +0 -314
- package/lib-esm/conversation-form-adapter.js +0 -85
- package/lib-esm/conversation-platform.js +0 -292
- package/lib-esm/conversation-provider.js +0 -70
- package/lib-esm/index.d.ts +0 -9
- package/lib-esm/index.js +0 -6
- package/lib-esm/resolve-entity-value.js +0 -18
- package/lib-esm/types.d.ts +0 -110
- package/lib-esm/types.js +0 -16
- package/lib-esm/ui/conversation/conversation-component.js +0 -127
- package/lib-esm/ui/conversation/conversation-content.d.ts +0 -11
- package/lib-esm/ui/conversation/conversation-content.js +0 -212
- package/lib-esm/ui/conversation/conversation-input.js +0 -138
- package/lib-esm/ui/conversation/conversation-loader.d.ts +0 -8
- package/lib-esm/ui/conversation/conversation-loader.js +0 -13
- package/lib-esm/ui/conversation/conversation-message.d.ts +0 -7
- package/lib-esm/ui/conversation/conversation-message.js +0 -113
- package/lib-esm/ui/conversation/conversation-styles.js +0 -39
- package/lib-esm/ui/conversation/conversation.d.ts +0 -6
- package/lib-esm/ui/conversation/conversation.js +0 -111
- package/lib-esm/ui/conversation/index.d.ts +0 -2
- package/lib-esm/ui/conversation/index.js +0 -2
- package/lib-esm/ui/conversation/message-types/agent.js +0 -25
- package/lib-esm/ui/conversation/message-types/custom-message-list-item.d.ts +0 -9
- package/lib-esm/ui/conversation/message-types/custom-message-list-item.js +0 -22
- package/lib-esm/ui/conversation/message-types/custom.d.ts +0 -9
- package/lib-esm/ui/conversation/message-types/custom.js +0 -25
- package/lib-esm/ui/conversation/message-types/index.d.ts +0 -5
- package/lib-esm/ui/conversation/message-types/index.js +0 -5
- package/lib-esm/ui/conversation/message-types/system.js +0 -20
- package/lib-esm/ui/conversation/message-types/timestamp.d.ts +0 -8
- package/lib-esm/ui/conversation/message-types/timestamp.js +0 -31
- package/lib-esm/ui/conversation/message-types/user.js +0 -19
- package/lib-esm/ui/index.d.ts +0 -2
- package/lib-esm/ui/index.js +0 -2
- package/lib-esm/ui/return-button/index.js +0 -2
- package/lib-esm/ui/return-button/return-button-component.d.ts +0 -19
- package/lib-esm/ui/return-button/return-button-component.js +0 -44
- package/lib-esm/ui/return-button/return-button.d.ts +0 -6
- package/lib-esm/ui/return-button/return-button.js +0 -54
- package/lib-esm/user.d.ts +0 -7
- package/lib-esm/user.js +0 -13
- package/lib-esm/utils/custom-message.js +0 -52
- package/lib-esm/utils/index.js +0 -1
- package/lib-esm/utils/open-chat-widget.js +0 -142
|
@@ -1,4 +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;
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-conversation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "ACE Widget Conversation Platform",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Telia Company AB",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"telia"
|
|
9
9
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
12
|
"files": [
|
|
13
13
|
"LICENSE.txt",
|
|
14
14
|
"README.md",
|
|
15
|
-
"
|
|
16
|
-
"lib-esm/"
|
|
15
|
+
"dist/"
|
|
17
16
|
],
|
|
18
17
|
"publishConfig": {
|
|
19
18
|
"access": "public"
|
|
20
19
|
},
|
|
21
20
|
"scripts": {
|
|
22
|
-
"clean": "
|
|
23
|
-
"
|
|
21
|
+
"clean": "rimraf ./dist",
|
|
22
|
+
"precompile": "tsc -emitDeclarationOnly",
|
|
23
|
+
"compile": "vite build"
|
|
24
24
|
},
|
|
25
25
|
"sideEffects": false,
|
|
26
|
-
"typings": "lib/index.d.ts",
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@telia-ace/widget-core": "^1.0.
|
|
29
|
-
"@telia-ace/widget-forms": "^1.0.
|
|
30
|
-
"@telia-ace/widget-plugins": "^1.0.
|
|
31
|
-
"@telia-ace/widget-routing": "^1.0.
|
|
32
|
-
"@telia-ace/widget-services": "^1.0.
|
|
33
|
-
"@telia-ace/widget-ui": "^1.0.
|
|
34
|
-
"@telia-ace/widget-utilities": "^1.0.
|
|
27
|
+
"@telia-ace/widget-core": "^1.0.7",
|
|
28
|
+
"@telia-ace/widget-forms": "^1.0.11",
|
|
29
|
+
"@telia-ace/widget-plugins": "^1.0.8",
|
|
30
|
+
"@telia-ace/widget-routing": "^1.0.8",
|
|
31
|
+
"@telia-ace/widget-services": "^1.0.7",
|
|
32
|
+
"@telia-ace/widget-ui": "^1.0.11",
|
|
33
|
+
"@telia-ace/widget-utilities": "^1.0.2",
|
|
35
34
|
"@webprovisions/platform": "^1.1.2"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
@@ -41,5 +40,5 @@
|
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@types/react": "^16.8.0"
|
|
43
42
|
},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "0dfcfc79a4b6c45f98b7e62b71d5c0a30b907236"
|
|
45
44
|
}
|
package/lib/agent.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Symbol } from '@telia-ace/widget-ui';
|
|
2
|
-
import { ConversationEntry } from './conversation-controller';
|
|
3
|
-
import { ConversationProvider } from './conversation-provider';
|
|
4
|
-
import { ConversationMessageSettings, ConverstationMessageItem } 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 | ConverstationMessageItem<any> | ConverstationMessageItem<any>[]) => ConversationEntry | undefined;
|
|
15
|
-
typing: () => (() => void) | undefined;
|
|
16
|
-
update(settings: AgentSettings): void;
|
|
17
|
-
}
|
package/lib/agent.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Agent = void 0;
|
|
4
|
-
var conversation_controller_1 = require("./conversation-controller");
|
|
5
|
-
var Agent = /** @class */ (function () {
|
|
6
|
-
function Agent(provider, settings) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
this.provider = provider;
|
|
9
|
-
this.print = function (settings) {
|
|
10
|
-
var sender = { name: _this.name, avatar: _this.avatar };
|
|
11
|
-
var normalized = (0, conversation_controller_1.getNormalizedMessageSettings)(settings);
|
|
12
|
-
return _this.provider.createEntry(normalized.key, normalized.content, conversation_controller_1.ConversationMessageType.Agent, sender, normalized.timestamp);
|
|
13
|
-
};
|
|
14
|
-
this.typing = function () {
|
|
15
|
-
return _this.provider.setTypingState({ name: _this.name, avatar: _this.avatar });
|
|
16
|
-
};
|
|
17
|
-
this.name = settings.name;
|
|
18
|
-
this.avatar = settings.avatar;
|
|
19
|
-
}
|
|
20
|
-
Agent.prototype.update = function (settings) {
|
|
21
|
-
var name = settings.name, avatar = settings.avatar;
|
|
22
|
-
if (avatar === null) {
|
|
23
|
-
this.avatar = undefined;
|
|
24
|
-
}
|
|
25
|
-
else if (avatar) {
|
|
26
|
-
this.avatar = avatar;
|
|
27
|
-
}
|
|
28
|
-
if (name === null) {
|
|
29
|
-
this.name = undefined;
|
|
30
|
-
}
|
|
31
|
-
else if (name) {
|
|
32
|
-
this.name = name;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return Agent;
|
|
36
|
-
}());
|
|
37
|
-
exports.Agent = Agent;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Container, EventListener, EventManager } from '@webprovisions/platform';
|
|
2
|
-
import { ConversationProvider } from './conversation-provider';
|
|
3
|
-
import { ConversationMessageContent, ConversationMessageSender, ConversationMessageSettings, ConversationMessageUpdateSettings, ConverstationMessageItem, 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 | ConverstationMessageItem<any> | ConverstationMessageItem<any>[]): void;
|
|
24
|
-
remove(): void;
|
|
25
|
-
private getNormalizedSettings;
|
|
26
|
-
}
|
|
27
|
-
export declare enum ConversationMessageType {
|
|
28
|
-
User = "user",
|
|
29
|
-
Agent = "agent",
|
|
30
|
-
System = "system"
|
|
31
|
-
}
|
|
32
|
-
export declare type ConversationMessage = {
|
|
33
|
-
key: string;
|
|
34
|
-
timestamp: number | null;
|
|
35
|
-
content: ConversationMessageContent | null;
|
|
36
|
-
sender: ConversationMessageSender | null;
|
|
37
|
-
type: ConversationMessageType;
|
|
38
|
-
};
|
|
39
|
-
export declare type EntryWriter = (content: ConversationMessageUpdateSettings | null) => void;
|
|
40
|
-
export declare const getNormalizedMessageSettings: (settings: string | ConversationMessageSettings | ConverstationMessageItem<any> | ConverstationMessageItem<any>[]) => NormalizedMessageSettings;
|
|
41
|
-
/**
|
|
42
|
-
* Manages the stream of messages inside a `ConversationComponent` and provides external read-write
|
|
43
|
-
* access to it as well as exposing emitted actions.
|
|
44
|
-
*/
|
|
45
|
-
export declare class ConversationController {
|
|
46
|
-
container: Container;
|
|
47
|
-
id: string;
|
|
48
|
-
formHandlers: FormHandlers;
|
|
49
|
-
/**
|
|
50
|
-
* Represents the current end user.
|
|
51
|
-
*/
|
|
52
|
-
user: User;
|
|
53
|
-
events: EventManager;
|
|
54
|
-
providers: string[];
|
|
55
|
-
active: boolean;
|
|
56
|
-
private registeredProviders;
|
|
57
|
-
private loaders;
|
|
58
|
-
private componentMounted;
|
|
59
|
-
messages: ConversationMessage[];
|
|
60
|
-
private typingActors;
|
|
61
|
-
constructor(container: Container, id: string);
|
|
62
|
-
setProviders(providers: string[]): void;
|
|
63
|
-
createProvider(name: string): ConversationProvider;
|
|
64
|
-
providerIndex(name: string): number;
|
|
65
|
-
dispose(): void;
|
|
66
|
-
onDispose(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
67
|
-
onStarted(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
68
|
-
disposeProvider(target: ConversationProvider): void;
|
|
69
|
-
onProvidersChange(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
70
|
-
setComponentMountedState(mounted: boolean): void;
|
|
71
|
-
getComponentMountedState(): boolean;
|
|
72
|
-
onUnreadMessage(fn: EventListener): import("@webprovisions/platform").EventSubscriptionCancellation;
|
|
73
|
-
createEntry(key: string, content: ConversationMessageContent, type: ConversationMessageType, sender?: ConversationMessageSender, timestamp?: number | null): ConversationEntry;
|
|
74
|
-
print: (settings: string | ConversationMessageSettings) => ConversationEntry;
|
|
75
|
-
update(): void;
|
|
76
|
-
getMessageStream(): {
|
|
77
|
-
messages: ConversationMessage[];
|
|
78
|
-
loading: boolean;
|
|
79
|
-
typingActors: ConversationMessageSender[];
|
|
80
|
-
};
|
|
81
|
-
setTypingState(sender: ConversationMessageSender, type?: ConversationMessageType): () => void;
|
|
82
|
-
/**
|
|
83
|
-
* Displays a loader in the conversation.
|
|
84
|
-
*/
|
|
85
|
-
loader(): CancelLoaderDelegate;
|
|
86
|
-
submitForm(key: string, handler: SubmitHandler): void;
|
|
87
|
-
validateForm(key: string, handler: ValidateHandler): void;
|
|
88
|
-
}
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ConversationController = exports.getNormalizedMessageSettings = exports.ConversationMessageType = exports.ConversationEntry = void 0;
|
|
26
|
-
var widget_forms_1 = require("@telia-ace/widget-forms");
|
|
27
|
-
var widget_utilities_1 = require("@telia-ace/widget-utilities");
|
|
28
|
-
var conversation_provider_1 = require("./conversation-provider");
|
|
29
|
-
var user_1 = require("./user");
|
|
30
|
-
var ConversationEntry = /** @class */ (function () {
|
|
31
|
-
function ConversationEntry(writer) {
|
|
32
|
-
this.writer = writer;
|
|
33
|
-
}
|
|
34
|
-
ConversationEntry.prototype.update = function (content) {
|
|
35
|
-
var normalized = this.getNormalizedSettings(content);
|
|
36
|
-
// const normalized = typeof content === 'string' ? { body: content } : content;
|
|
37
|
-
this.writer(normalized);
|
|
38
|
-
};
|
|
39
|
-
ConversationEntry.prototype.remove = function () {
|
|
40
|
-
this.writer(null);
|
|
41
|
-
};
|
|
42
|
-
ConversationEntry.prototype.getNormalizedSettings = function (content) {
|
|
43
|
-
if (typeof content === 'string')
|
|
44
|
-
return { body: content };
|
|
45
|
-
else if (content.length > -1 && typeof content === 'object')
|
|
46
|
-
return { items: content };
|
|
47
|
-
else
|
|
48
|
-
return content;
|
|
49
|
-
};
|
|
50
|
-
return ConversationEntry;
|
|
51
|
-
}());
|
|
52
|
-
exports.ConversationEntry = ConversationEntry;
|
|
53
|
-
var ConversationMessageType;
|
|
54
|
-
(function (ConversationMessageType) {
|
|
55
|
-
ConversationMessageType["User"] = "user";
|
|
56
|
-
ConversationMessageType["Agent"] = "agent";
|
|
57
|
-
ConversationMessageType["System"] = "system";
|
|
58
|
-
})(ConversationMessageType = exports.ConversationMessageType || (exports.ConversationMessageType = {}));
|
|
59
|
-
var getNormalizedMessageSettings = function (settings) {
|
|
60
|
-
var content;
|
|
61
|
-
var key = (0, widget_utilities_1.uuid)();
|
|
62
|
-
var timestamp = Date.now();
|
|
63
|
-
if (Array.isArray(settings) && settings.length > -1) {
|
|
64
|
-
if (typeof settings[0] === 'string') {
|
|
65
|
-
content = { items: [settings] };
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
content = { items: settings };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (typeof settings === 'string') {
|
|
72
|
-
content = { body: settings };
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
settings = settings || {};
|
|
76
|
-
if (settings.type) {
|
|
77
|
-
content = __assign({}, settings);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
content = {
|
|
81
|
-
body: settings.body,
|
|
82
|
-
actions: settings.actions,
|
|
83
|
-
title: settings.title,
|
|
84
|
-
};
|
|
85
|
-
if (settings.key) {
|
|
86
|
-
key = settings.key;
|
|
87
|
-
}
|
|
88
|
-
if (settings.timestamp) {
|
|
89
|
-
timestamp = settings.timestamp;
|
|
90
|
-
}
|
|
91
|
-
if (settings.form) {
|
|
92
|
-
var builder = widget_forms_1.FormBuilder.create(key);
|
|
93
|
-
settings.form(builder);
|
|
94
|
-
var builtForm = builder.get();
|
|
95
|
-
content.form = builtForm;
|
|
96
|
-
}
|
|
97
|
-
if (settings.timestamp === null) {
|
|
98
|
-
timestamp = null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return { content: content, key: key, timestamp: timestamp };
|
|
103
|
-
};
|
|
104
|
-
exports.getNormalizedMessageSettings = getNormalizedMessageSettings;
|
|
105
|
-
var removeTypingState = function (typingActors, sender) {
|
|
106
|
-
if (!sender) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
var senderString = JSON.stringify(sender);
|
|
110
|
-
var indexToRemove = typingActors.findIndex(function (item) {
|
|
111
|
-
return senderString === JSON.stringify(item);
|
|
112
|
-
});
|
|
113
|
-
if (indexToRemove > -1) {
|
|
114
|
-
return typingActors.splice(indexToRemove, 1);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Manages the stream of messages inside a `ConversationComponent` and provides external read-write
|
|
119
|
-
* access to it as well as exposing emitted actions.
|
|
120
|
-
*/
|
|
121
|
-
var ConversationController = /** @class */ (function () {
|
|
122
|
-
function ConversationController(container, id) {
|
|
123
|
-
var _this = this;
|
|
124
|
-
this.container = container;
|
|
125
|
-
this.id = id;
|
|
126
|
-
this.formHandlers = {};
|
|
127
|
-
/**
|
|
128
|
-
* Represents the current end user.
|
|
129
|
-
*/
|
|
130
|
-
this.user = new user_1.User(this);
|
|
131
|
-
this.providers = [];
|
|
132
|
-
this.active = false;
|
|
133
|
-
this.registeredProviders = [];
|
|
134
|
-
this.loaders = 0;
|
|
135
|
-
this.componentMounted = false;
|
|
136
|
-
this.messages = [];
|
|
137
|
-
this.typingActors = [];
|
|
138
|
-
this.print = function (settings) {
|
|
139
|
-
var normalized = (0, exports.getNormalizedMessageSettings)(settings);
|
|
140
|
-
return _this.createEntry(normalized.key, normalized.content, ConversationMessageType.System, undefined, normalized.timestamp);
|
|
141
|
-
};
|
|
142
|
-
var widget = container.get('$widget');
|
|
143
|
-
this.events = widget.events.createChild(this);
|
|
144
|
-
}
|
|
145
|
-
ConversationController.prototype.setProviders = function (providers) {
|
|
146
|
-
var _this = this;
|
|
147
|
-
var removed = [];
|
|
148
|
-
var added = [];
|
|
149
|
-
// remove
|
|
150
|
-
this.providers
|
|
151
|
-
.reduce(function (acc, provider) {
|
|
152
|
-
if (providers.indexOf(provider) === -1) {
|
|
153
|
-
acc.push(provider);
|
|
154
|
-
}
|
|
155
|
-
return acc;
|
|
156
|
-
}, [])
|
|
157
|
-
.forEach(function (providerToRemove) {
|
|
158
|
-
var indexToRemove = _this.providers.indexOf(providerToRemove);
|
|
159
|
-
if (indexToRemove > -1) {
|
|
160
|
-
removed.push(providerToRemove);
|
|
161
|
-
_this.providers.splice(indexToRemove, 1);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
// add
|
|
165
|
-
providers.forEach(function (provider) {
|
|
166
|
-
if (_this.providers.indexOf(provider) === -1) {
|
|
167
|
-
added.push(provider);
|
|
168
|
-
_this.providers.push(provider);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
if (added.length || removed.length) {
|
|
172
|
-
this.events.dispatch('conversation:providers-changed', { added: added, removed: removed });
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
ConversationController.prototype.createProvider = function (name) {
|
|
176
|
-
var index = this.providerIndex(name);
|
|
177
|
-
if (index > -1) {
|
|
178
|
-
return this.registeredProviders[index];
|
|
179
|
-
}
|
|
180
|
-
var provider = conversation_provider_1.ConversationProvider.create(name, this.container, this);
|
|
181
|
-
this.registeredProviders.push(provider);
|
|
182
|
-
return provider;
|
|
183
|
-
};
|
|
184
|
-
ConversationController.prototype.providerIndex = function (name) {
|
|
185
|
-
return this.registeredProviders.findIndex(function (p) { return p.name === name; });
|
|
186
|
-
};
|
|
187
|
-
ConversationController.prototype.dispose = function () {
|
|
188
|
-
this.registeredProviders.forEach(function (provider) { return provider.dispose(); });
|
|
189
|
-
this.messages = [];
|
|
190
|
-
this.events.dispatch('conversation:controller-disposed', this);
|
|
191
|
-
this.active = false;
|
|
192
|
-
};
|
|
193
|
-
ConversationController.prototype.onDispose = function (fn) {
|
|
194
|
-
return this.events.subscribe('conversation:controller-disposed', fn);
|
|
195
|
-
};
|
|
196
|
-
ConversationController.prototype.onStarted = function (fn) {
|
|
197
|
-
return this.events.subscribe('conversation:started', fn);
|
|
198
|
-
};
|
|
199
|
-
ConversationController.prototype.disposeProvider = function (target) {
|
|
200
|
-
var index = this.providerIndex(target.name);
|
|
201
|
-
index > -1 && this.registeredProviders.splice(index, 1);
|
|
202
|
-
this.events.dispatch('conversation:providers-changed', { removed: [target.name] });
|
|
203
|
-
if (!this.registeredProviders.length) {
|
|
204
|
-
this.dispose();
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
ConversationController.prototype.onProvidersChange = function (fn) {
|
|
208
|
-
return this.events.subscribe('conversation:providers-changed', fn);
|
|
209
|
-
};
|
|
210
|
-
ConversationController.prototype.setComponentMountedState = function (mounted) {
|
|
211
|
-
if (this.componentMounted === mounted) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
this.componentMounted = mounted;
|
|
215
|
-
if (mounted) {
|
|
216
|
-
this.events.dispatch('conversation:unread-message', false);
|
|
217
|
-
this.events.dispatch('conversation:started', true);
|
|
218
|
-
this.active = true;
|
|
219
|
-
}
|
|
220
|
-
this.events.dispatch('conversation:component-mount-changed', mounted);
|
|
221
|
-
};
|
|
222
|
-
ConversationController.prototype.getComponentMountedState = function () {
|
|
223
|
-
return this.componentMounted;
|
|
224
|
-
};
|
|
225
|
-
ConversationController.prototype.onUnreadMessage = function (fn) {
|
|
226
|
-
return this.events.subscribe('conversation:unread-message', fn);
|
|
227
|
-
};
|
|
228
|
-
ConversationController.prototype.createEntry = function (key, content, type, sender, timestamp) {
|
|
229
|
-
var _this = this;
|
|
230
|
-
var message = {
|
|
231
|
-
key: key,
|
|
232
|
-
content: content,
|
|
233
|
-
type: type,
|
|
234
|
-
sender: sender || null,
|
|
235
|
-
timestamp: timestamp || timestamp === null ? timestamp : Date.now(),
|
|
236
|
-
};
|
|
237
|
-
this.messages.push(message);
|
|
238
|
-
message.type === ConversationMessageType.Agent &&
|
|
239
|
-
removeTypingState(this.typingActors, sender);
|
|
240
|
-
var entry = new ConversationEntry(function (updated) {
|
|
241
|
-
if (updated !== null) {
|
|
242
|
-
var _a = updated.timestamp, updatedTimestamp = _a === void 0 ? undefined : _a, content_1 = __rest(updated, ["timestamp"]);
|
|
243
|
-
message.content = content_1;
|
|
244
|
-
if (updatedTimestamp) {
|
|
245
|
-
message.timestamp = updatedTimestamp;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
var indexToRemove = _this.messages.indexOf(message);
|
|
250
|
-
message.content = null;
|
|
251
|
-
if (indexToRemove > -1) {
|
|
252
|
-
_this.messages.splice(indexToRemove, 1);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
_this.events.dispatch('conversation:message-updated', { message: message });
|
|
256
|
-
_this.update();
|
|
257
|
-
});
|
|
258
|
-
this.events.dispatch('conversation:message-created', { message: message });
|
|
259
|
-
this.update();
|
|
260
|
-
if (!this.componentMounted) {
|
|
261
|
-
this.events.dispatch('conversation:unread-message', true);
|
|
262
|
-
}
|
|
263
|
-
return entry;
|
|
264
|
-
};
|
|
265
|
-
ConversationController.prototype.update = function () {
|
|
266
|
-
this.events.dispatch('conversation:updated', {
|
|
267
|
-
messages: this.messages,
|
|
268
|
-
loading: this.loaders > 0,
|
|
269
|
-
typingActors: this.typingActors,
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
ConversationController.prototype.getMessageStream = function () {
|
|
273
|
-
return {
|
|
274
|
-
messages: this.messages,
|
|
275
|
-
loading: this.loaders > 0,
|
|
276
|
-
typingActors: this.typingActors,
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
ConversationController.prototype.setTypingState = function (sender, type) {
|
|
280
|
-
var _this = this;
|
|
281
|
-
if (this.typingActors.indexOf(sender) === -1) {
|
|
282
|
-
this.typingActors.push(sender);
|
|
283
|
-
this.update();
|
|
284
|
-
}
|
|
285
|
-
return function () {
|
|
286
|
-
removeTypingState(_this.typingActors, sender);
|
|
287
|
-
_this.update();
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Displays a loader in the conversation.
|
|
292
|
-
*/
|
|
293
|
-
ConversationController.prototype.loader = function () {
|
|
294
|
-
var _this = this;
|
|
295
|
-
this.loaders = this.loaders + 1;
|
|
296
|
-
var dismissed = false;
|
|
297
|
-
if (this.loaders === 1) {
|
|
298
|
-
this.update();
|
|
299
|
-
}
|
|
300
|
-
return function () {
|
|
301
|
-
if (!dismissed) {
|
|
302
|
-
dismissed = true;
|
|
303
|
-
_this.loaders = _this.loaders - 1;
|
|
304
|
-
if (_this.loaders === 0) {
|
|
305
|
-
_this.update();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
ConversationController.prototype.submitForm = function (key, handler) {
|
|
311
|
-
this.formHandlers[key] = __assign(__assign({}, this.formHandlers[key]), { submit: handler });
|
|
312
|
-
};
|
|
313
|
-
ConversationController.prototype.validateForm = function (key, handler) {
|
|
314
|
-
this.formHandlers[key] = __assign(__assign({}, this.formHandlers[key]), { validate: handler });
|
|
315
|
-
};
|
|
316
|
-
return ConversationController;
|
|
317
|
-
}());
|
|
318
|
-
exports.ConversationController = ConversationController;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ConversationPlatform } from '.';
|
|
2
|
-
export declare class ConversationFormAdapter {
|
|
3
|
-
private platform;
|
|
4
|
-
constructor(platform: ConversationPlatform);
|
|
5
|
-
submit: (invoke: any, cancel: any) => (contactMethod: any) => Promise<any>;
|
|
6
|
-
updateContactMethod: (contactMethod: any, errors?: any) => void;
|
|
7
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
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.ConversationFormAdapter = void 0;
|
|
40
|
-
var ConversationFormAdapter /*implements Adapter*/ = /** @class */ (function () {
|
|
41
|
-
function ConversationFormAdapter(platform) {
|
|
42
|
-
var _this = this;
|
|
43
|
-
this.platform = platform;
|
|
44
|
-
this.submit = function (invoke /*InvokeAdapterDelegate*/, cancel /*CancelAdapterDelegate*/) {
|
|
45
|
-
return function (contactMethod) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
46
|
-
return [2 /*return*/];
|
|
47
|
-
}); }); };
|
|
48
|
-
};
|
|
49
|
-
// this.platform.container
|
|
50
|
-
// .getAsync('data')
|
|
51
|
-
// .then((dataSource: any/* DataSource */) =>
|
|
52
|
-
// dataSource
|
|
53
|
-
// .read()
|
|
54
|
-
// .then((entries: any) => {
|
|
55
|
-
// const { entryId } = contactMethod;
|
|
56
|
-
// const entry = entries.find((e: any) => e.id === entryId);
|
|
57
|
-
// if (entry) {
|
|
58
|
-
// const { submit, validate } = this.platform.formHandlers[entry.content.key];
|
|
59
|
-
// const { values } = { values: {} }/*extractFormValues(contactMethod.body.form)*/;
|
|
60
|
-
// if (validate) {
|
|
61
|
-
// return validate(values)
|
|
62
|
-
// .then((result) => {
|
|
63
|
-
// const { valid, errors } = result;
|
|
64
|
-
// if (valid) {
|
|
65
|
-
// return submit(values)
|
|
66
|
-
// .then(() => {
|
|
67
|
-
// this.updateContactMethod(contactMethod);
|
|
68
|
-
// return {};
|
|
69
|
-
// });
|
|
70
|
-
// }
|
|
71
|
-
// this.updateContactMethod(contactMethod, errors);
|
|
72
|
-
// return {};
|
|
73
|
-
// });
|
|
74
|
-
// }
|
|
75
|
-
// return submit(values)
|
|
76
|
-
// .then(() => {
|
|
77
|
-
// this.updateContactMethod(contactMethod);
|
|
78
|
-
// return {};
|
|
79
|
-
// });
|
|
80
|
-
// }
|
|
81
|
-
// return {};
|
|
82
|
-
// }),
|
|
83
|
-
// )
|
|
84
|
-
this.updateContactMethod = function (contactMethod, errors) { };
|
|
85
|
-
}
|
|
86
|
-
return ConversationFormAdapter;
|
|
87
|
-
}());
|
|
88
|
-
exports.ConversationFormAdapter = ConversationFormAdapter;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ComponentNodeController, ComponentPlatform } from '@telia-ace/widget-core';
|
|
2
|
-
import { RouteData } from '@telia-ace/widget-routing';
|
|
3
|
-
import { Container, EventManager, EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
4
|
-
import { ConversationController } from './conversation-controller';
|
|
5
|
-
import { ConversationProvider } from './conversation-provider';
|
|
6
|
-
export declare type ConversationHandler = (conversation: ConversationProvider, component: ComponentNodeController) => void | (() => void);
|
|
7
|
-
export declare type UnregisterControllerDelegate = () => void;
|
|
8
|
-
export declare type ConversationProviderRegistration = {
|
|
9
|
-
name: string;
|
|
10
|
-
handler: ConversationHandler;
|
|
11
|
-
};
|
|
12
|
-
export declare enum ConversationEndedBehavior {
|
|
13
|
-
Deactivate = "deactivate",
|
|
14
|
-
Navigate = "navigate",
|
|
15
|
-
None = "none"
|
|
16
|
-
}
|
|
17
|
-
export declare type SessionInfo = {
|
|
18
|
-
id?: string;
|
|
19
|
-
route?: RouteData;
|
|
20
|
-
conversationEndedBehavior?: ConversationEndedBehavior;
|
|
21
|
-
};
|
|
22
|
-
export declare class ConversationPlatform {
|
|
23
|
-
private container;
|
|
24
|
-
private components;
|
|
25
|
-
events: EventManager;
|
|
26
|
-
private controllers;
|
|
27
|
-
private providers;
|
|
28
|
-
private disposeProviders;
|
|
29
|
-
private subscriptions;
|
|
30
|
-
private storageWriter;
|
|
31
|
-
private router;
|
|
32
|
-
private buttonQuery;
|
|
33
|
-
private sessionInfo;
|
|
34
|
-
constructor(container: Container, components: ComponentPlatform);
|
|
35
|
-
initialize(): void;
|
|
36
|
-
addSubscription(sub: EventSubscriptionCancellation): void;
|
|
37
|
-
static getInstance(container: Container, key?: string): Promise<ConversationPlatform>;
|
|
38
|
-
navigateToConversationIfActive(id: string): Promise<void>;
|
|
39
|
-
setConversationEndedBehavior(behavior: ConversationEndedBehavior): Promise<void>;
|
|
40
|
-
createController(id: string): ConversationController;
|
|
41
|
-
registerProvider(name: string, handler: ConversationHandler): void;
|
|
42
|
-
registerController(conversation: ConversationController, component: ComponentNodeController): boolean;
|
|
43
|
-
private writeToComponents;
|
|
44
|
-
private invokeHandler;
|
|
45
|
-
getComponentRoute(): Promise<RouteData | undefined>;
|
|
46
|
-
dispose(): void;
|
|
47
|
-
static handleContactMethodClick(event: any, container: Container, contactMethod: any, callback?: Function): Promise<void>;
|
|
48
|
-
static handleContactMethodSubmit(container: Container, contactMethod: any): Promise<any>;
|
|
49
|
-
}
|