quickblox-react-ui-kit 0.2.2 → 0.2.4

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.
Files changed (85) hide show
  1. package/dist/CommonTypes/FunctionResult.d.ts +5 -1
  2. package/dist/Data/DefaultConfigurations.d.ts +2 -2
  3. package/dist/Data/source/remote/Mapper/MessageDTOMapper.d.ts +3 -1
  4. package/dist/Domain/use_cases/ai/AIAnswerAssistUseCase.d.ts +13 -0
  5. package/dist/Domain/use_cases/ai/AIAnswerAssistWithProxyUseCase.d.ts +13 -0
  6. package/dist/Domain/use_cases/ai/AIRephraseUseCase.d.ts +15 -0
  7. package/dist/Domain/use_cases/ai/AIRephraseWithProxyUseCase.d.ts +15 -0
  8. package/dist/Domain/use_cases/ai/AITranslateUseCase.d.ts +14 -0
  9. package/dist/Domain/use_cases/ai/AITranslateWithProxyUseCase.d.ts +14 -0
  10. package/dist/Presentation/Views/Base/BaseViewModel.d.ts +2 -0
  11. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.d.ts +10 -1
  12. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIWidgetActions/AIWidgetActions.d.ts +3 -2
  13. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone.d.ts +5 -13
  14. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.d.ts +2 -10
  15. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.d.ts +2 -0
  16. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.d.ts +2 -10
  17. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.d.ts +2 -0
  18. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.d.ts +2 -10
  19. package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.d.ts +2 -0
  20. package/dist/Presentation/components/UI/Dialogs/MessagesView/DefaultAttachmentComponent/DefaultAttachmentComponent.d.ts +7 -0
  21. package/dist/Presentation/components/UI/Dialogs/MessagesView/ErrorToast/ErrorToast.d.ts +7 -0
  22. package/dist/Presentation/components/UI/Dialogs/MessagesView/InComingMessage/InComingMessage.d.ts +3 -1
  23. package/dist/Presentation/components/UI/Dialogs/PreviewDialog/PreviewAudioFile/PreviewAudioFile.d.ts +7 -0
  24. package/dist/Presentation/components/UI/Dialogs/PreviewDialog/PreviewDefaultFile/PreviewDefaultFile.d.ts +7 -0
  25. package/dist/Presentation/components/UI/Dialogs/PreviewDialog/PreviewImageFile/PreviewImageFile.d.ts +8 -0
  26. package/dist/Presentation/components/UI/Dialogs/PreviewDialog/PreviewVideoFile/PreviewVideoFile.d.ts +7 -0
  27. package/dist/Presentation/components/UI/svgs/Icons/AIWidgets/BotIcon/BotIcon.d.ts +4 -0
  28. package/dist/QBconfig.d.ts +14 -3
  29. package/dist/index-ui.js +384 -35
  30. package/dist/utils/utils.d.ts +9 -0
  31. package/global.d.ts +12 -4
  32. package/package.json +5 -1
  33. package/src/App.tsx +3 -1
  34. package/src/CommonTypes/FunctionResult.ts +6 -1
  35. package/src/Data/DefaultConfigurations.ts +155 -19
  36. package/src/Data/source/remote/Mapper/DialogDTOMapper.ts +3 -0
  37. package/src/Data/source/remote/Mapper/MessageDTOMapper.ts +55 -2
  38. package/src/Data/source/remote/RemoteDataSource.ts +2 -1
  39. package/src/Domain/use_cases/ai/AIAnswerAssistUseCase.ts +69 -0
  40. package/src/Domain/use_cases/ai/AIAnswerAssistWithProxyUseCase.ts +71 -0
  41. package/src/Domain/use_cases/ai/AIRephraseUseCase.ts +89 -0
  42. package/src/Domain/use_cases/ai/AIRephraseWithProxyUseCase.ts +75 -0
  43. package/src/Domain/use_cases/ai/AITranslateUseCase.ts +76 -0
  44. package/src/Domain/use_cases/ai/AITranslateWithProxyUseCase.ts +79 -0
  45. package/src/Presentation/Views/Base/BaseViewModel.ts +2 -0
  46. package/src/Presentation/Views/Dialogs/Dialogs.tsx +2 -2
  47. package/src/Presentation/Views/Dialogs/useDialogsViewModel.ts +4 -1
  48. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.ts +18 -2
  49. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIWidgetActions/AIWidgetActions.tsx +10 -4
  50. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone.ts +29 -15
  51. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.tsx +24 -40
  52. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.tsx +83 -0
  53. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.tsx +40 -41
  54. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.tsx +102 -0
  55. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.tsx +27 -44
  56. package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.tsx +89 -0
  57. package/src/Presentation/components/UI/Dialogs/MessagesView/DefaultAttachmentComponent/DefaultAttachmentComponent.scss +76 -0
  58. package/src/Presentation/components/UI/Dialogs/MessagesView/DefaultAttachmentComponent/DefaultAttachmentComponent.tsx +34 -0
  59. package/src/Presentation/components/UI/Dialogs/MessagesView/ErrorToast/ErrorToast.scss +26 -0
  60. package/src/Presentation/components/UI/Dialogs/MessagesView/ErrorToast/ErrorToast.tsx +25 -0
  61. package/src/Presentation/components/UI/Dialogs/MessagesView/InComingMessage/InComingMessage.scss +4 -6
  62. package/src/Presentation/components/UI/Dialogs/MessagesView/InComingMessage/InComingMessage.tsx +93 -405
  63. package/src/Presentation/components/UI/Dialogs/MessagesView/MessagesView.scss +2 -3
  64. package/src/Presentation/components/UI/Dialogs/MessagesView/MessagesView.tsx +578 -415
  65. package/src/Presentation/components/UI/Dialogs/MessagesView/VideoAttachmentComponent/VideoAttachmentComponent.scss +6 -2
  66. package/src/Presentation/components/UI/Dialogs/MessagesView/useMessagesViewModel.ts +13 -3
  67. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewAudioFile/PreviewAudioFile.scss +62 -0
  68. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewAudioFile/PreviewAudioFile.tsx +25 -0
  69. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewDefaultFile/PreviewDefaultFile.scss +61 -0
  70. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewDefaultFile/PreviewDefaultFile.tsx +32 -0
  71. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewDialog.scss +2 -2
  72. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewDialog.tsx +50 -2
  73. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewImageFile/PreviewImageFile.scss +40 -0
  74. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewImageFile/PreviewImageFile.tsx +26 -0
  75. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewVideoFile/PreviewVideoFile.scss +62 -0
  76. package/src/Presentation/components/UI/Dialogs/PreviewDialog/PreviewVideoFile/PreviewVideoFile.tsx +25 -0
  77. package/src/Presentation/components/UI/svgs/Icons/AIWidgets/BotIcon/BotIcon.svg +5 -0
  78. package/src/Presentation/components/UI/svgs/Icons/AIWidgets/BotIcon/BotIcon.tsx +50 -0
  79. package/src/Presentation/components/layouts/Desktop/QuickBloxUIKitDesktopLayout.tsx +41 -42
  80. package/src/Presentation/components/providers/QuickBloxUIKitProvider/QuickBloxUIKitProvider.tsx +1 -1
  81. package/src/Presentation/components/providers/QuickBloxUIKitProvider/useQbInitializedDataContext.ts +15 -14
  82. package/src/QBconfig.ts +156 -10
  83. package/src/package_artan_react_ui.json +13 -9
  84. package/src/package_original.json +5 -1
  85. package/src/utils/utils.ts +63 -0
