@memori.ai/memori-react 2.9.2 → 2.10.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.
@@ -43,41 +43,19 @@ const getMemoriState = (integrationId) => {
43
43
  let dialogState = JSON.parse(engineState);
44
44
  return dialogState;
45
45
  };
46
- function setNativeValue(element, value) {
47
- var _a, _b, _c, _d;
48
- const valueSetter = (_b = (_a = Object === null || Object === void 0 ? void 0 : Object.getOwnPropertyDescriptor) === null || _a === void 0 ? void 0 : _a.call(Object, element, 'value')) === null || _b === void 0 ? void 0 : _b.set;
49
- const prototype = Object.getPrototypeOf(element);
50
- const prototypeValueSetter = (_d = (_c = Object === null || Object === void 0 ? void 0 : Object.getOwnPropertyDescriptor) === null || _c === void 0 ? void 0 : _c.call(Object, prototype, 'value')) === null || _d === void 0 ? void 0 : _d.set;
51
- if (prototypeValueSetter &&
52
- valueSetter &&
53
- valueSetter !== prototypeValueSetter) {
54
- prototypeValueSetter.call(element, value);
55
- }
56
- else if (valueSetter) {
57
- valueSetter.call(element, value);
58
- }
59
- }
60
- const typeMessage = (message) => {
61
- var _a, _b;
62
- let textarea = document.querySelector('fieldset#chat-fieldset textarea') ||
63
- ((_b = (_a = document
64
- .querySelector('memori-client')) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('fieldset#chat-fieldset textarea'));
65
- if (!textarea)
66
- return;
67
- setNativeValue(textarea, message);
68
- textarea.dispatchEvent(new Event('input', { bubbles: true }));
69
- setTimeout(() => {
70
- var _a, _b;
71
- let sendButton = document.querySelector('button.memori-chat-inputs--send') ||
72
- ((_b = (_a = document
73
- .querySelector('memori-client')) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('button.memori-chat-inputs--send'));
74
- if (!sendButton)
75
- return;
76
- sendButton.click();
77
- }, 100);
46
+ const typeMessage = (message, hidden = false) => {
47
+ const e = new CustomEvent('MemoriTextEntered', {
48
+ detail: {
49
+ text: message,
50
+ hidden,
51
+ },
52
+ });
53
+ document.dispatchEvent(e);
78
54
  };
55
+ const typeMessageHidden = (message) => typeMessage(message, true);
79
56
  window.getMemoriState = getMemoriState;
80
57
  window.typeMessage = typeMessage;
58
+ window.typeMessageHidden = typeMessageHidden;
81
59
  let recognizer;
82
60
  let speechConfig;
83
61
  let speechSynthesizer;
@@ -85,6 +63,7 @@ let audioDestination;
85
63
  let audioContext;
86
64
  let memoriPassword;
87
65
  let speakerMuted = false;
66
+ let memoriSpeaking = false;
88
67
  const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integration, layout = 'DEFAULT', customLayout, showInstruct = false, showShare, preview = false, embed = false, showInputs = true, showDates = false, showContextPerLine = false, showSettings = true, height = '100vh', secret, baseUrl = 'https://app.twincreator.com', apiUrl = 'https://backend.memori.ai', initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, }) => {
89
68
  var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t, _u, _v, _w, _x, _y;
90
69
  const { t, i18n } = useTranslation();
@@ -120,6 +99,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
120
99
  const [hideEmissions, setHideEmissions] = useState(false);
121
100
  useEffect(() => {
122
101
  setIsPlayingAudio(!!speechSynthesizer);
102
+ memoriSpeaking = !!speechSynthesizer;
123
103
  }, [speechSynthesizer]);
124
104
  useEffect(() => {
125
105
  let defaultControlsPosition = 'bottom';
@@ -166,199 +146,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
166
146
  _setPosition(venue);
167
147
  applyPosition(venue);
168
148
  };
169
- const [userMessage, setUserMessage] = useState('');
170
- const onChangeUserMessage = (value) => {
171
- if (!value || value === '\n' || value.trim() === '') {
172
- setUserMessage('');
173
- resetInteractionTimeout();
174
- return;
175
- }
176
- setUserMessage(value);
177
- clearInteractionTimeout();
178
- };
179
- const [listening, setListening] = useState(false);
180
- const [history, setHistory] = useState([]);
181
- const pushMessage = (message) => {
182
- setHistory(history => [...history, { ...message }]);
183
- };
184
- const sendMessage = async (text, media, newSessionId, translate = true, translatedText) => {
185
- var _a, _b, _c, _d, _f;
186
- if (!sessionId || !(text === null || text === void 0 ? void 0 : text.length))
187
- return;
188
- pushMessage({
189
- text: text,
190
- translatedText,
191
- fromUser: true,
192
- media: media !== null && media !== void 0 ? media : [],
193
- initial: !!newSessionId,
194
- });
195
- setMemoriTyping(true);
196
- const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
197
- let msg = text;
198
- if (translate &&
199
- !instruct &&
200
- isMultilanguageEnabled &&
201
- userLang.toUpperCase() !== language.toUpperCase()) {
202
- const translation = await getTranslation(text, language, userLang, baseUrl);
203
- msg = translation.text;
204
- }
205
- const { currentState, ...response } = await postTextEnteredEvent({
206
- sessionId: newSessionId !== null && newSessionId !== void 0 ? newSessionId : sessionId,
207
- text: msg,
208
- });
209
- if (response.resultCode === 0 && currentState) {
210
- const emission = (_f = currentState.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
211
- if (currentState.state === 'X4' && memori.giverTag) {
212
- const { currentState, ...resp } = await postTagChangedEvent(sessionId, memori.giverTag);
213
- if (resp.resultCode === 0) {
214
- setCurrentDialogState(currentState);
215
- if (currentState.emission) {
216
- pushMessage({
217
- text: currentState.emission,
218
- media: currentState.media,
219
- fromUser: false,
220
- });
221
- speak(currentState.emission);
222
- }
223
- }
224
- else {
225
- console.error(response, resp);
226
- message.error(t(getErrori18nKey(resp.resultCode)));
227
- }
228
- }
229
- else if (currentState.state === 'X2d' && memori.giverTag) {
230
- const { currentState, ...resp } = await postTextEnteredEvent({
231
- sessionId: newSessionId !== null && newSessionId !== void 0 ? newSessionId : sessionId,
232
- text: Math.random().toString().substring(2, 8),
233
- });
234
- if (resp.resultCode === 0) {
235
- const { currentState, ...resp } = await postTagChangedEvent(sessionId, memori.giverTag);
236
- if (resp.resultCode === 0) {
237
- setCurrentDialogState(currentState);
238
- if (currentState.emission) {
239
- pushMessage({
240
- text: currentState.emission,
241
- media: currentState.media,
242
- fromUser: false,
243
- });
244
- speak(currentState.emission);
245
- }
246
- }
247
- else {
248
- console.error(response, resp);
249
- message.error(t(getErrori18nKey(resp.resultCode)));
250
- }
251
- }
252
- else {
253
- console.error(response, resp);
254
- message.error(t(getErrori18nKey(resp.resultCode)));
255
- }
256
- }
257
- else if (userLang.toLowerCase() !== language.toLowerCase() &&
258
- emission &&
259
- !instruct &&
260
- isMultilanguageEnabled) {
261
- translateDialogState(currentState, userLang).then(ts => {
262
- if (ts.emission) {
263
- speak(ts.emission);
264
- }
265
- });
266
- }
267
- else {
268
- setCurrentDialogState({
269
- ...currentState,
270
- emission,
271
- });
272
- if (emission) {
273
- pushMessage({
274
- text: emission,
275
- media: currentState.media,
276
- fromUser: false,
277
- generatedByAI: !!currentState.completion,
278
- });
279
- speak(emission);
280
- }
281
- }
282
- }
283
- else if (response.resultCode === 404) {
284
- setHistory(h => [...h.slice(0, h.length - 1)]);
285
- reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(state => {
286
- console.info('session timeout');
287
- if (state === null || state === void 0 ? void 0 : state.sessionID) {
288
- setTimeout(() => {
289
- sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
290
- }, 500);
291
- }
292
- });
293
- }
294
- setMemoriTyping(false);
295
- };
296
- const translateDialogState = async (state, userLang) => {
297
- var _a, _b, _c, _d, _f, _g, _h;
298
- const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
299
- const emission = (_f = state.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
300
- let translatedState = { ...state };
301
- let translatedMsg = null;
302
- if (!emission ||
303
- instruct ||
304
- language.toUpperCase() === userLang.toUpperCase() ||
305
- !isMultilanguageEnabled) {
306
- translatedState = { ...state, emission };
307
- if (emission) {
308
- translatedMsg = {
309
- text: emission,
310
- media: state.media,
311
- fromUser: false,
312
- };
313
- }
314
- }
315
- else {
316
- const t = await getTranslation(emission, userLang, language, baseUrl);
317
- if (state.hints && state.hints.length > 0) {
318
- const translatedHints = await Promise.all(((_g = state.hints) !== null && _g !== void 0 ? _g : []).map(async (hint) => {
319
- var _a;
320
- const tHint = await getTranslation(hint, userLang, language, baseUrl);
321
- return {
322
- text: (_a = tHint === null || tHint === void 0 ? void 0 : tHint.text) !== null && _a !== void 0 ? _a : hint,
323
- originalText: hint,
324
- };
325
- }));
326
- translatedState = {
327
- ...state,
328
- emission: t.text,
329
- translatedHints,
330
- };
331
- }
332
- else {
333
- translatedState = {
334
- ...state,
335
- emission: t.text,
336
- hints: (_h = state.hints) !== null && _h !== void 0 ? _h : (state.state === 'G1' ? currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.hints : []),
337
- };
338
- }
339
- if (t.text.length > 0)
340
- translatedMsg = {
341
- text: t.text,
342
- media: state.media,
343
- fromUser: false,
344
- generatedByAI: !!state.completion,
345
- };
346
- }
347
- setCurrentDialogState(translatedState);
348
- if (translatedMsg) {
349
- pushMessage(translatedMsg);
350
- }
351
- return translatedState;
352
- };
353
- const minAge = memori.ageRestriction
354
- ? memori.ageRestriction
355
- : memori.nsfw
356
- ? 18
357
- : memori.enableCompletions
358
- ? 14
359
- : 0;
360
- const [birthDate, setBirthDate] = useState();
361
- const [showAgeVerification, setShowAgeVerification] = useState(false);
362
149
  const [sessionId, setSessionId] = useState(initialSessionID);
363
150
  const [currentDialogState, _setCurrentDialogState] = useState();
364
151
  const setCurrentDialogState = (state) => {
@@ -607,6 +394,201 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
607
394
  restoreGiverTag();
608
395
  };
609
396
  }, []);
397
+ const [userMessage, setUserMessage] = useState('');
398
+ const onChangeUserMessage = (value) => {
399
+ if (!value || value === '\n' || value.trim() === '') {
400
+ setUserMessage('');
401
+ resetInteractionTimeout();
402
+ return;
403
+ }
404
+ setUserMessage(value);
405
+ clearInteractionTimeout();
406
+ };
407
+ const [listening, setListening] = useState(false);
408
+ const [history, setHistory] = useState([]);
409
+ const pushMessage = (message) => {
410
+ setHistory(history => [...history, { ...message }]);
411
+ };
412
+ const sendMessage = useCallback(async (text, media, newSessionId, translate = true, translatedText, hidden = false) => {
413
+ var _a, _b, _c, _d, _f;
414
+ const sessionID = newSessionId || sessionId;
415
+ if (!sessionID || !(text === null || text === void 0 ? void 0 : text.length))
416
+ return;
417
+ if (!hidden)
418
+ pushMessage({
419
+ text: text,
420
+ translatedText,
421
+ fromUser: true,
422
+ media: media !== null && media !== void 0 ? media : [],
423
+ initial: !!newSessionId,
424
+ });
425
+ setMemoriTyping(true);
426
+ const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
427
+ let msg = text;
428
+ if (translate &&
429
+ !instruct &&
430
+ isMultilanguageEnabled &&
431
+ userLang.toUpperCase() !== language.toUpperCase()) {
432
+ const translation = await getTranslation(text, language, userLang, baseUrl);
433
+ msg = translation.text;
434
+ }
435
+ const { currentState, ...response } = await postTextEnteredEvent({
436
+ sessionId: sessionID,
437
+ text: msg,
438
+ });
439
+ if (response.resultCode === 0 && currentState) {
440
+ const emission = (_f = currentState.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
441
+ if (currentState.state === 'X4' && memori.giverTag) {
442
+ const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
443
+ if (resp.resultCode === 0) {
444
+ setCurrentDialogState(currentState);
445
+ if (currentState.emission) {
446
+ pushMessage({
447
+ text: currentState.emission,
448
+ media: currentState.media,
449
+ fromUser: false,
450
+ });
451
+ speak(currentState.emission);
452
+ }
453
+ }
454
+ else {
455
+ console.error(response, resp);
456
+ message.error(t(getErrori18nKey(resp.resultCode)));
457
+ }
458
+ }
459
+ else if (currentState.state === 'X2d' && memori.giverTag) {
460
+ const { currentState, ...resp } = await postTextEnteredEvent({
461
+ sessionId: sessionID,
462
+ text: Math.random().toString().substring(2, 8),
463
+ });
464
+ if (resp.resultCode === 0) {
465
+ const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
466
+ if (resp.resultCode === 0) {
467
+ setCurrentDialogState(currentState);
468
+ if (currentState.emission) {
469
+ pushMessage({
470
+ text: currentState.emission,
471
+ media: currentState.media,
472
+ fromUser: false,
473
+ });
474
+ speak(currentState.emission);
475
+ }
476
+ }
477
+ else {
478
+ console.error(response, resp);
479
+ message.error(t(getErrori18nKey(resp.resultCode)));
480
+ }
481
+ }
482
+ else {
483
+ console.error(response, resp);
484
+ message.error(t(getErrori18nKey(resp.resultCode)));
485
+ }
486
+ }
487
+ else if (userLang.toLowerCase() !== language.toLowerCase() &&
488
+ emission &&
489
+ !instruct &&
490
+ isMultilanguageEnabled) {
491
+ translateDialogState(currentState, userLang).then(ts => {
492
+ if (ts.emission) {
493
+ speak(ts.emission);
494
+ }
495
+ });
496
+ }
497
+ else {
498
+ setCurrentDialogState({
499
+ ...currentState,
500
+ emission,
501
+ });
502
+ if (emission) {
503
+ pushMessage({
504
+ text: emission,
505
+ media: currentState.media,
506
+ fromUser: false,
507
+ generatedByAI: !!currentState.completion,
508
+ });
509
+ speak(emission);
510
+ }
511
+ }
512
+ }
513
+ else if (response.resultCode === 404) {
514
+ setHistory(h => [...h.slice(0, h.length - 1)]);
515
+ reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(state => {
516
+ console.info('session timeout');
517
+ if (state === null || state === void 0 ? void 0 : state.sessionID) {
518
+ setTimeout(() => {
519
+ sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
520
+ }, 500);
521
+ }
522
+ });
523
+ }
524
+ setMemoriTyping(false);
525
+ }, [sessionId]);
526
+ const translateDialogState = async (state, userLang) => {
527
+ var _a, _b, _c, _d, _f, _g, _h;
528
+ const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
529
+ const emission = (_f = state.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
530
+ let translatedState = { ...state };
531
+ let translatedMsg = null;
532
+ if (!emission ||
533
+ instruct ||
534
+ language.toUpperCase() === userLang.toUpperCase() ||
535
+ !isMultilanguageEnabled) {
536
+ translatedState = { ...state, emission };
537
+ if (emission) {
538
+ translatedMsg = {
539
+ text: emission,
540
+ media: state.media,
541
+ fromUser: false,
542
+ };
543
+ }
544
+ }
545
+ else {
546
+ const t = await getTranslation(emission, userLang, language, baseUrl);
547
+ if (state.hints && state.hints.length > 0) {
548
+ const translatedHints = await Promise.all(((_g = state.hints) !== null && _g !== void 0 ? _g : []).map(async (hint) => {
549
+ var _a;
550
+ const tHint = await getTranslation(hint, userLang, language, baseUrl);
551
+ return {
552
+ text: (_a = tHint === null || tHint === void 0 ? void 0 : tHint.text) !== null && _a !== void 0 ? _a : hint,
553
+ originalText: hint,
554
+ };
555
+ }));
556
+ translatedState = {
557
+ ...state,
558
+ emission: t.text,
559
+ translatedHints,
560
+ };
561
+ }
562
+ else {
563
+ translatedState = {
564
+ ...state,
565
+ emission: t.text,
566
+ hints: (_h = state.hints) !== null && _h !== void 0 ? _h : (state.state === 'G1' ? currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.hints : []),
567
+ };
568
+ }
569
+ if (t.text.length > 0)
570
+ translatedMsg = {
571
+ text: t.text,
572
+ media: state.media,
573
+ fromUser: false,
574
+ generatedByAI: !!state.completion,
575
+ };
576
+ }
577
+ setCurrentDialogState(translatedState);
578
+ if (translatedMsg) {
579
+ pushMessage(translatedMsg);
580
+ }
581
+ return translatedState;
582
+ };
583
+ const minAge = memori.ageRestriction
584
+ ? memori.ageRestriction
585
+ : memori.nsfw
586
+ ? 18
587
+ : memori.enableCompletions
588
+ ? 14
589
+ : 0;
590
+ const [birthDate, setBirthDate] = useState();
591
+ const [showAgeVerification, setShowAgeVerification] = useState(false);
610
592
  const [userInteractionTimeout, setUserInteractionTimeout] = useState();
611
593
  const timeoutRef = useRef();
612
594
  const clearInteractionTimeout = () => {
@@ -876,6 +858,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
876
858
  if (preview)
877
859
  return;
878
860
  if (muteSpeaker || speakerMuted) {
861
+ memoriSpeaking = false;
879
862
  if (continuousSpeech) {
880
863
  setListeningTimeout();
881
864
  }
@@ -894,6 +877,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
894
877
  audioContext.suspend();
895
878
  if (isPlayingAudio) {
896
879
  try {
880
+ memoriSpeaking = false;
897
881
  if (speechSynthesizer) {
898
882
  speechSynthesizer.close();
899
883
  speechSynthesizer = null;
@@ -934,15 +918,18 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
934
918
  const source = audioContext.createBufferSource();
935
919
  source.addEventListener('ended', () => {
936
920
  setIsPlayingAudio(false);
921
+ memoriSpeaking = false;
937
922
  });
938
923
  audioDestination.onAudioEnd = () => {
939
924
  setIsPlayingAudio(false);
925
+ memoriSpeaking = false;
940
926
  source.disconnect();
941
927
  onEndSpeakStartListen();
942
928
  };
943
929
  speechSynthesizer.speakSsmlAsync(`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(userLang)}"><voice name="${getTTSVoice(userLang)}"><s>${replaceTextWithPhonemes(escapeHTML(text), userLang.toLowerCase())}</s></voice></speak>`, result => {
944
930
  if (result) {
945
931
  setIsPlayingAudio(true);
932
+ memoriSpeaking = true;
946
933
  try {
947
934
  audioContext.decodeAudioData(result.audioData, function (buffer) {
948
935
  source.buffer = buffer;
@@ -956,6 +943,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
956
943
  audioContext.state === 'closed') {
957
944
  source.disconnect();
958
945
  setIsPlayingAudio(false);
946
+ memoriSpeaking = false;
959
947
  }
960
948
  else if (audioContext.state === 'interrupted') {
961
949
  audioContext.resume();
@@ -971,6 +959,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
971
959
  console.error('speak error: ', e);
972
960
  window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
973
961
  setIsPlayingAudio(false);
962
+ memoriSpeaking = false;
974
963
  if (speechSynthesizer) {
975
964
  speechSynthesizer.close();
976
965
  speechSynthesizer = null;
@@ -980,16 +969,19 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
980
969
  else {
981
970
  audioContext.resume();
982
971
  setIsPlayingAudio(false);
972
+ memoriSpeaking = false;
983
973
  }
984
974
  }, error => {
985
975
  console.error('speak:', error);
986
976
  window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
987
977
  setIsPlayingAudio(false);
978
+ memoriSpeaking = false;
988
979
  });
989
980
  setMemoriTyping(false);
990
981
  };
991
982
  const stopAudio = () => {
992
983
  setIsPlayingAudio(false);
984
+ memoriSpeaking = false;
993
985
  try {
994
986
  if (speechSynthesizer) {
995
987
  speechSynthesizer.close();
@@ -1346,6 +1338,27 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
1346
1338
  stopAudio();
1347
1339
  sendMessage(text, undefined, undefined, false, translatedText);
1348
1340
  };
1341
+ const memoriTextEnteredHandler = useCallback((e) => {
1342
+ var _a;
1343
+ const { text, hidden } = e.detail;
1344
+ const sessionID = sessionId || ((_a = window.getMemoriState()) === null || _a === void 0 ? void 0 : _a.sessionID);
1345
+ if (text) {
1346
+ if (!speakerMuted && (memoriSpeaking || memoriTyping)) {
1347
+ setTimeout(() => {
1348
+ memoriTextEnteredHandler(e);
1349
+ }, 1000);
1350
+ }
1351
+ else {
1352
+ sendMessage(text, undefined, sessionID, undefined, undefined, hidden);
1353
+ }
1354
+ }
1355
+ }, [sessionId, isPlayingAudio, memoriTyping]);
1356
+ useEffect(() => {
1357
+ document.addEventListener('MemoriTextEntered', memoriTextEnteredHandler);
1358
+ return () => {
1359
+ document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
1360
+ };
1361
+ }, []);
1349
1362
  const onClickStart = useCallback(async (session) => {
1350
1363
  const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1351
1364
  const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;