@memori.ai/memori-react 2.18.7 → 2.18.9

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.
@@ -122,8 +122,18 @@ const typeMessage = (
122
122
  hasBatchQueued,
123
123
  },
124
124
  });
125
-
126
125
  document.dispatchEvent(e);
126
+
127
+ const isSafariIOS =
128
+ window.navigator.userAgent.includes('Safari') &&
129
+ !window.navigator.userAgent.includes('Chrome') &&
130
+ /iPad|iPhone|iPod/.test(navigator.userAgent);
131
+
132
+ if (isSafariIOS) {
133
+ setTimeout(() => {
134
+ document.dispatchEvent(new CustomEvent('MemoriEndSpeak'));
135
+ }, 300);
136
+ }
127
137
  };
128
138
  const typeMessageHidden = (
129
139
  message: string,
@@ -189,6 +199,11 @@ const typeBatchMessages = (
189
199
  ?.hasAttribute('disabled');
190
200
  }
191
201
 
202
+ const isSafariIOS =
203
+ window.navigator.userAgent.includes('Safari') &&
204
+ !window.navigator.userAgent.includes('Chrome') &&
205
+ /iPad|iPhone|iPod/.test(navigator.userAgent);
206
+
192
207
  const stepsGenerator = (function* () {
193
208
  yield* messages;
194
209
  })();
@@ -200,20 +215,35 @@ const typeBatchMessages = (
200
215
  const step = next.value;
201
216
 
202
217
  if (step) {
218
+ if (!areInputsDisabled()) {
219
+ disableInputs();
220
+ }
221
+
222
+ let waitForPrevious = step.waitForPrevious;
223
+ if (isSafariIOS) waitForPrevious = false;
224
+
203
225
  typeMessage(
204
226
  step.message,
205
- step.waitForPrevious,
227
+ waitForPrevious,
206
228
  step.hidden,
207
229
  step.typingText,
208
230
  step.useLoaderTextAsMsg,
209
231
  !next.done
210
232
  );
233
+
234
+ if (isSafariIOS) {
235
+ setTimeout(() => {
236
+ document.dispatchEvent(new CustomEvent('MemoriEndSpeak'));
237
+ reEnableInputs();
238
+ }, 3000);
239
+ }
211
240
  } else if (areInputsDisabled()) {
212
241
  reEnableInputs();
213
242
  }
214
243
 
215
244
  if (next.done) {
216
245
  document.removeEventListener('MemoriEndSpeak', submitNewMessage);
246
+ if (areInputsDisabled()) reEnableInputs();
217
247
  return;
218
248
  }
219
249
  };
@@ -776,13 +806,14 @@ const MemoriWidget = ({
776
806
  /**
777
807
  * Age verification
778
808
  */
779
- const minAge = memori.ageRestriction
780
- ? memori.ageRestriction
781
- : memori.nsfw
782
- ? 18
783
- : memori.enableCompletions
784
- ? 14
785
- : 0;
809
+ const minAge =
810
+ memori.ageRestriction !== undefined
811
+ ? memori.ageRestriction
812
+ : memori.nsfw
813
+ ? 18
814
+ : memori.enableCompletions
815
+ ? 14
816
+ : 0;
786
817
  const [birthDate, setBirthDate] = useState<string | undefined>();
787
818
  const [showAgeVerification, setShowAgeVerification] = useState(false);
788
819
 
@@ -1544,35 +1575,6 @@ const MemoriWidget = ({
1544
1575
  audioContext.resume().then(() => speak(text));
1545
1576
  return;
1546
1577
  }
1547
- if (isIOS && isSafari) {
1548
- audioContext.suspend();
1549
-
1550
- if (isPlayingAudio) {
1551
- try {
1552
- memoriSpeaking = false;
1553
- if (speechSynthesizer) {
1554
- speechSynthesizer.close();
1555
- speechSynthesizer = null;
1556
- }
1557
- if (audioDestination) {
1558
- audioDestination.pause();
1559
- audioDestination.close();
1560
- }
1561
- if (audioContext) {
1562
- // audioContext.close().then(() => {
1563
- // audioContext = new AudioContext();
1564
- // let buffer = audioContext.createBuffer(1, 10000, 22050);
1565
- // let source = audioContext.createBufferSource();
1566
- // source.buffer = buffer;
1567
- // source.connect(audioContext.destination);
1568
- // });
1569
- audioContext.destination.disconnect();
1570
- }
1571
- } catch (e) {
1572
- console.error('stopAudio error: ', e);
1573
- }
1574
- }
1575
- }
1576
1578
  if (audioContext.state === 'closed') {
1577
1579
  audioContext = new AudioContext();
1578
1580
  let buffer = audioContext.createBuffer(1, 10000, 22050);
@@ -1590,7 +1592,9 @@ const MemoriWidget = ({
1590
1592
  }
1591
1593
 
1592
1594
  if (!speechSynthesizer) {
1593
- audioDestination = new speechSdk.SpeakerAudioDestination();
1595
+ if (!isIOS) {
1596
+ audioDestination = new speechSdk.SpeakerAudioDestination();
1597
+ }
1594
1598
  let audioConfig =
1595
1599
  speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
1596
1600
  speechSynthesizer = new speechSdk.SpeechSynthesizer(
@@ -1628,9 +1632,6 @@ const MemoriWidget = ({
1628
1632
  memoriSpeaking = true;
1629
1633
 
1630
1634
  try {
1631
- // if (audioContext.destination.context.state === 'running') {
1632
- // audioContext.destination.disconnect();
1633
- // }
1634
1635
  audioContext.decodeAudioData(result.audioData, function (buffer) {
1635
1636
  source.buffer = buffer;
1636
1637
  source.connect(audioContext.destination);
@@ -1669,11 +1670,13 @@ const MemoriWidget = ({
1669
1670
  speechSynthesizer.close();
1670
1671
  speechSynthesizer = null;
1671
1672
  }
1673
+ emitEndSpeakEvent();
1672
1674
  }
1673
1675
  } else {
1674
1676
  audioContext.resume();
1675
1677
  setIsPlayingAudio(false);
1676
1678
  memoriSpeaking = false;
1679
+ emitEndSpeakEvent();
1677
1680
  }
1678
1681
  },
1679
1682
  error => {
@@ -1681,6 +1684,7 @@ const MemoriWidget = ({
1681
1684
  window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
1682
1685
  setIsPlayingAudio(false);
1683
1686
  memoriSpeaking = false;
1687
+ emitEndSpeakEvent();
1684
1688
  }
1685
1689
  );
1686
1690
 
@@ -52,6 +52,52 @@ Localhost.args = {
52
52
  integrationID: '82f017cc-450b-4c47-acf5-47910d336ce9',
53
53
  };
54
54
 
55
+ const TemplateWithBatchButton: Story<Props> = args => (
56
+ <div>
57
+ <button
58
+ style={{
59
+ position: 'fixed',
60
+ top: '0.5rem',
61
+ left: '0.5rem',
62
+ zIndex: 99999,
63
+ }}
64
+ onClick={() => {
65
+ window.typeBatchMessages([
66
+ {
67
+ message: 'uno di tre',
68
+ hidden: false,
69
+ waitForPrevious: true,
70
+ },
71
+ {
72
+ message: 'due di tre',
73
+ hidden: false,
74
+ waitForPrevious: true,
75
+ },
76
+ {
77
+ message: 'tre di tre',
78
+ hidden: false,
79
+ waitForPrevious: true,
80
+ },
81
+ ]);
82
+ }}
83
+ >
84
+ Start Batch
85
+ </button>
86
+ <Memori {...args} />
87
+ </div>
88
+ );
89
+ export const WithBatch = TemplateWithBatchButton.bind({});
90
+ WithBatch.args = {
91
+ ownerUserName: 'nzambello',
92
+ memoriName: 'Nicola',
93
+ tenantID: 'app.memorytwin.com',
94
+ apiURL: 'https://backend.memori.ai',
95
+ baseURL: 'https://app.memorytwin.com',
96
+ uiLang: 'it',
97
+ showShare: true,
98
+ showSettings: true,
99
+ };
100
+
55
101
  // export const Instruction = Template.bind({});
56
102
  // Instruction.args = {
57
103
  // ownerUserName: 'nzambello',
@@ -65,42 +111,3 @@ Localhost.args = {
65
111
  // pin: 'giver pin',
66
112
  // authToken: 'your login token',
67
113
  // };
68
-
69
- export const DemoSophia = Template.bind({});
70
- DemoSophia.args = {
71
- layout: 'TOTEM',
72
- memoriName: 'Sophia',
73
- ownerUserName: 'francescoimpellizzeri',
74
- memoriID: '57405959-a2c5-4499-adb8-bb8dcc848ad5',
75
- ownerUserID: '44ccefdb-d7a2-447e-9851-2a76be055a40',
76
- tenantID: 'nextpresent.aclambda.online',
77
- apiURL: 'https://backend.memori.ai',
78
- baseURL: 'https://nextpresent.aclambda.online',
79
- uiLang: 'it',
80
- lang: 'it',
81
- showShare: true,
82
- showSettings: true,
83
- integrationID: 'd10bbffd-26f3-4614-a092-15b215d04ffa',
84
- initialQuestion: 'Welcome Totem',
85
- contextVars: 'CONTEXT:TOTEM',
86
- // https://assets.memori.ai/api/v2/asset/6af08bf1-f011-40ea-92a2-699b7b53a53c.glb
87
- };
88
-
89
- export const DemoStefano = Template.bind({});
90
- DemoStefano.args = {
91
- layout: 'TOTEM',
92
- memoriName: 'Stefano Zingoni',
93
- ownerUserName: 'roberta.bianchi',
94
- memoriID: 'd6df4c75-8dfb-4e6d-b19f-193fa8a9bcce',
95
- ownerUserID: 'b242160e-c19c-468f-b7f8-b2dc1ce51045',
96
- tenantID: 'gruppoe.aclambda.online',
97
- apiURL: 'https://backend.memori.ai',
98
- baseURL: 'https://gruppoe.aclambda.online',
99
- uiLang: 'it',
100
- lang: 'it',
101
- showShare: true,
102
- showSettings: true,
103
- contextVars: 'CONTEXT:TOTEM',
104
- integrationID: '5712601d-6174-45e7-bfb1-b4ac71c4ff80',
105
- // https://assets.memori.ai/api/v2/asset/ed50c6a4-37cd-458b-9209-8cabfa256b30.glb
106
- };
package/src/index.tsx CHANGED
@@ -24,8 +24,13 @@ export interface Props {
24
24
  layout?: WidgetProps['layout'];
25
25
  customLayout?: WidgetProps['customLayout'];
26
26
  showShare?: boolean;
27
- showSettings?: boolean;
28
27
  showInstruct?: boolean;
28
+ showInputs?: boolean;
29
+ showDates?: boolean;
30
+ showContextPerLine?: boolean;
31
+ showSettings?: boolean;
32
+ showClear?: boolean;
33
+ showOnlyLastMessages?: boolean;
29
34
  showTypingText?: boolean;
30
35
  height?: number | string;
31
36
  baseURL?: string;
@@ -77,6 +82,11 @@ const Memori: React.FC<Props> = ({
77
82
  showSettings = true,
78
83
  showInstruct = false,
79
84
  showTypingText = false,
85
+ showClear = false,
86
+ showOnlyLastMessages = false,
87
+ showInputs = true,
88
+ showDates = false,
89
+ showContextPerLine = false,
80
90
  height = '100%',
81
91
  baseURL,
82
92
  apiURL = 'https://backend.memori.ai',
@@ -207,6 +217,11 @@ const Memori: React.FC<Props> = ({
207
217
  showSettings={showSettings}
208
218
  showInstruct={showInstruct}
209
219
  showTypingText={showTypingText}
220
+ showClear={showClear}
221
+ showOnlyLastMessages={showOnlyLastMessages}
222
+ showInputs={showInputs}
223
+ showDates={showDates}
224
+ showContextPerLine={showContextPerLine}
210
225
  integration={memori?.integrations?.find(i =>
211
226
  integrationID
212
227
  ? i.integrationID === integrationID
@@ -257,8 +272,13 @@ Memori.propTypes = {
257
272
  ]),
258
273
  customLayout: PropTypes.any,
259
274
  showShare: PropTypes.bool,
260
- showSettings: PropTypes.bool,
261
275
  showInstruct: PropTypes.bool,
276
+ showInputs: PropTypes.bool,
277
+ showDates: PropTypes.bool,
278
+ showContextPerLine: PropTypes.bool,
279
+ showSettings: PropTypes.bool,
280
+ showClear: PropTypes.bool,
281
+ showOnlyLastMessages: PropTypes.bool,
262
282
  showTypingText: PropTypes.bool,
263
283
  height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
264
284
  baseURL: PropTypes.string,