@telia-ace/widget-conversation 1.0.21 → 1.0.24

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/README.md CHANGED
@@ -58,32 +58,34 @@ const agent = conversation.createAgent({
58
58
 
59
59
  ## Writing to the conversation
60
60
 
61
+ ***`print()` accepts an array, which is considered best practice when writing to the conversation. The previous way of posting an object will still currently be supported, but is considered to be deprecated.**
62
+
61
63
  ### Posting, updating and removing content
62
64
 
63
- When managing content in the conversation you'll first need to create an `Agent`-object and then use its `print()` function. There are serveral types of entries in order to accommedate different types of content.
65
+ When managing content in the conversation you'll first need to create an `Agent`-object and then use its `print()` function. There are serveral types of entries in order to accommodate different types of content.
64
66
 
65
- The `print(content: object)` function let's you return a `ConversationEntry` message that can be used to update and/or remove the content from the conversation.
67
+ The `print(items: ConversationMessageItem[])` function let's you return a `ConversationEntry` message that can be used to update and/or remove the content from the conversation.
66
68
 
67
69
  ##### Example of simple text message
68
70
 
69
71
  ```ts
70
72
  // print user message
71
- conversation.user.print('Lorem ipsum');
73
+ conversation.user.print([['text', 'Lorem ipsum']]);
72
74
 
73
75
  // print agent message
74
76
  const agent = conversation.createAgent();
75
- agent.print('Lorem ipsum');
77
+ agent.print([['text', 'Lorem ipsum']]);
76
78
  ```
77
79
 
78
80
  ##### Example of updating or removing content
79
81
 
80
82
  ```ts
81
83
  const agent = conversation.createAgent();
82
- const entry = agent.print('Hello world!');
84
+ const entry = agent.print([['text', 'Hello world!']]);
83
85
 
84
- entry.update({
86
+ entry.update([
85
87
  // ...
86
- });
88
+ ]);
87
89
 
88
90
  entry.remove();
89
91
  ```
@@ -92,24 +94,55 @@ entry.remove();
92
94
 
93
95
  You can post an entry into the conversation with actions. You can specify a title, body and available actions. This is only supported for the `Agent` and will be displayed as a system message.
94
96
 
95
- | Name | Type | Description |
96
- | --------- | -------- | ------------------------------------------------------------- |
97
- | `title` | `string` | Title for the entry. |
98
- | `body` | `string` | Body content for the entry. Supports HTML. |
99
- | `actions` | `object` | Key-value-pairs representing available actions for the entry. |
97
+ This can be either in the form of a "ButtonList" or an "LinkList" as demostrated below.
98
+
99
+ | Name | Type | Description |
100
+ | --------- | -------- | -------------------------------------------- |
101
+ | `header` | `string` | Header for the entry. |
102
+ | `actions` | `array` | Array of of available actions for the entry. |
100
103
 
101
104
  ##### Example of a list of actions
102
105
 
103
106
  ```ts
104
- agent.print({
105
- title: 'Download invoices',
106
- body: 'Click an invoice below to download a copy.',
107
- actions: {
108
- invoice_190201: 'Invoice 190201',
109
- invoice_190301: 'Invoice 190301',
110
- invoice_190401: 'Invoice 190401',
111
- },
112
- });
107
+ // example of button list
108
+ agent.print([
109
+ [
110
+ 'button-list',
111
+ {
112
+ header: 'Download invoices',
113
+ actions: [
114
+ {
115
+ actionKey: 'invoice_190201',
116
+ label: 'Invoice 190201',
117
+ },
118
+ {
119
+ actionKey: 'invoice_190301',
120
+ label: 'Invoice 190301',
121
+ },
122
+ ],
123
+ },
124
+ ],
125
+ ]);
126
+
127
+ // here we use a link list instead, but with the same actions
128
+ agent.print([
129
+ [
130
+ 'link-list',
131
+ {
132
+ header: 'Download invoices',
133
+ actions: [
134
+ {
135
+ actionKey: 'invoice_190201',
136
+ label: 'Invoice 190201',
137
+ },
138
+ {
139
+ actionKey: 'invoice_190301',
140
+ label: 'Invoice 190301',
141
+ },
142
+ ],
143
+ },
144
+ ],
145
+ ]);
113
146
  ```
114
147
 
115
148
  ### Entry with a form
@@ -152,6 +185,56 @@ agent.print({
152
185
  });
153
186
  ```
154
187
 
188
+ ### Entry with a video call
189
+
190
+ Use the `video-request` item type to create an entry representing an incoming video call. This entry can also have a form attached, which uses the `FormBuilder`-method and is handled by the `conversation.form` event. It is only supported for an `Agent` and will be displayed as a system message.
191
+
192
+ | Name | Type | Description |
193
+ | -------------- | -------- | ----------------------------------------------- |
194
+ | `header` | `string` | Header for the entry. |
195
+ | `acceptLabel` | `string` | Label to be shown for the "accept call button" |
196
+ | `declineLabel` | `string` | Label to be shown for the "decline call button" |
197
+
198
+ ##### Example of an entry for an incoming video call
199
+
200
+ ```ts
201
+ agent.print([
202
+ [
203
+ 'video-request',
204
+ {
205
+ header: 'Video call',
206
+ accept: 'Accept',
207
+ decline: 'Decline',
208
+ },
209
+ ],
210
+ ]);
211
+ ```
212
+
213
+ When the user presses one of these buttons to accept or decline the call, an action will be dispatched with actionKey `accept-video-call` or `decline-video-call`, depending on which button was clicked.
214
+
215
+ Listening to these actions can be done as following:
216
+
217
+ ```ts
218
+ component.actions.watch('conversation.action', (input, next) => {
219
+ if (input.actionKey === 'accept-video-call') {
220
+ // this will render an overlay over the widget,
221
+ // and prepare the widget for displaying the actual call
222
+ component.actions.dispatch('show-overlay', {});
223
+ } else if (input.actionKey === 'decline-video-call') {
224
+ // ...
225
+ }
226
+ return next(input);
227
+ });
228
+ ```
229
+
230
+ Use an overlay over the conversation to render your video call. The `show-overlay`-action, as described above, accomplishes this. After the overlay is rendered and ready it will dispatch another event: `overlay-mounted`. Use the HTML element this generates to render your video call.
231
+
232
+ ```ts
233
+ component.actions.watch('overlay-mounted', (overlayElem, next) => {
234
+ // the overlayElem here may be used to render the ongoing call
235
+ });
236
+ ```
237
+
155
238
  ### The loading and typing indicators
156
239
 
157
240
  When you need to fetch data from external resource you should use the `loading()` function on the `ConversationProvider` to inform the user that something is about to happen. Even in cases when the response is available immediately it gives a better user experience to present a loading indicator for a short while.
@@ -181,7 +264,7 @@ System message in the conversation are sent by using the `print` method on the `
181
264
  #### Example
182
265
 
183
266
  ```ts
184
- conversation.print('Hello world!');
267
+ conversation.print([['text', 'Hello world!']]);
185
268
  ```
186
269
 
187
270
  ## Reading from the conversation
@@ -4,5 +4,5 @@ declare type Props = {
4
4
  className?: string;
5
5
  agentData?: ConversationMessageSender;
6
6
  };
7
- declare const ConversationLoader: React.FC<Props>;
7
+ declare const ConversationLoader: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
8
8
  export default ConversationLoader;