@@ -1,3 +1,12 @@
1
+ import { MessageEntity } from '../Domain/entity/MessageEntity';
2
+ import { IChatMessage } from '../Data/source/AISource';
3
+ import { Tone } from '../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
1
4
  export declare const completeSentence: (text?: string) => string;
2
5
  export declare const tokenCounter: (text?: string) => number;
3
6
  export declare const loopToLimitTokens: <T>(limit: number, data: T[], getValue?: (item: T) => string, tokens?: number) => T[];
7
+ export declare class AIUtils {
8
+ static createTranslatePrompt(textToSend: string, language?: string): string;
9
+ static createAnswerAssistPrompt(textToSend: string): string;
10
+ static createRephrasePrompt(textToSend: string, tone?: Tone): string;
11
+ static messageEntitiesToIChatMessageCollection(messageEntities: MessageEntity[], currentUserId: number | undefined, MAX_TOKENS?: number): IChatMessage[];
12
+ }
package/global.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ interface Tone {
2
+ name: string;
3
+ description: string;
4
+ iconEmoji: string;
5
+ }
6
+
1
7
  type Dictionary<T> = Record<string, T>;
2
8
 
3
9
  type DictionaryByKey<T, V> = {
@@ -21,20 +27,22 @@ type ProxyConfig = {
21
27
  api: string;
22
28
  servername: string;
23
29
  port: string;
24
- sessionToken: string;
25
30
  };
26
31
  interface WidgetConfig {
27
32
  apiKey: string;
28
33
  useDefault: boolean;
34
+ maxTokens: number;
29
35
  proxyConfig: ProxyConfig;
30
36
  }
31
37
 
32
- interface AITranslateWidgetConfig extends WidgetConfig{
33
- defaultLanguage: string; languages: string[];
38
+ interface AITranslateWidgetConfig extends WidgetConfig {
39
+ defaultLanguage: string;
40
+ languages: string[];
34
41
  }
35
42
 
36
43
  interface AIRephraseWidgetConfig extends WidgetConfig {
37
- defaultTone: string
44
+ defaultTone: string;
45
+ Tones: Tone[];
38
46
  }
39
47
 
40
48
  interface QBConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickblox-react-ui-kit",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "main": "dist/index-ui.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -8,6 +8,10 @@
8
8
  "@types/react": "^18.0.26",
9
9
  "@types/react-dom": "^18.0.9",
10
10
  "classnames": "^2.3.2",
11
+ "qb-ai-answer-assistant": "^0.1.0",
12
+ "qb-ai-core": "^0.1.0",
13
+ "qb-ai-rephrase": "^0.1.0",
14
+ "qb-ai-translate": "^0.1.0",
11
15
  "react": "^18.2.0",
12
16
  "react-dom": "^18.2.0",
13
17
  "react-router-dom": "^6.11.1",
package/src/App.tsx CHANGED
@@ -191,7 +191,9 @@ function App() {
191
191
 
192
192
  useEffect(() => {
193
193
  console.log('0. APP INIT');
194
- prepareSDK(currentUser).catch();
194
+ prepareSDK(currentUser).catch((er) => {
195
+ console.log(er);
196
+ });
195
197
  }, []);
196
198
  //
197
199
  // const { proxyConfig } = QBConfig.configAIApi.AIAnswerAssistWidgetConfig;
@@ -1,3 +1,5 @@
1
+ import {Tone} from "../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone";
2
+
1
3
  export type FunctionResult<T> = {
2
4
  result: T | T[] | boolean;
3
5
  error: any;
@@ -7,10 +9,12 @@ export type ProxyConfig = {
7
9
  api: string;
8
10
  servername: string;
9
11
  port: string;
10
- sessionToken: string;
11
12
  };
12
13
  export interface WidgetConfig {
14
+ organizationName: string;
15
+ openAIModel: string;
13
16
  apiKey: string;
17
+ maxTokens: number;
14
18
  useDefault: boolean;
15
19
  proxyConfig: ProxyConfig;
16
20
  }
@@ -22,6 +26,7 @@ export interface AITranslateWidgetConfig extends WidgetConfig {
22
26
 
23
27
  export interface AIRephraseWidgetConfig extends WidgetConfig {
24
28
  defaultTone: string;
29
+ Tones: Tone[];
25
30
  }
26
31
 
27
32
  export interface QBConfig {
@@ -9,6 +9,7 @@ const supportedLanguagesForIATranslate: string[] = [
9
9
  'German',
10
10
  ];
11
11
 
12
+ // ["en-US", "zh-CN", "ja-JP"]
12
13
  const languageBCP47: Record<string, string> = {
13
14
  'ar-SA': 'Arabic',
14
15
  'bn-BD': 'Bangla',
@@ -80,15 +81,17 @@ export class DefaultConfigurations {
80
81
  api: 'v1/chat/completions',
81
82
  servername: 'https://api.openai.com',
82
83
  port: '',
83
- sessionToken: '',
84
84
  };
85
85
  }
86
86
 
87
- static getDefaultLanguageForAITranslate(): string {
87
+ static getDefaultLanguageForAITranslate(
88
+ configAITranslate: AITranslateWidgetConfig,
89
+ ): string {
88
90
  let languageForAITranslate = 'English';
89
- const { defaultLanguage } =
91
+ const defaultLanguage: string =
92
+ configAITranslate.defaultLanguage ||
90
93
  DefaultConfigurations.getDefaultQBConfig().configAIApi
91
- .AITranslateWidgetConfig;
94
+ .AITranslateWidgetConfig.defaultLanguage;
92
95
 
93
96
  if (
94
97
  defaultLanguage.length > 0 &&
@@ -106,11 +109,14 @@ export class DefaultConfigurations {
106
109
  return languageForAITranslate;
107
110
  }
108
111
 
109
- static getAdditionalLanguagesForAITranslate(): string[] {
112
+ static getAdditionalLanguagesForAITranslate(
113
+ configAITranslate: AITranslateWidgetConfig,
114
+ ): string[] {
110
115
  const additionalLanguages: string[] = [];
111
- const { languages } =
116
+ const languages: string[] =
117
+ configAITranslate.languages ||
112
118
  DefaultConfigurations.getDefaultQBConfig().configAIApi
113
- .AITranslateWidgetConfig;
119
+ .AITranslateWidgetConfig.languages;
114
120
 
115
121
  languages.forEach((item) => {
116
122
  if (supportedLanguagesForIATranslate.includes(item)) {
@@ -135,43 +141,109 @@ export class DefaultConfigurations {
135
141
  },
136
142
  configAIApi: {
137
143
  AIAnswerAssistWidgetConfig: {
144
+ organizationName: 'Quickblox',
145
+ openAIModel: 'gpt-3.5-turbo',
138
146
  apiKey: '',
147
+ maxTokens: 3584,
139
148
  useDefault: true,
140
149
  proxyConfig: {
141
150
  api: 'v1/chat/completions',
142
151
  servername: 'https://api.openai.com/',
143
152
  port: '',
144
- sessionToken: '',
145
153
  },
146
154
  },
147
155
  AITranslateWidgetConfig: {
156
+ organizationName: 'Quickblox',
157
+ openAIModel: 'gpt-3.5-turbo',
148
158
  apiKey: '',
159
+ maxTokens: 3584,
149
160
  useDefault: true,
150
161
  defaultLanguage: 'English',
151
- languages: [
152
- 'English',
153
- 'Spanish',
154
- 'French',
155
- 'Portuguese',
156
- 'German',
157
- 'Ukrainian',
158
- ],
162
+ languages: ['English', 'French', 'Portuguese', 'German', 'Ukrainian'],
159
163
  proxyConfig: {
160
164
  api: 'v1/chat/completions',
161
- servername: 'https://api.openai.com/',
165
+ servername: '',
162
166
  port: '',
163
- sessionToken: '',
164
167
  },
168
+ // proxyConfig: {
169
+ // api: 'v1/chat/completions',
170
+ // servername: 'http://localhost',
171
+ // port: '3012',
172
+ // },
165
173
  },
166
174
  AIRephraseWidgetConfig: {
175
+ organizationName: 'Quickblox',
176
+ openAIModel: 'gpt-3.5-turbo',
167
177
  apiKey: '',
178
+ maxTokens: 3584,
168
179
  useDefault: true,
169
180
  defaultTone: 'Professional',
181
+ Tones: [
182
+ {
183
+ name: 'Professional Tone',
184
+ description:
185
+ 'This would edit messages to sound more formal, using technical vocabulary, clear sentence structures, and maintaining a respectful tone. It would avoid colloquial language and ensure appropriate salutations and sign-offs',
186
+ iconEmoji: '👔',
187
+ },
188
+ {
189
+ name: 'Friendly Tone',
190
+ description:
191
+ 'This would adjust messages to reflect a casual, friendly tone. It would incorporate casual language, use emoticons, exclamation points, and other informalities to make the message seem more friendly and approachable.',
192
+ iconEmoji: '🤝',
193
+ },
194
+ {
195
+ name: 'Encouraging Tone',
196
+ description:
197
+ 'This tone would be useful for motivation and encouragement. It would include positive words, affirmations, and express support and belief in the recipient.',
198
+ iconEmoji: '💪',
199
+ },
200
+ {
201
+ name: 'Empathetic Tone',
202
+ description:
203
+ 'This tone would be utilized to display understanding and empathy. It would involve softer language, acknowledging feelings, and demonstrating compassion and support.',
204
+ iconEmoji: '🤲',
205
+ },
206
+ {
207
+ name: 'Neutral Tone',
208
+ description:
209
+ 'For times when you want to maintain an even, unbiased, and objective tone. It would avoid extreme language and emotive words, opting for clear, straightforward communication.',
210
+ iconEmoji: '😐',
211
+ },
212
+ {
213
+ name: 'Assertive Tone',
214
+ description:
215
+ 'This tone is beneficial for making clear points, standing ground, or in negotiations. It uses direct language, is confident, and does not mince words.',
216
+ iconEmoji: '🔨',
217
+ },
218
+ {
219
+ name: 'Instructive Tone',
220
+ description:
221
+ 'This tone would be useful for tutorials, guides, or other teaching and training materials. It is clear, concise, and walks the reader through steps or processes in a logical manner.',
222
+ iconEmoji: '📖',
223
+ },
224
+ {
225
+ name: 'Persuasive Tone',
226
+ description:
227
+ 'This tone can be used when trying to convince someone or argue a point. It uses persuasive language, powerful words, and logical reasoning.',
228
+ iconEmoji: '☝️',
229
+ },
230
+ {
231
+ name: 'Sarcastic/Ironic Tone',
232
+ description:
233
+ 'This tone can make the communication more humorous or show an ironic stance. It is harder to implement as it requires the AI to understand nuanced language and may not always be taken as intended by the reader.',
234
+ iconEmoji: '😏',
235
+ },
236
+ {
237
+ name: 'Poetic Tone',
238
+ description:
239
+ 'This would add an artistic touch to messages, using figurative language, rhymes, and rhythm to create a more expressive text.',
240
+ iconEmoji: '🎭',
241
+ },
242
+ ],
170
243
  proxyConfig: {
171
244
  api: 'v1/chat/completions',
172
245
  servername: 'https://api.openai.com/',
173
246
  port: '',
174
- sessionToken: '',
175
247
  },
176
248
  },
177
249
  },
@@ -190,6 +262,70 @@ export class DefaultConfigurations {
190
262
  enable: true,
191
263
  },
192
264
  },
265
+ // credentials: {
266
+ // appId: -1,
267
+ // accountKey: '',
268
+ // authKey: '',
269
+ // authSecret: '',
270
+ // sessionToken: '',
271
+ // },
272
+ // configAIApi: {
273
+ // AIAnswerAssistWidgetConfig: {
274
+ // apiKey: '',
275
+ // useDefault: true,
276
+ // proxyConfig: {
277
+ // api: 'v1/chat/completions',
278
+ // servername: 'https://api.openai.com/',
279
+ // port: '',
280
+ // sessionToken: '',
281
+ // },
282
+ // },
283
+ // AITranslateWidgetConfig: {
284
+ // apiKey: '',
285
+ // useDefault: true,
286
+ // defaultLanguage: 'English',
287
+ // languages: [
288
+ // 'English',
289
+ // 'Spanish',
290
+ // 'French',
291
+ // 'Portuguese',
292
+ // 'German',
293
+ // 'Ukrainian',
294
+ // ],
295
+ // proxyConfig: {
296
+ // api: 'v1/chat/completions',
297
+ // servername: 'https://api.openai.com/',
298
+ // port: '',
299
+ // sessionToken: '',
300
+ // },
301
+ // },
302
+ // AIRephraseWidgetConfig: {
303
+ // apiKey: '',
304
+ // useDefault: true,
305
+ // defaultTone: 'Professional',
306
+ // proxyConfig: {
307
+ // api: 'v1/chat/completions',
308
+ // servername: 'https://api.openai.com/',
309
+ // port: '',
310
+ // sessionToken: '',
311
+ // },
312
+ // },
313
+ // },
314
+ // appConfig: {
315
+ // maxFileSize: 10 * 1024 * 1024,
316
+ // sessionTimeOut: 122,
317
+ // chatProtocol: {
318
+ // active: 2,
319
+ // },
320
+ // debug: true,
321
+ // endpoints: {
322
+ // api: 'api.quickblox.com',
323
+ // chat: 'chat.quickblox.com',
324
+ // },
325
+ // streamManagement: {
326
+ // enable: true,
327
+ // },
328
+ // },
193
329
  };
194
330
  }
195
331
 
@@ -61,6 +61,9 @@ export class DialogDTOMapper implements IDTOMapper {
61
61
  dto.lastMessageId = qbDialog.last_message_id || '';
62
62
  dto.lastMessageText = qbDialog.last_message as string;
63
63
  dto.lastMessageDateSent = qbDialog.last_message_date_sent as string;
64
+ // dto.lastMessageDateSent = (
65
+ // parseInt(qbDialog.last_message_date_sent || '0', 10) * 1000
66
+ // ).toString();
64
67
  dto.lastMessageUserId =
65
68
  qbDialog.last_message_user_id === null
66
69
  ? ''
@@ -39,7 +39,10 @@ export class MessageDTOMapper implements IDTOMapper {
39
39
  }
40
40
 
41
41
  // eslint-disable-next-line class-methods-use-this
42
- public static transformAttachment(qbAtts: ChatMessageAttachment[]) {
42
+ public static transformAttachment(
43
+ qbMessage: string,
44
+ qbAtts: ChatMessageAttachment[],
45
+ ) {
43
46
  const result: ChatMessageAttachmentEntity[] = qbAtts.map((item) => {
44
47
  const newItem: ChatMessageAttachmentEntity = {
45
48
  id: item.id,
@@ -57,6 +60,25 @@ export class MessageDTOMapper implements IDTOMapper {
57
60
  url: item.uid && QB.content.privateUrl(item.uid),
58
61
  },
59
62
  };
63
+ const messageParts = MessageDTOMapper.getMessageParts(qbMessage);
64
+
65
+ if (messageParts && messageParts.length > 0) {
66
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
67
+ // 0, 1, 2, 3
68
+ // eslint-disable-next-line prefer-destructuring
69
+ newItem.uid = messageParts[2];
70
+ // eslint-disable-next-line prefer-destructuring
71
+ newItem.name = messageParts[1];
72
+ // eslint-disable-next-line prefer-destructuring
73
+ newItem.type = messageParts[3];
74
+ newItem.url = newItem.uid && QB.content.privateUrl(newItem.uid);
75
+ if (newItem.file) {
76
+ newItem.file.uid = newItem.uid;
77
+ newItem.file.name = newItem.name;
78
+ newItem.file.url = newItem.uid && QB.content.privateUrl(newItem.uid);
79
+ newItem.file.type = newItem.type;
80
+ }
81
+ }
60
82
 
61
83
  return newItem;
62
84
  });
@@ -74,7 +96,7 @@ export class MessageDTOMapper implements IDTOMapper {
74
96
 
75
97
  dto.id = qbMessage._id;
76
98
  dto.dialogId = qbMessage.chat_dialog_id;
77
- dto.message = qbMessage.message;
99
+ dto.message = MessageDTOMapper.formatMessage(qbMessage.message);
78
100
  dto.created_at = qbMessage.created_at;
79
101
  dto.date_sent = qbMessage.date_sent * 1000;
80
102
  dto.delivered_ids = qbMessage.delivered_ids ? qbMessage.delivered_ids : [];
@@ -82,6 +104,7 @@ export class MessageDTOMapper implements IDTOMapper {
82
104
 
83
105
  dto.recipient_id = qbMessage.recipient_id ? qbMessage.recipient_id : 0;
84
106
  dto.attachments = MessageDTOMapper.transformAttachment(
107
+ qbMessage.message,
85
108
  qbMessage.attachments ? qbMessage.attachments : [],
86
109
  );
87
110
  dto.read = qbMessage.read;
@@ -98,6 +121,36 @@ export class MessageDTOMapper implements IDTOMapper {
98
121
  return Promise.resolve(dto as TResult);
99
122
  }
100
123
 
124
+ public static formatMessage(qbMessage: string) {
125
+ if (
126
+ qbMessage.includes('MediaContentEntity') ||
127
+ qbMessage.includes('[Attachment]')
128
+ ) {
129
+ const messageParts = qbMessage.split('|');
130
+
131
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
132
+ // 0, 1, 2, 3
133
+ return messageParts[1] || '';
134
+ }
135
+
136
+ return qbMessage;
137
+ }
138
+
139
+ private static getMessageParts(qbMessage: string) {
140
+ if (
141
+ qbMessage.includes('MediaContentEntity') ||
142
+ qbMessage.includes('[Attachment]')
143
+ ) {
144
+ const messageParts = qbMessage.split('|');
145
+
146
+ // val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
147
+ // 0, 1, 2, 3
148
+ return messageParts;
149
+ }
150
+
151
+ return [];
152
+ }
153
+
101
154
  private static validateDTO(messageDTO: RemoteMessageDTO) {
102
155
  const messageDTOValidator: DtoValidator<RemoteMessageDTO> = {
103
156
  created_at(v: unknown): v is RemoteMessageDTO['created_at'] {
@@ -371,7 +371,7 @@ export class RemoteDataSource implements IRemoteDataSource {
371
371
  const resultMessage = new RemoteMessageDTO();
372
372
 
373
373
  resultMessage.id = message.id;
374
- resultMessage.message = message.body;
374
+ resultMessage.message = MessageDTOMapper.formatMessage(message.body);
375
375
  resultMessage.markable = message.markable
376
376
  ? message.markable.toString()
377
377
  : '0';
@@ -394,6 +394,7 @@ export class RemoteDataSource implements IRemoteDataSource {
394
394
 
395
395
  // resultMessage.attachments = message.extension.attachments || [];
396
396
  resultMessage.attachments = MessageDTOMapper.transformAttachment(
397
+ message.body,
397
398
  message.extension.attachments ? message.extension.attachments : [],
398
399
  );
399
400
 
@@ -0,0 +1,69 @@
1
+ // eslint-disable-next-line import/extensions
2
+ import { QBAIAnswerAssistant } from 'qb-ai-answer-assistant';
3
+ import { IChatMessage } from '../../../Data/source/AISource';
4
+ import { IUseCase } from '../base/IUseCase';
5
+
6
+ export class AIAnswerAssistUseCase implements IUseCase<void, string> {
7
+ private textToSend: string;
8
+
9
+ private dialogMessages: IChatMessage[];
10
+
11
+ private servername: string;
12
+
13
+ private api: string;
14
+
15
+ private port: string;
16
+
17
+ private sessionToken: string;
18
+
19
+ private openAIModel: string;
20
+
21
+ constructor(
22
+ textToSend: string,
23
+ dialogMessages: IChatMessage[],
24
+ servername: string,
25
+ api: string,
26
+ port: string,
27
+ sessionToken: string,
28
+ openAIModel = 'gpt-3.5-turbo',
29
+ ) {
30
+ console.log('CONSTRUCTOR AIRephraseUseCase');
31
+ this.api = api;
32
+ this.openAIModel = openAIModel;
33
+ this.port = port;
34
+ this.sessionToken = sessionToken;
35
+ this.textToSend = textToSend;
36
+ this.servername = servername;
37
+ this.dialogMessages = dialogMessages;
38
+ }
39
+
40
+ async execute(): Promise<string> {
41
+ console.log('execute AIRephraseUseCase');
42
+ const settings =
43
+ QBAIAnswerAssistant.createDefaultAIAnswerAssistantSettings();
44
+
45
+ settings.apiKey = this.sessionToken;
46
+ // settings.organization = 'Quickblox';
47
+ settings.model = this.openAIModel;
48
+
49
+ return QBAIAnswerAssistant.createAnswer(
50
+ this.textToSend,
51
+ this.dialogMessages,
52
+ settings,
53
+ );
54
+
55
+ // const prompt = AIUtils.createAnswerAssistPrompt(this.textToSend);
56
+ //
57
+ // //
58
+ // return AISource.getData(
59
+ // prompt,
60
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
61
+ // this.dialogMessages,
62
+ // this.servername,
63
+ // this.api,
64
+ // this.port,
65
+ // this.sessionToken,
66
+ // this.openAIModel,
67
+ // );
68
+ }
69
+ }
@@ -0,0 +1,71 @@
1
+ // eslint-disable-next-line import/extensions
2
+ import { QBAIAnswerAssistant } from 'qb-ai-answer-assistant';
3
+ import { IChatMessage } from '../../../Data/source/AISource';
4
+ import { IUseCase } from '../base/IUseCase';
5
+
6
+ export class AIAnswerAssistWithProxyUseCase implements IUseCase<void, string> {
7
+ private textToSend: string;
8
+
9
+ private dialogMessages: IChatMessage[];
10
+
11
+ private servername: string;
12
+
13
+ private api: string;
14
+
15
+ private port: string;
16
+
17
+ private sessionToken: string;
18
+
19
+ private openAIModel: string;
20
+
21
+ constructor(
22
+ textToSend: string,
23
+ dialogMessages: IChatMessage[],
24
+ servername: string,
25
+ api: string,
26
+ port: string,
27
+ sessionToken: string,
28
+ openAIModel = 'gpt-3.5-turbo',
29
+ ) {
30
+ console.log('CONSTRUCTOR AIRephraseUseCase');
31
+ this.api = api;
32
+ this.openAIModel = openAIModel;
33
+ this.port = port;
34
+ this.sessionToken = sessionToken;
35
+ this.textToSend = textToSend;
36
+ this.servername = servername;
37
+ this.dialogMessages = dialogMessages;
38
+ }
39
+
40
+ async execute(): Promise<string> {
41
+ console.log('execute AIRephraseUseCase');
42
+
43
+ const settings =
44
+ QBAIAnswerAssistant.createDefaultAIAnswerAssistantSettings();
45
+
46
+ settings.token = this.sessionToken;
47
+ // settings.organization = 'Quickblox';
48
+ settings.model = this.openAIModel;
49
+ settings.serverPath = `${this.servername}:${this.port}/${this.api}`;
50
+
51
+ return QBAIAnswerAssistant.createAnswer(
52
+ this.textToSend,
53
+ this.dialogMessages,
54
+ settings,
55
+ );
56
+
57
+ // const prompt = AIUtils.createAnswerAssistPrompt(this.textToSend);
58
+ //
59
+ // //
60
+ // return AISource.getDataWithProxyServer(
61
+ // prompt,
62
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
63
+ // this.dialogMessages,
64
+ // this.servername,
65
+ // this.api,
66
+ // this.port,
67
+ // this.sessionToken,
68
+ // this.openAIModel,
69
+ // );
70
+ }
71
+ }