@davi-ai/retorik-framework 1.0.7 → 1.0.8

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
@@ -1,508 +1,6 @@
1
- # retorik-framework
2
-
3
- > Retorik Framework package
4
-
5
- [![NPM](https://img.shields.io/npm/v/retorik-framework.svg)](https://www.npmjs.com/package/retorik-framework) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
6
-
7
- ## Usage with React
8
-
9
- ### Install
10
-
11
- Create a .npmrc file at project root (where your package.json file is located) :
12
-
13
- ```
14
- @davi:registry=https://pkgs.dev.azure.com/mydavi/_packaging/Retorik/npm/registry/
15
-
16
- always-auth=true
17
- ```
18
-
19
- Then [connect to feed](https://dev.azure.com/mydavi/BU%20Logiciel/_artifacts/feed/Retorik/connect/npm) and install package :
20
-
21
- ```bash
22
- npm install --save @davi/retorik-framework
23
- ```
24
-
25
- ### Retorik Agent (full screen)
26
-
27
- Minimal configuration :
28
-
29
- ```tsx
30
- import { RetorikAgent, characters } from '@davi/retorik-framework'
31
- import {
32
- Configuration,
33
- ViewsConfiguration,
34
- ChatbotData,
35
- PonyfillFactoryCredentials,
36
- AddressData,
37
- UserData,
38
- CustomVoice,
39
- characters
40
- } from '@davi/retorik-framework/dist/src'
41
-
42
- const defaultConfig: Configuration = {
43
- subtitles: {
44
- activated: true,
45
- maxLength: 50,
46
- showAttachmentsAsSubtitle: false
47
- }
48
- }
49
-
50
- const defaultViewsConfig: ViewsConfiguration = {
51
- homeRoute: 'home',
52
- views: {
53
- home: {
54
- background: {
55
- image: 'images/background_MTC.jpg',
56
- style: 'image'
57
- }
58
- }
59
- }
60
- }
61
-
62
- const chatbotData: ChatbotData = {
63
- size: undefined,
64
- height: undefined
65
- }
66
-
67
- // NB : prefix can be 'dev', 'staging', or 'experimental'
68
- const addressData: AddressData = {
69
- baseURI: ''
70
- tenant: 'name_of_the_tenant',
71
- prefix: 'prefix_if_not_using_production_studio.retorik'
72
- }
73
-
74
- const userData: UserData = {
75
- name: '',
76
- id: '',
77
- username: '',
78
- nom: '',
79
- prenom: '',
80
- email: '',
81
- token: '',
82
- referrer: '',
83
- ipaddress: ''
84
- }
85
-
86
- const ponyfillFactoryCredentials: PonyfillFactoryCredentials = {
87
- region: 'your_region',
88
- subscriptionKey: 'subscription_key'
89
- }
90
-
91
- class Example extends Component {
92
- render() {
93
- return (
94
- <RetorikAgent
95
- config={defaultConfig}
96
- viewsConfig={defaultViewsConfig}
97
- chatbotData={chatbotData}
98
- agentData={characters.lea}
99
- ponyfillFactoryCredentials={ponyfillFactoryCredentials}
100
- addressData={addressData}
101
- userData={userData}
102
- />
103
- }
104
- }
105
- ```
106
-
107
- ### Retorik Widget
108
-
109
- You can use Retorik Widget just like Retorik Agent, with the same props.
110
- The default button supplied with Retorik Widget can be customized or deleted as you wish (`#retorik-widget-button`)
111
- You can create your own buttons and use several global helper functions to open and close the widget.
112
- These functions can be either imported from the package (React mode) or used through the DOM window element :
113
- - React :
114
- ```ts
115
- import {
116
- openWidget,
117
- closeWidget,
118
- toggleWidget,
119
- toggleDisplay
120
- } from '@davi/retorik-framework'
121
-
122
- openWidget() // open the widget
123
- closeWidget() // close the widget
124
- toggleWidget() // toggle to open if the widget is closed, and to close if the widget is opened
125
- toggleDisplay() // toggle from large display to thumbnail, or from thumbnail to large (experimental)
126
- ```
127
- - commonJs :
128
- ```ts
129
- window.Retorik.toggleWidget()
130
- window.Retorik.openWidget()
131
- window.Retorik.closeWidget()
132
- window.Retorik.toggleDisplay()
133
- ````
134
- A configuration file is also available, allowing you to customize some parts of the widget. If this configuration is used, it has to be added in the props as `{ widgetConfig: <configuration> }` This configuration's type is :
135
-
136
- ```ts
137
- type WidgetConfiguration = {
138
- button?: WidgetButton // button options
139
- large?: WidgetFrame // main frame options
140
- thumbnail?: WidgetFrame // thumbnail mode options (experimental)
141
- }
142
-
143
- type WidgetButton = {
144
- display?: boolean // set this to false to prevent the button from being displayed
145
- text?: {
146
- content?: string // string that will be displayed in the button, if not set a default translation of 'Need help ?' based on the browser's default language is displayed
147
- color?: string // text color, default = rgb(112, 112, 112)
148
- bold?: boolean // text is bold by default, set to false to use a normal weight
149
- }
150
- image?: {
151
- url?: string
152
- position?: 'left' | 'right' // default = left
153
- height?: string // default = 2rem
154
- marginY?: boolean // default = 0.25rem, set to false to remove this margin
155
- }
156
- border?: {
157
- color?: string // default = rgb(112, 112, 112)
158
- thickness?: number // border width in pixels, default = 1px
159
- rounded?: boolean // rounded corners by default, set to false to remove rounding
160
- }
161
- background?: {
162
- color?: string // default = transparent
163
- }
164
- position?: Position // default = right lower corner (right = 1rem, bottom = 1rem)
165
- }
166
-
167
- type WidgetFrame = {
168
- height?: string // default = full height
169
- width?: string // max-width = 600px, default = 600px
170
- position?: Position // default = on the right of the screen with margins (right = 1rem, bottom = 1rem, top = 2rem)
171
- border?: {
172
- color?: string // default = rgb(112, 112, 112)
173
- thickness?: number // border width in pixels, default = 1px
174
- rounded?: boolean // rounded corners by default, set to false to remove rounding
175
- }
176
- }
177
-
178
- type Position = {
179
- top?: string
180
- bottom?: string
181
- left?: string
182
- right?: string
183
- }
184
- ```
185
-
186
- ## Locales
187
-
188
- If you followed the minimal configuration `addressData` field, the available languages will be automatically retrieved from studio.retorik
189
- depending on the chosen tenant, and the default language will be set from this data.
190
- If graphql is not allowed for this tenant or if no locale is set, `fr-FR` is the default one, without any other language allowed.
191
-
192
- ### Default Locale
193
-
194
- You can override the default locale with the `locales` objet in the `config`. There are two mechanisms, and of course each one functions only if the
195
- chosen language is available in studio.retorik. You can either :
196
- - choose the default language to use with the field `default`
197
- - choose to use the browser's language as default with putting the `getDefaultFromBrowser` field to `true`
198
-
199
- The chosen locale will be compared with the array of those retrieved from studio.retorik, and set as default if present in this array.
200
-
201
- ### Dynamically set the locale
202
-
203
- You can dynamically set the current locale by using the CustomEvent `changeRetorikLocale`, giving the wanted locale in the detail in the `locale` field.
204
- ```
205
- const changeLocaleEvent = new CustomEvent('changeRetorikLocale', {
206
- detail: {
207
- locale: 'en-US'
208
- }
209
- })
210
-
211
- document.dispatchEvent(changeLocaleEvent)
212
- ```
213
- The locale sent inside the event will also be compared with the array of those retrieved from studio.retorik, and set if present in this array.
214
-
215
- ## Development
216
-
217
- Navigate to the root of the folder 'retorik-framework'.
218
- Install the packages with npm
219
-
220
- ```bash
221
- npm install
222
- ```
223
-
224
- Launch the auto-package tool and let it run
225
-
226
- ```bash
227
- npm start
228
- ```
229
-
230
- Navigate to the folder 'example'.
231
- Same steps as before :
232
-
233
- ```bash
234
- npm install
235
- npm start
236
- ```
237
-
238
- Npm start launches a local server on localhost:3000 which renders the app, as if used as a React app importing the packages.
239
- Modifying the code inside the 'example' or 'src' folders auto-updates the display on localhost:3000
240
-
241
- ## About the animation
242
-
243
- Your animations MUST follow the following rules
244
-
245
- ### Folder architecture
246
-
247
- The parameter 'agentData' in the props of the component 'retorikAgent' is an URL so that the framework is able to load the animations.
248
- This URL must lead to a folder with the following architecture :
249
-
250
- ```
251
- └── <folder_name>
252
- ├── webm
253
- │ ├── small
254
- │ │ ├── Move
255
- │ │ │ ├── ns
256
- │ │ │ │ ├── Explain1_ns.webm
257
- │ │ │ │ ├── ...
258
- │ │ │ │ ├── Explain<x>_ns.webm
259
- │ │ │ │ ├── Idle1_ns.webm
260
- │ │ │ │ ├── ...
261
- │ │ │ │ └── Idle<x>_ns.webm
262
- │ │ │ └── sp
263
- │ │ │ ├── Explain1_sp.webm
264
- │ │ │ ├── ...
265
- │ │ │ ├── Explain<x>_sp.webm
266
- │ │ │ ├── Idle1_sp.webm
267
- │ │ │ ├── ...
268
- │ │ │ └── Idle<x>_sp.webm
269
- │ │ ├── Still
270
- │ │ │ ├── ns
271
- │ │ │ │ ├── Still1_ns.webm
272
- │ │ │ │ ├── ...
273
- │ │ │ │ └── Still<x>_ns.webm
274
- │ │ │ └── sp
275
- │ │ │ ├── Still1_sp.webm
276
- │ │ │ ├── ...
277
- │ │ │ └── Still<x>_sp.webm
278
- │ │ ├── <custom>
279
- │ │ │ ├── ns
280
- │ │ │ │ ├── <custom>1_ns.webm
281
- │ │ │ │ ├── ...
282
- │ │ │ │ └── <custom><x>_ns.webm
283
- │ │ │ └── sp
284
- │ │ │ ├── <custom>1_sp.webm
285
- │ │ │ ├── ...
286
- │ │ │ └── <custom><x>_sp.webm
287
- │ │ └── ...
288
- │ ├── medium
289
- │ │ └── <same as small>
290
- │ └── large
291
- │ └── <same as small>
292
- ├── mp4
293
- │ ├── small
294
- │ │ └── <same as webm with mp4 files>
295
- │ ├── medium
296
- │ │ └── <same as webm with mp4 files>
297
- │ └── large
298
- │ └── <same as webm with mp4 files>
299
- └── manifest.json
300
- ```
301
-
302
- Webm / mp4 are used in different browsers (mostly mp4 for Safari, webm for the others).
303
- The 3 sub-folders small, medium and large contain the animations which are scaled for different screen sizes. The sizes below are thoses used basicaly :
304
-
305
- - small : 480x480 pixels (mobiles)
306
- - medium : 1200x1200 px (laptops / desktops)
307
- - large : 2000x2000 px (very large screens)
308
-
309
- 'ns' and 'sp' sub-folders mean 'no-speak' and 'speak'. In the 'ns' folders are the animations where the character's lips aren't moving and the 'sp' folder contains the same animations, in which the lips are moving to simulate a speech.
310
-
311
- ### Naming convention
312
-
313
- Only the folders 'Move' and 'Still' are necessary. The folder 'Move' contains the basic animation that are displayed when the character is performing an action, and is divided in 2 main categories :
314
-
315
- - Idle : animation where the character moves while there is no text to speak
316
- - Explain : animation where the character makes movements to explain something while speaking.
317
-
318
- The folder 'Still' contains the animations where the character stays still. These are used for transition between each loading of an Idle or Explain animation.
319
-
320
- The other folders contain the animations only usable in a custom queue where the given animations will be played one after another, with a fallback to the normal behavior when every animation has been played.
321
-
322
- Each animation file MUST follow this pattern :
323
-
324
- ```
325
- 'Move' folder :
326
- <Explain|Idle><index>_<ns|sp>.<webm|mp4>
327
-
328
- 'Still' folder :
329
- <Still><index>_<ns|sp>.<webm|mp4>
330
-
331
- <other_folder> folder :
332
- <other_folder><index>_<ns|sp>.<webm|mp4>
333
- ```
334
-
335
- The index begins at 1 and goes one by one up to 99. There MUST be an index even if there is only 1 animation in the folder.
336
-
337
- For example :
338
-
339
- ```
340
- └── <folder_name>
341
- ├── webm
342
- │ ├── small
343
- │ │ ├── Chatting
344
- │ │ │ ├── ns
345
- │ │ │ │ ├── Chatting1_ns.webm
346
- │ │ │ │ └── Chatting2_ns.webm
347
- │ │ │ └── sp
348
- │ │ │ ├── Chatting1_sp.webm
349
- │ │ │ └── Chatting2_sp.webm
350
- ```
351
-
352
- ### Manifest.json
353
-
354
- At the root of the main folder reached when using the URL, there has to be a 'manifest.json' file containing some data related to the animations :
355
-
356
- - gender : 'male' | 'female' | 'other' : the gender of the character, used to choose a correct voice inside the framework
357
- - name : the name of the agent displayed in the framework
358
- - portrait : link to the portrait image displayed in the widget or mobile in text conversation mode
359
- - data : contains the number of animations related to each folder. The mandatoty keys are "idle", "explain" and "still". For every other animation folder, there must be a pair "key" : value with the name of the folder (lowercase) as key and the number of animations available as value.
360
-
361
- For example if you have :
362
-
363
- - a male character
364
- - 5 Explain animations
365
- - 3 Idle animations
366
- - 1 Still animation
367
- - taking the example above, 2 Chatting animations
368
- the manifest.json file will be as follows :
369
-
370
- ```tsx
371
- {
372
- "gender": "male",
373
- "name": "Léa",
374
- "portrait": "portrait_cropped.png",
375
- "data": {
376
- "idle": 3,
377
- "explain": 5,
378
- "still": 1,
379
- "chatting": 2
380
- }
381
- }
382
- ```
383
-
384
- With these data, the chatbot inside the framework will be able to use the animations and switch from one to another depending on the situation.
385
-
386
- ## Actions and events
387
-
388
- ### Keep the animations playing no-speak even while a speech is played
389
-
390
- Two customEvents allow you to prevent or allow the animations from playing the speak ones.
391
- These events are linked to the document, and can be called anywhere as follows :
392
-
393
- ```tsx
394
- /* Allow speak animations : */
395
- document.dispatchEvent(new CustomEvent('allowChatbotSpeakAnimationsEvent'))
396
- /* Prevent speak animations : */
397
- document.dispatchEvent(new CustomEvent('preventChatbotSpeakAnimationsEvent'))
398
- ```
399
-
400
- ### Change the voice used for speak without changing the complete agent
401
-
402
- When you change the agentData in the props of the RetorikAgent component, its gender is taken in account to get a correct voice each time a text is spoken. If you want
403
- to use different voice from the basic one or want to use a voice from the other gender, you can use the prop 'customVoice'. The custom voice is taken in account before the gender of the agent, so you can use a male voice even with a female agent, and inversely. See the type of customVoice below :
404
-
405
- ```tsx
406
- type CustomVoice = {
407
- voice?: string
408
- gender?: 'male' | 'female' | 'other'
409
- }
410
- ```
411
-
412
- You can either use :
413
-
414
- - a special voice if you know its name among the set of Azure neural voices, for example the default English voices are 'AriaNeural' (female) and 'GuyNeural' (male). Be aware that using this forces the language to the one linked to the chosen voice.
415
- - the default voice using only the gender. As the voice is selected depending the locale in the activity, the first voice within the set of Azure neural voices matching both gender and locale is chosen.
416
-
417
-
418
- ### Menus and extensions
419
-
420
- Menu entries are customizable and expandable
421
- ## Menu types
422
- You can use 3 types of menu :
423
- - BaseMenu using the views available inside Retorik Framework :
424
- ```tsx
425
- type BaseMenu = {
426
- view: AvailableViews
427
- indice: number
428
- }
429
- ```
430
-
431
- - CustomMenu using the custom data from your side :
432
- ```tsx
433
- type CustomMenu = {
434
- icon: JSX.Element;
435
- clickHandler?: () => void;
436
- label: LocalizedStrings | string;
437
- customDisplay?: string;
438
- indice: number
439
- };
440
- ```
441
-
442
- - BaseSubMenu with smaller cards for sub-functionalities
443
- ```tsx
444
- type BaseSubMenu = {
445
- view: AvailableSubViews
446
- indice: number
447
- }
448
- ```
449
- ## Menu disposition in desktop mode
450
- ![](./example/public/images/readme/menus.PNG)
451
-
452
- You can have several custom menus. They will stack one under another.
453
-
454
- ## Base menu
455
- In the configuration object, `baseMenu` property is available to add or remove base menu entries
456
-
457
- `baseMenu` is an array of type `BaseMenu` | `CustomMenu`.
458
-
459
- Here is the default value :
460
-
461
- ```js
462
- baseMenu:[
463
- { view: AvailableViews.home, indice: 1 }
464
- ]
465
- ```
466
-
467
- ## Additionnal menu & page
468
- You can add additionnal entry that redirect to an external component with the property `customMenu` in the configuration object.
469
-
470
- `customMenu` is an array of type `CustomMenu`.
471
-
472
- External components can be passed to the `RetorikMainComponentProps` when creating the `RetorikAgent` or the `RetorikWidget` component :
473
-
474
- ```tsx
475
- externalComponents: Array<{ name: string; component: JSX.Element }>
476
- ```
477
-
478
- - `customDisplay` and `externalComponents` properties need to match and make the connection between menu entry and external component. They allow to inject an external component which will be displayed in full screen in the framework
479
- - The complete menu is ordered by the `indice` property present in the basic and custom menus
480
-
481
- You can also trigger the opening of the custom screen externaly using the `setCurrentCustomView` function that takes as parameter a `CustomMenu` object
482
-
483
- ## Submenu
484
- Basically contains history and tutorial functionnalities. You can add custom items inside, with the same behaviour as in base or custom menus.
485
-
486
- `subMemu` is an array of type `BaseSubMenu | CustomMenu`:
487
-
488
- ### Events sent and received
489
- Most of the time, these events are used in a commonJs way, as we provide functions carrying the same task that you can import from the package.
490
- You can find all the events in the 2 next sections.
491
-
492
- ## Events sent by Retorik Framework
493
- - `retorikChangeLocale` : CustomEvent, detail: { locale: string } -> event sent when the locale is changed inside the retorik framework. The detail is an object which key 'locale' contains the new locale as string
494
- - `retorikSpeakStart` : Event -> sent on speech start
495
- - `retorikSpeakStop` : Event -> sent on speech end / error
496
- - `newsEnded` : Event -> sent when all news have been read in news view
497
- - `retorikSpeechRecognitionEnded` : CustomEvent, detail : string | undefined -> event sent at the end of a speech recognition. The detail field contains the text spoken as a string | undefined
498
-
499
- ## Events with listeners in Retorik Framework
500
- - `cancelSpeech` : Event linked to document -> cancels current speech if there is one
501
- - `retorikSendActivity` : CustomEvent linked to document, detail : Object of type WebchatActivity -> uses the internal process to send an activity to the bot
502
- - `retorikStartListening` : Event linked to the document -> begins speech recognition in Retorik Framework
503
- - `retorikDisplaySubtitles` : CustomEvent linked to document, detail : boolean -> sets displaySubtitles state to the content of detail (true / false)
504
- - `sendPlayAnimationEvent` : CustomEvent linked to the document, detail : { queue : Array<string> } -> sets a queue of animations to be played by the Body Engine Sprite
505
-
506
- ## License
507
-
508
- MIT © [DAVI](https://github.com/DAVI)
1
+ # retorik-framework
2
+
3
+ ![types](https://camo.githubusercontent.com/0d1fa0bafb9d3d26ac598799ca1d0bf767fc28a41d3f718d404433b392b9a5cd/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f74797065732f73637275622d6a732e737667)
4
+ ![licence](https://badges.frapsoft.com/os/mit/mit.png)
5
+
6
+ Documentation under progress
Binary file