quickblox-react-ui-kit 0.2.1 → 0.2.3
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/dist/CommonTypes/FunctionResult.d.ts +47 -0
- package/dist/Data/DefaultConfigurations.d.ts +2 -6
- package/dist/Data/source/remote/Mapper/MessageDTOMapper.d.ts +3 -1
- package/dist/Domain/use_cases/ai/AIRephraseUseCase.d.ts +15 -0
- package/dist/Domain/use_cases/ai/AIRephraseWithProxyUseCase.d.ts +15 -0
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.d.ts +6 -0
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.d.ts +2 -10
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.d.ts +2 -0
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.d.ts +2 -10
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.d.ts +2 -0
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.d.ts +2 -10
- package/dist/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.d.ts +2 -0
- package/dist/Presentation/components/providers/QuickBloxUIKitProvider/QuickBloxUIKitProvider.d.ts +1 -1
- package/dist/QBconfig.d.ts +1 -0
- package/dist/index-ui.js +82 -16
- package/global.d.ts +48 -6
- package/package.json +1 -1
- package/src/App.tsx +9 -14
- package/src/CommonTypes/FunctionResult.ts +54 -0
- package/src/Data/DefaultConfigurations.ts +79 -10
- package/src/Data/source/AISource.ts +3 -3
- package/src/Data/source/remote/Mapper/DialogDTOMapper.ts +3 -0
- package/src/Data/source/remote/Mapper/MessageDTOMapper.ts +57 -4
- package/src/Data/source/remote/RemoteDataSource.ts +2 -1
- package/src/Domain/use_cases/ai/AIRephraseUseCase.ts +87 -0
- package/src/Domain/use_cases/ai/AIRephraseWithProxyUseCase.ts +71 -0
- package/src/Presentation/Views/Dialogs/Dialogs.tsx +1 -1
- package/src/Presentation/Views/Dialogs/useDialogsViewModel.ts +4 -1
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/AIMessageWidget.ts +11 -0
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidget.tsx +15 -35
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIAssistAnswerWidgetWithProxy.tsx +79 -0
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidget.tsx +23 -41
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAIRephraseMessageWidgetWithProxy.tsx +86 -0
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidget.tsx +15 -33
- package/src/Presentation/components/UI/Dialogs/MessagesView/AIWidgets/UseDefaultAITranslateWidgetWithProxy.tsx +88 -0
- package/src/Presentation/components/UI/Dialogs/MessagesView/InComingMessage/InComingMessage.scss +2 -2
- package/src/Presentation/components/UI/Dialogs/MessagesView/MessagesView.tsx +19 -17
- package/src/Presentation/components/UI/Dialogs/MessagesView/VideoAttachmentComponent/VideoAttachmentComponent.scss +6 -2
- package/src/Presentation/components/UI/Dialogs/MessagesView/useMessagesViewModel.ts +18 -6
- package/src/Presentation/components/layouts/Desktop/QuickBloxUIKitDesktopLayout.tsx +42 -38
- package/src/Presentation/components/providers/QuickBloxUIKitProvider/QuickBloxUIKitProvider.tsx +8 -7
- package/src/QBconfig.ts +4 -3
- package/src/utils/parse.ts +1 -1
package/global.d.ts
CHANGED
|
@@ -17,14 +17,56 @@ interface DateRange {
|
|
|
17
17
|
to: Date;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
type ProxyConfig = {
|
|
21
|
+
api: string;
|
|
22
|
+
servername: string;
|
|
23
|
+
port: string;
|
|
24
|
+
sessionToken: string;
|
|
25
|
+
};
|
|
26
|
+
interface WidgetConfig {
|
|
27
|
+
apiKey: string;
|
|
28
|
+
useDefault: boolean;
|
|
29
|
+
proxyConfig: ProxyConfig;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AITranslateWidgetConfig extends WidgetConfig{
|
|
33
|
+
defaultLanguage: string; languages: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface AIRephraseWidgetConfig extends WidgetConfig {
|
|
37
|
+
defaultTone: string
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
interface QBConfig {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
credentials: {
|
|
42
|
+
appId: number;
|
|
43
|
+
accountKey: string;
|
|
44
|
+
authKey: string;
|
|
45
|
+
authSecret: string;
|
|
46
|
+
sessionToken: string;
|
|
47
|
+
};
|
|
48
|
+
configAIApi: {
|
|
49
|
+
AIAnswerAssistWidgetConfig: WidgetConfig;
|
|
50
|
+
AITranslateWidgetConfig: AITranslateWidgetConfig;
|
|
51
|
+
AIRephraseWidgetConfig: AIRephraseWidgetConfig;
|
|
25
52
|
};
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
appConfig: {
|
|
54
|
+
maxFileSize: number;
|
|
55
|
+
sessionTimeOut: number;
|
|
56
|
+
chatProtocol: {
|
|
57
|
+
active: number;
|
|
58
|
+
};
|
|
59
|
+
debug: boolean;
|
|
60
|
+
endpoints: {
|
|
61
|
+
api: string;
|
|
62
|
+
chat: string;
|
|
63
|
+
};
|
|
64
|
+
// on: {
|
|
65
|
+
// sessionExpired: (handleResponse: any, retry: any) => Promise<void>;
|
|
66
|
+
// };
|
|
67
|
+
streamManagement: {
|
|
68
|
+
enable: boolean;
|
|
69
|
+
};
|
|
28
70
|
};
|
|
29
71
|
}
|
|
30
72
|
|
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import './App.scss';
|
|
3
3
|
import { Route, Routes, useNavigate } from 'react-router-dom';
|
|
4
|
-
import { QBConfig } from './QBconfig';
|
|
5
4
|
import useQBConnection from './Presentation/components/providers/QuickBloxUIKitProvider/useQBConnection';
|
|
6
5
|
import { LocalDataSource } from './Data/source/local/LocalDataSource';
|
|
7
6
|
import Login from './Presentation/components/layouts/TestStage/LoginView/Login';
|
|
@@ -15,6 +14,7 @@ import {
|
|
|
15
14
|
import QuickBloxUIKitDesktopLayout from './Presentation/components/layouts/Desktop/QuickBloxUIKitDesktopLayout';
|
|
16
15
|
import DefaultTheme from './Presentation/assets/DefaultThemes/DefaultTheme';
|
|
17
16
|
import useQbUIKitDataContext from './Presentation/components/providers/QuickBloxUIKitProvider/useQbUIKitDataContext';
|
|
17
|
+
import { QBConfig } from './QBconfig';
|
|
18
18
|
|
|
19
19
|
function App() {
|
|
20
20
|
// const currentContext = React.useContext(qbDataContext);
|
|
@@ -28,8 +28,8 @@ function App() {
|
|
|
28
28
|
const { connectionRepository } = useQBConnection();
|
|
29
29
|
|
|
30
30
|
const initLoginData: LoginData = {
|
|
31
|
-
login: '',
|
|
32
|
-
password: '',
|
|
31
|
+
login: 'artimed', // vit1
|
|
32
|
+
password: 'quickblox',
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const [currentUser, setCurrentUser] = React.useState(initLoginData);
|
|
@@ -70,7 +70,7 @@ function App() {
|
|
|
70
70
|
authKeyOrAppId: currentContext.InitParams.accountData.authKey,
|
|
71
71
|
authSecret: currentContext.InitParams.accountData.authSecret,
|
|
72
72
|
accountKey: currentContext.InitParams.accountData.accountKey,
|
|
73
|
-
config: QBConfig
|
|
73
|
+
config: QBConfig,
|
|
74
74
|
},
|
|
75
75
|
authData,
|
|
76
76
|
);
|
|
@@ -175,7 +175,7 @@ function App() {
|
|
|
175
175
|
authKeyOrAppId: currentContext.InitParams.accountData.authKey,
|
|
176
176
|
authSecret: currentContext.InitParams.accountData.authSecret,
|
|
177
177
|
accountKey: currentContext.InitParams.accountData.accountKey,
|
|
178
|
-
config: QBConfig
|
|
178
|
+
config: QBConfig,
|
|
179
179
|
},
|
|
180
180
|
data,
|
|
181
181
|
);
|
|
@@ -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;
|
|
@@ -206,14 +208,7 @@ function App() {
|
|
|
206
208
|
maxFileSize={QBConfig.appConfig.maxFileSize}
|
|
207
209
|
// SDK={QB} //init SDK
|
|
208
210
|
accountData={{ ...QBConfig.credentials, sessionToken: '' }}
|
|
209
|
-
|
|
210
|
-
// debug: true,
|
|
211
|
-
// endpoints: {
|
|
212
|
-
// api: 'apilpsgdev.quickblox.com',
|
|
213
|
-
// chat: 'chatlpsgdev.quickblox.com',
|
|
214
|
-
// },
|
|
215
|
-
// webrtc: {},
|
|
216
|
-
// }}
|
|
211
|
+
qbConfig={{ ...QBConfig }}
|
|
217
212
|
loginData={{
|
|
218
213
|
login: currentUser.login,
|
|
219
214
|
password: currentUser.password,
|
|
@@ -2,3 +2,57 @@ export type FunctionResult<T> = {
|
|
|
2
2
|
result: T | T[] | boolean;
|
|
3
3
|
error: any;
|
|
4
4
|
};
|
|
5
|
+
|
|
6
|
+
export type ProxyConfig = {
|
|
7
|
+
api: string;
|
|
8
|
+
servername: string;
|
|
9
|
+
port: string;
|
|
10
|
+
sessionToken: string;
|
|
11
|
+
};
|
|
12
|
+
export interface WidgetConfig {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
useDefault: boolean;
|
|
15
|
+
proxyConfig: ProxyConfig;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AITranslateWidgetConfig extends WidgetConfig {
|
|
19
|
+
defaultLanguage: string;
|
|
20
|
+
languages: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AIRephraseWidgetConfig extends WidgetConfig {
|
|
24
|
+
defaultTone: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface QBConfig {
|
|
28
|
+
credentials: {
|
|
29
|
+
appId: number;
|
|
30
|
+
accountKey: string;
|
|
31
|
+
authKey: string;
|
|
32
|
+
authSecret: string;
|
|
33
|
+
sessionToken: string;
|
|
34
|
+
};
|
|
35
|
+
configAIApi: {
|
|
36
|
+
AIAnswerAssistWidgetConfig: WidgetConfig;
|
|
37
|
+
AITranslateWidgetConfig: AITranslateWidgetConfig;
|
|
38
|
+
AIRephraseWidgetConfig: AIRephraseWidgetConfig;
|
|
39
|
+
};
|
|
40
|
+
appConfig: {
|
|
41
|
+
maxFileSize: number;
|
|
42
|
+
sessionTimeOut: number;
|
|
43
|
+
chatProtocol: {
|
|
44
|
+
active: number;
|
|
45
|
+
};
|
|
46
|
+
debug: boolean;
|
|
47
|
+
endpoints: {
|
|
48
|
+
api: string;
|
|
49
|
+
chat: string;
|
|
50
|
+
};
|
|
51
|
+
// on: {
|
|
52
|
+
// sessionExpired: (handleResponse: any, retry: any) => Promise<void>;
|
|
53
|
+
// };
|
|
54
|
+
streamManagement: {
|
|
55
|
+
enable: boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QBConfig } from '../
|
|
1
|
+
import { ProxyConfig, QBConfig } from '../CommonTypes/FunctionResult';
|
|
2
2
|
|
|
3
3
|
const supportedLanguagesForIATranslate: string[] = [
|
|
4
4
|
'English',
|
|
@@ -74,13 +74,6 @@ const getDefaultSystemLanguage = () => {
|
|
|
74
74
|
return language;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
export type ProxyConfig = {
|
|
78
|
-
api: string;
|
|
79
|
-
servername: string;
|
|
80
|
-
port: string;
|
|
81
|
-
sessionToken: string;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
77
|
export class DefaultConfigurations {
|
|
85
78
|
static getDefaultProxyConfig(): ProxyConfig {
|
|
86
79
|
return {
|
|
@@ -93,7 +86,9 @@ export class DefaultConfigurations {
|
|
|
93
86
|
|
|
94
87
|
static getDefaultLanguageForAITranslate(): string {
|
|
95
88
|
let languageForAITranslate = 'English';
|
|
96
|
-
const { defaultLanguage } =
|
|
89
|
+
const { defaultLanguage } =
|
|
90
|
+
DefaultConfigurations.getDefaultQBConfig().configAIApi
|
|
91
|
+
.AITranslateWidgetConfig;
|
|
97
92
|
|
|
98
93
|
if (
|
|
99
94
|
defaultLanguage.length > 0 &&
|
|
@@ -113,7 +108,9 @@ export class DefaultConfigurations {
|
|
|
113
108
|
|
|
114
109
|
static getAdditionalLanguagesForAITranslate(): string[] {
|
|
115
110
|
const additionalLanguages: string[] = [];
|
|
116
|
-
const { languages } =
|
|
111
|
+
const { languages } =
|
|
112
|
+
DefaultConfigurations.getDefaultQBConfig().configAIApi
|
|
113
|
+
.AITranslateWidgetConfig;
|
|
117
114
|
|
|
118
115
|
languages.forEach((item) => {
|
|
119
116
|
if (supportedLanguagesForIATranslate.includes(item)) {
|
|
@@ -125,4 +122,76 @@ export class DefaultConfigurations {
|
|
|
125
122
|
|
|
126
123
|
return additionalLanguages;
|
|
127
124
|
}
|
|
125
|
+
|
|
126
|
+
//
|
|
127
|
+
static getDefaultQBConfig(): QBConfig {
|
|
128
|
+
return {
|
|
129
|
+
credentials: {
|
|
130
|
+
appId: -1,
|
|
131
|
+
accountKey: '',
|
|
132
|
+
authKey: '',
|
|
133
|
+
authSecret: '',
|
|
134
|
+
sessionToken: '',
|
|
135
|
+
},
|
|
136
|
+
configAIApi: {
|
|
137
|
+
AIAnswerAssistWidgetConfig: {
|
|
138
|
+
apiKey: '',
|
|
139
|
+
useDefault: true,
|
|
140
|
+
proxyConfig: {
|
|
141
|
+
api: 'v1/chat/completions',
|
|
142
|
+
servername: 'https://api.openai.com/',
|
|
143
|
+
port: '',
|
|
144
|
+
sessionToken: '',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
AITranslateWidgetConfig: {
|
|
148
|
+
apiKey: '',
|
|
149
|
+
useDefault: true,
|
|
150
|
+
defaultLanguage: 'English',
|
|
151
|
+
languages: [
|
|
152
|
+
'English',
|
|
153
|
+
'Spanish',
|
|
154
|
+
'French',
|
|
155
|
+
'Portuguese',
|
|
156
|
+
'German',
|
|
157
|
+
'Ukrainian',
|
|
158
|
+
],
|
|
159
|
+
proxyConfig: {
|
|
160
|
+
api: 'v1/chat/completions',
|
|
161
|
+
servername: 'https://api.openai.com/',
|
|
162
|
+
port: '',
|
|
163
|
+
sessionToken: '',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
AIRephraseWidgetConfig: {
|
|
167
|
+
apiKey: '',
|
|
168
|
+
useDefault: true,
|
|
169
|
+
defaultTone: 'Professional',
|
|
170
|
+
proxyConfig: {
|
|
171
|
+
api: 'v1/chat/completions',
|
|
172
|
+
servername: 'https://api.openai.com/',
|
|
173
|
+
port: '',
|
|
174
|
+
sessionToken: '',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
appConfig: {
|
|
179
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
180
|
+
sessionTimeOut: 122,
|
|
181
|
+
chatProtocol: {
|
|
182
|
+
active: 2,
|
|
183
|
+
},
|
|
184
|
+
debug: true,
|
|
185
|
+
endpoints: {
|
|
186
|
+
api: 'api.quickblox.com',
|
|
187
|
+
chat: 'chat.quickblox.com',
|
|
188
|
+
},
|
|
189
|
+
streamManagement: {
|
|
190
|
+
enable: true,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//
|
|
128
197
|
}
|
|
@@ -45,7 +45,7 @@ export class AISource {
|
|
|
45
45
|
|
|
46
46
|
return outputMessage;
|
|
47
47
|
} catch (err) {
|
|
48
|
-
const outputMessage = stringifyError(err);
|
|
48
|
+
const outputMessage: string = stringifyError(err);
|
|
49
49
|
|
|
50
50
|
throw new RepositoryException(outputMessage, -1);
|
|
51
51
|
}
|
|
@@ -85,7 +85,7 @@ export class AISource {
|
|
|
85
85
|
|
|
86
86
|
return outputMessage;
|
|
87
87
|
} catch (err) {
|
|
88
|
-
const outputMessage = stringifyError(err);
|
|
88
|
+
const outputMessage: string = stringifyError(err);
|
|
89
89
|
|
|
90
90
|
throw new RepositoryException(outputMessage, -1);
|
|
91
91
|
}
|
|
@@ -125,7 +125,7 @@ export class AISource {
|
|
|
125
125
|
|
|
126
126
|
return outputMessage;
|
|
127
127
|
} catch (err) {
|
|
128
|
-
const outputMessage = stringifyError(err);
|
|
128
|
+
const outputMessage: string = stringifyError(err);
|
|
129
129
|
|
|
130
130
|
throw new RepositoryException(outputMessage, -1);
|
|
131
131
|
}
|
|
@@ -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(
|
|
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,
|
|
@@ -47,16 +50,35 @@ export class MessageDTOMapper implements IDTOMapper {
|
|
|
47
50
|
size: item.size,
|
|
48
51
|
type: item.type,
|
|
49
52
|
uid: item.uid,
|
|
50
|
-
url: item.
|
|
53
|
+
url: item.uid && QB.content.privateUrl(item.uid),
|
|
51
54
|
file: {
|
|
52
55
|
id: item.id,
|
|
53
56
|
name: item.name,
|
|
54
57
|
size: item.size,
|
|
55
58
|
type: item.type,
|
|
56
59
|
uid: item.uid || '',
|
|
57
|
-
url: item.
|
|
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,87 @@
|
|
|
1
|
+
// eslint-disable-next-line import/extensions
|
|
2
|
+
import { AISource, IChatMessage } from '../../../Data/source/AISource';
|
|
3
|
+
import { IUseCase } from '../base/IUseCase';
|
|
4
|
+
import {
|
|
5
|
+
Tone,
|
|
6
|
+
toneToString,
|
|
7
|
+
} from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
|
|
8
|
+
|
|
9
|
+
export class AIRephraseUseCase implements IUseCase<void, string> {
|
|
10
|
+
private textToSend: string;
|
|
11
|
+
|
|
12
|
+
private tone: Tone;
|
|
13
|
+
|
|
14
|
+
private dialogMessages: IChatMessage[];
|
|
15
|
+
|
|
16
|
+
private servername: string;
|
|
17
|
+
|
|
18
|
+
private api: string;
|
|
19
|
+
|
|
20
|
+
private port: string;
|
|
21
|
+
|
|
22
|
+
private sessionToken: string;
|
|
23
|
+
|
|
24
|
+
private openAIModel: string;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
textToSend: string,
|
|
28
|
+
tone: Tone,
|
|
29
|
+
dialogMessages: IChatMessage[],
|
|
30
|
+
servername: string,
|
|
31
|
+
api: string,
|
|
32
|
+
port: string,
|
|
33
|
+
sessionToken: string,
|
|
34
|
+
openAIModel = 'gpt-3.5-turbo',
|
|
35
|
+
) {
|
|
36
|
+
console.log('CONSTRUCTOR AIRephraseUseCase');
|
|
37
|
+
this.api = api;
|
|
38
|
+
this.openAIModel = openAIModel;
|
|
39
|
+
this.port = port;
|
|
40
|
+
this.sessionToken = sessionToken;
|
|
41
|
+
this.textToSend = textToSend;
|
|
42
|
+
this.tone = tone;
|
|
43
|
+
this.servername = servername;
|
|
44
|
+
this.dialogMessages = dialogMessages;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async execute(): Promise<string> {
|
|
48
|
+
console.log('execute AIRephraseUseCase');
|
|
49
|
+
|
|
50
|
+
let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
|
|
51
|
+
|
|
52
|
+
if (this.tone) {
|
|
53
|
+
prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
|
|
54
|
+
this.tone,
|
|
55
|
+
)} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
|
|
56
|
+
this.textToSend
|
|
57
|
+
}"`;
|
|
58
|
+
}
|
|
59
|
+
//
|
|
60
|
+
|
|
61
|
+
// return await AISource.getData(
|
|
62
|
+
// prompt,
|
|
63
|
+
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
64
|
+
// context,
|
|
65
|
+
// servername,
|
|
66
|
+
// api,
|
|
67
|
+
// port,
|
|
68
|
+
// apiKeyOrSessionToken,
|
|
69
|
+
// ).then((data) => {
|
|
70
|
+
// setTextFromWidgetToContent(data);
|
|
71
|
+
//
|
|
72
|
+
// return data;
|
|
73
|
+
// });
|
|
74
|
+
|
|
75
|
+
//
|
|
76
|
+
return AISource.getData(
|
|
77
|
+
prompt,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
79
|
+
this.dialogMessages,
|
|
80
|
+
this.servername,
|
|
81
|
+
this.api,
|
|
82
|
+
this.port,
|
|
83
|
+
this.sessionToken,
|
|
84
|
+
this.openAIModel,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// eslint-disable-next-line import/extensions
|
|
2
|
+
import { AISource, IChatMessage } from '../../../Data/source/AISource';
|
|
3
|
+
import { IUseCase } from '../base/IUseCase';
|
|
4
|
+
import {
|
|
5
|
+
Tone,
|
|
6
|
+
toneToString,
|
|
7
|
+
} from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
|
|
8
|
+
|
|
9
|
+
export class AIRephraseWithProxyUseCase implements IUseCase<void, string> {
|
|
10
|
+
private textToSend: string;
|
|
11
|
+
|
|
12
|
+
private tone: Tone;
|
|
13
|
+
|
|
14
|
+
private dialogMessages: IChatMessage[];
|
|
15
|
+
|
|
16
|
+
private servername: string;
|
|
17
|
+
|
|
18
|
+
private api: string;
|
|
19
|
+
|
|
20
|
+
private port: string;
|
|
21
|
+
|
|
22
|
+
private sessionToken: string;
|
|
23
|
+
|
|
24
|
+
private openAIModel: string;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
textToSend: string,
|
|
28
|
+
tone: Tone,
|
|
29
|
+
dialogMessages: IChatMessage[],
|
|
30
|
+
servername: string,
|
|
31
|
+
api: string,
|
|
32
|
+
port: string,
|
|
33
|
+
sessionToken: string,
|
|
34
|
+
openAIModel = 'gpt-3.5-turbo',
|
|
35
|
+
) {
|
|
36
|
+
console.log('CONSTRUCTOR AIRephraseUseCase');
|
|
37
|
+
this.api = api;
|
|
38
|
+
this.openAIModel = openAIModel;
|
|
39
|
+
this.port = port;
|
|
40
|
+
this.sessionToken = sessionToken;
|
|
41
|
+
this.textToSend = textToSend;
|
|
42
|
+
this.tone = tone;
|
|
43
|
+
this.servername = servername;
|
|
44
|
+
this.dialogMessages = dialogMessages;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async execute(): Promise<string> {
|
|
48
|
+
console.log('execute AIRephraseUseCase');
|
|
49
|
+
|
|
50
|
+
let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
|
|
51
|
+
|
|
52
|
+
if (this.tone) {
|
|
53
|
+
prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
|
|
54
|
+
this.tone,
|
|
55
|
+
)} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
|
|
56
|
+
this.textToSend
|
|
57
|
+
}"`;
|
|
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
|
+
}
|
|
@@ -191,7 +191,7 @@ const DialogsComponent: React.FC<DialogsProps> = ({
|
|
|
191
191
|
if (Number.isNaN(dateInt)) {
|
|
192
192
|
return formattedValue;
|
|
193
193
|
}
|
|
194
|
-
formattedValue = getTimeShort24hFormat(dateInt);
|
|
194
|
+
formattedValue = getTimeShort24hFormat(dateInt * 1000);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
return formattedValue;
|
|
@@ -67,7 +67,10 @@ export default function useDialogsViewModel(
|
|
|
67
67
|
|
|
68
68
|
const dialogUpdateHandler = (dialogInfo: DialogEventInfo) => {
|
|
69
69
|
console.log('call dialogUpdateHandler in useDialogsViewModel');
|
|
70
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
dialogInfo.eventMessageType === EventMessageType.SystemMessage
|
|
72
|
+
// || dialogInfo.eventMessageType === EventMessageType.RegularMessage
|
|
73
|
+
) {
|
|
71
74
|
if (dialogInfo.notificationTypes === NotificationTypes.UPDATE_DIALOG) {
|
|
72
75
|
if (dialogInfo.messageInfo) {
|
|
73
76
|
const { dialogId } = dialogInfo.messageInfo;
|
|
@@ -4,6 +4,17 @@ import {
|
|
|
4
4
|
FunctionTypeStringWithContextToString,
|
|
5
5
|
} from '../../../../../Views/Base/BaseViewModel';
|
|
6
6
|
|
|
7
|
+
export interface MessageWidgetProps {
|
|
8
|
+
// https://api.openai.com/v1/chat/completions'
|
|
9
|
+
// api: 'v1/chat/completions',
|
|
10
|
+
// servername: 'https://myproxy.com',
|
|
11
|
+
// https://func270519800.azurewebsites.net/api/TranslateTextToEng
|
|
12
|
+
servername: string;
|
|
13
|
+
api: string;
|
|
14
|
+
port: string;
|
|
15
|
+
apiKeyOrSessionToken: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export interface AIWidget {
|
|
8
19
|
renderWidget: FunctionTypeJSXElement;
|
|
9
20
|
}
|