core-services-sdk 1.3.45 → 1.3.47
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/package.json +1 -1
- package/src/ids/generators.js +7 -0
- package/src/ids/prefixes.js +3 -0
- package/src/index.js +1 -0
- package/src/instant-messages/im-platform.js +18 -0
- package/src/instant-messages/index.js +4 -0
- package/src/instant-messages/message-type.js +153 -0
- package/src/instant-messages/message-types.js +127 -0
- package/src/instant-messages/message-unified-mapper.js +247 -0
- package/tests/ids/prefixes.unit.test.js +1 -0
- package/tests/instant-messages/applications.unit.test.js +27 -0
- package/tests/instant-messages/message-type.unit.test.js +185 -0
- package/tests/instant-messages/message-types.unit.test.js +93 -0
- package/tests/instant-messages/message-unified-mapper-telegram.unit.test.js +66 -0
- package/tests/instant-messages/message-unified-mapper-united.unit.test.js +94 -0
- package/tests/instant-messages/message-unified-mapper-whatsapp.unit.test.js +65 -0
- package/tests/instant-messages/mock-messages/telegram/contact.json +27 -0
- package/tests/instant-messages/mock-messages/telegram/document.json +43 -0
- package/tests/instant-messages/mock-messages/telegram/location.json +26 -0
- package/tests/instant-messages/mock-messages/telegram/photo.json +52 -0
- package/tests/instant-messages/mock-messages/telegram/poll.json +45 -0
- package/tests/instant-messages/mock-messages/telegram/text.json +63 -0
- package/tests/instant-messages/mock-messages/telegram/video.json +46 -0
- package/tests/instant-messages/mock-messages/telegram/video_note.json +43 -0
- package/tests/instant-messages/mock-messages/telegram/voice.json +29 -0
- package/tests/instant-messages/mock-messages/whatsapp/audio.json +42 -0
- package/tests/instant-messages/mock-messages/whatsapp/contacts.json +50 -0
- package/tests/instant-messages/mock-messages/whatsapp/document.json +42 -0
- package/tests/instant-messages/mock-messages/whatsapp/image.json +41 -0
- package/tests/instant-messages/mock-messages/whatsapp/location.json +40 -0
- package/tests/instant-messages/mock-messages/whatsapp/reaction.json +40 -0
- package/tests/instant-messages/mock-messages/whatsapp/sticker.json +42 -0
- package/tests/instant-messages/mock-messages/whatsapp/text.json +39 -0
- package/tests/instant-messages/mock-messages/whatsapp/video.json +41 -0
- package/types/ids/generators.d.ts +2 -0
- package/types/ids/prefixes.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/instant-messages/im-platform.d.ts +13 -0
- package/types/instant-messages/index.d.ts +4 -0
- package/types/instant-messages/message-type.d.ts +24 -0
- package/types/instant-messages/message-types.d.ts +62 -0
- package/types/instant-messages/message-unified-mapper.d.ts +356 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function isItMediaType(
|
|
2
|
+
mediaType: string,
|
|
3
|
+
): (params: { imMessage: any }) => boolean
|
|
4
|
+
export function isMessageTypeof(
|
|
5
|
+
typeOfMessage: string,
|
|
6
|
+
): (params: { imMessage: any }) => boolean
|
|
7
|
+
export function isCallbackQuery({ imMessage }: { imMessage: any }): boolean
|
|
8
|
+
export const isItPoll: (params: { imMessage: any }) => boolean
|
|
9
|
+
export const isItMessage: (params: { imMessage: any }) => boolean
|
|
10
|
+
export const isItVoice: (params: { imMessage: any }) => boolean
|
|
11
|
+
export const isItVideo: (params: { imMessage: any }) => boolean
|
|
12
|
+
export const isItPhoto: (params: { imMessage: any }) => boolean
|
|
13
|
+
export const isItFreeText: (params: { imMessage: any }) => boolean
|
|
14
|
+
export const isItSticker: (params: { imMessage: any }) => boolean
|
|
15
|
+
export const isItContact: (params: { imMessage: any }) => boolean
|
|
16
|
+
export const isItLocation: (params: { imMessage: any }) => boolean
|
|
17
|
+
export const isItDocument: (params: { imMessage: any }) => boolean
|
|
18
|
+
export const isItVideoNote: (params: { imMessage: any }) => boolean
|
|
19
|
+
export const isItButtonClick: (params: { imMessage: any }) => boolean
|
|
20
|
+
export function getTelegramMessageType({
|
|
21
|
+
imMessage,
|
|
22
|
+
}: {
|
|
23
|
+
imMessage: any
|
|
24
|
+
}): string
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* *
|
|
3
|
+
*/
|
|
4
|
+
export type MESSAGE_MEDIA_TYPE = string
|
|
5
|
+
export namespace MESSAGE_MEDIA_TYPE {
|
|
6
|
+
let TEXT: string
|
|
7
|
+
let POLL: string
|
|
8
|
+
let VIDEO: string
|
|
9
|
+
let PHOTO: string
|
|
10
|
+
let IMAGE: string
|
|
11
|
+
let VOICE: string
|
|
12
|
+
let AUDIO: string
|
|
13
|
+
let STICKER: string
|
|
14
|
+
let CONTACT: string
|
|
15
|
+
let MESSAGE: string
|
|
16
|
+
let REACTION: string
|
|
17
|
+
let DOCUMENT: string
|
|
18
|
+
let LOCATION: string
|
|
19
|
+
let CONTACTS: string
|
|
20
|
+
let VIDEO_NOTE: string
|
|
21
|
+
let BUTTON_CLICK: string
|
|
22
|
+
let BUTTON_CLICK_MULTIPLE: string
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* *
|
|
26
|
+
*/
|
|
27
|
+
export type MESSAGE_TYPE = string
|
|
28
|
+
export namespace MESSAGE_TYPE {
|
|
29
|
+
let MESSAGE_1: string
|
|
30
|
+
export { MESSAGE_1 as MESSAGE }
|
|
31
|
+
import BUTTON_CLICK_1 = MESSAGE_MEDIA_TYPE.BUTTON_CLICK
|
|
32
|
+
export { BUTTON_CLICK_1 as BUTTON_CLICK }
|
|
33
|
+
import BUTTON_CLICK_MULTIPLE_1 = MESSAGE_MEDIA_TYPE.BUTTON_CLICK_MULTIPLE
|
|
34
|
+
export { BUTTON_CLICK_MULTIPLE_1 as BUTTON_CLICK_MULTIPLE }
|
|
35
|
+
export let UNKNOWN_MESSAGE_TYPE: string
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* *
|
|
39
|
+
*/
|
|
40
|
+
export type MESSAGE_MEDIA_TYPE_MAPPER = string
|
|
41
|
+
/**
|
|
42
|
+
* Maps platform-specific message types into the unified equivalents.
|
|
43
|
+
*
|
|
44
|
+
* This is used to convert raw provider terminology into internal naming.
|
|
45
|
+
*
|
|
46
|
+
* @readonly
|
|
47
|
+
* @enum {string}
|
|
48
|
+
*
|
|
49
|
+
* @property {"audio"} VOICE
|
|
50
|
+
* Telegram's "voice" is normalized into the system's AUDIO type.
|
|
51
|
+
*
|
|
52
|
+
* @property {"image"} PHOTO
|
|
53
|
+
* Telegram's "photo" array is normalized into IMAGE.
|
|
54
|
+
*
|
|
55
|
+
* @property {"contact"} CONTACTS
|
|
56
|
+
* WhatsApp's "contacts" array is normalized into CONTACT.
|
|
57
|
+
*/
|
|
58
|
+
export const MESSAGE_MEDIA_TYPE_MAPPER: {
|
|
59
|
+
[MESSAGE_MEDIA_TYPE.VOICE]: string
|
|
60
|
+
[MESSAGE_MEDIA_TYPE.PHOTO]: string
|
|
61
|
+
[MESSAGE_MEDIA_TYPE.CONTACTS]: string
|
|
62
|
+
}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
export function getMessageType({ imMessage }: { imMessage: any }): string
|
|
2
|
+
export function mapMessageTelegramBase({ imMessage }: { imMessage: any }): {
|
|
3
|
+
messageBase: {
|
|
4
|
+
timestamp: string
|
|
5
|
+
forwardInfo: {
|
|
6
|
+
forward_date: any
|
|
7
|
+
forward_from: any
|
|
8
|
+
}
|
|
9
|
+
id: any
|
|
10
|
+
imExtraInfo: {
|
|
11
|
+
tmId: any
|
|
12
|
+
}
|
|
13
|
+
chatId: any
|
|
14
|
+
type: string
|
|
15
|
+
chatter: any
|
|
16
|
+
itIsForward: boolean
|
|
17
|
+
}
|
|
18
|
+
message: any
|
|
19
|
+
type: string
|
|
20
|
+
}
|
|
21
|
+
export function mapMessageWhatsAppContent({
|
|
22
|
+
message,
|
|
23
|
+
type,
|
|
24
|
+
}: {
|
|
25
|
+
message: any
|
|
26
|
+
type: any
|
|
27
|
+
}):
|
|
28
|
+
| {
|
|
29
|
+
text: any
|
|
30
|
+
reply?: undefined
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
[x: number]: any
|
|
34
|
+
text?: undefined
|
|
35
|
+
reply?: undefined
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
reply: any
|
|
39
|
+
text?: undefined
|
|
40
|
+
}
|
|
41
|
+
export function mapMessageTelegram({ imMessage }: { imMessage: any }):
|
|
42
|
+
| {
|
|
43
|
+
text: any
|
|
44
|
+
reply?: undefined
|
|
45
|
+
timestamp: string
|
|
46
|
+
forwardInfo: {
|
|
47
|
+
forward_date: any
|
|
48
|
+
forward_from: any
|
|
49
|
+
}
|
|
50
|
+
id: any
|
|
51
|
+
imExtraInfo: {
|
|
52
|
+
tmId: any
|
|
53
|
+
}
|
|
54
|
+
chatId: any
|
|
55
|
+
type: string
|
|
56
|
+
chatter: any
|
|
57
|
+
itIsForward: boolean
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
text?: undefined
|
|
61
|
+
reply?: undefined
|
|
62
|
+
timestamp: string
|
|
63
|
+
forwardInfo: {
|
|
64
|
+
forward_date: any
|
|
65
|
+
forward_from: any
|
|
66
|
+
}
|
|
67
|
+
id: any
|
|
68
|
+
imExtraInfo: {
|
|
69
|
+
tmId: any
|
|
70
|
+
}
|
|
71
|
+
chatId: any
|
|
72
|
+
type: string
|
|
73
|
+
chatter: any
|
|
74
|
+
itIsForward: boolean
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
attachment: string
|
|
78
|
+
animation: any
|
|
79
|
+
text?: undefined
|
|
80
|
+
reply?: undefined
|
|
81
|
+
timestamp: string
|
|
82
|
+
forwardInfo: {
|
|
83
|
+
forward_date: any
|
|
84
|
+
forward_from: any
|
|
85
|
+
}
|
|
86
|
+
id: any
|
|
87
|
+
imExtraInfo: {
|
|
88
|
+
tmId: any
|
|
89
|
+
}
|
|
90
|
+
chatId: any
|
|
91
|
+
type: string
|
|
92
|
+
chatter: any
|
|
93
|
+
itIsForward: boolean
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
reply: {
|
|
97
|
+
id: any
|
|
98
|
+
title: any
|
|
99
|
+
}
|
|
100
|
+
text?: undefined
|
|
101
|
+
timestamp: string
|
|
102
|
+
forwardInfo: {
|
|
103
|
+
forward_date: any
|
|
104
|
+
forward_from: any
|
|
105
|
+
}
|
|
106
|
+
id: any
|
|
107
|
+
imExtraInfo: {
|
|
108
|
+
tmId: any
|
|
109
|
+
}
|
|
110
|
+
chatId: any
|
|
111
|
+
type: string
|
|
112
|
+
chatter: any
|
|
113
|
+
itIsForward: boolean
|
|
114
|
+
}
|
|
115
|
+
export function getWhatsAppMessageType({ message }: { message: any }): any
|
|
116
|
+
export function extractReply({ imMessage }: { imMessage: any }): {
|
|
117
|
+
id: any
|
|
118
|
+
title: any
|
|
119
|
+
}
|
|
120
|
+
export function whatsappBaseExtraction({ imMessage }: { imMessage: any }): {
|
|
121
|
+
field: any
|
|
122
|
+
value: any
|
|
123
|
+
wbaid: any
|
|
124
|
+
}
|
|
125
|
+
export function mapMessageWhatsAppBase({ imMessage }: { imMessage: any }): {
|
|
126
|
+
messageBase: {
|
|
127
|
+
id: any
|
|
128
|
+
chatId: any
|
|
129
|
+
imExtraInfo: {
|
|
130
|
+
wbaid: any
|
|
131
|
+
}
|
|
132
|
+
type: any
|
|
133
|
+
chatter: {
|
|
134
|
+
id: any
|
|
135
|
+
name: any
|
|
136
|
+
username: any
|
|
137
|
+
}
|
|
138
|
+
itIsForward: boolean
|
|
139
|
+
timestamp: any
|
|
140
|
+
}
|
|
141
|
+
message: any
|
|
142
|
+
contact: any
|
|
143
|
+
context: any
|
|
144
|
+
}
|
|
145
|
+
export function mapMessageTelegramContent({
|
|
146
|
+
type,
|
|
147
|
+
message,
|
|
148
|
+
imMessage,
|
|
149
|
+
}: {
|
|
150
|
+
type: any
|
|
151
|
+
message: any
|
|
152
|
+
imMessage: any
|
|
153
|
+
}):
|
|
154
|
+
| {
|
|
155
|
+
text: any
|
|
156
|
+
reply?: undefined
|
|
157
|
+
}
|
|
158
|
+
| {
|
|
159
|
+
[x: number]: any
|
|
160
|
+
text?: undefined
|
|
161
|
+
reply?: undefined
|
|
162
|
+
}
|
|
163
|
+
| {
|
|
164
|
+
attachment: string
|
|
165
|
+
animation: any
|
|
166
|
+
text?: undefined
|
|
167
|
+
reply?: undefined
|
|
168
|
+
}
|
|
169
|
+
| {
|
|
170
|
+
reply: {
|
|
171
|
+
id: any
|
|
172
|
+
title: any
|
|
173
|
+
}
|
|
174
|
+
text?: undefined
|
|
175
|
+
}
|
|
176
|
+
export function mapMessageWhatsApp({ imMessage }: { imMessage: any }):
|
|
177
|
+
| {
|
|
178
|
+
text: any
|
|
179
|
+
reply?: undefined
|
|
180
|
+
id: any
|
|
181
|
+
chatId: any
|
|
182
|
+
imExtraInfo: {
|
|
183
|
+
wbaid: any
|
|
184
|
+
}
|
|
185
|
+
type: any
|
|
186
|
+
chatter: {
|
|
187
|
+
id: any
|
|
188
|
+
name: any
|
|
189
|
+
username: any
|
|
190
|
+
}
|
|
191
|
+
itIsForward: boolean
|
|
192
|
+
timestamp: any
|
|
193
|
+
}
|
|
194
|
+
| {
|
|
195
|
+
text?: undefined
|
|
196
|
+
reply?: undefined
|
|
197
|
+
id: any
|
|
198
|
+
chatId: any
|
|
199
|
+
imExtraInfo: {
|
|
200
|
+
wbaid: any
|
|
201
|
+
}
|
|
202
|
+
type: any
|
|
203
|
+
chatter: {
|
|
204
|
+
id: any
|
|
205
|
+
name: any
|
|
206
|
+
username: any
|
|
207
|
+
}
|
|
208
|
+
itIsForward: boolean
|
|
209
|
+
timestamp: any
|
|
210
|
+
}
|
|
211
|
+
| {
|
|
212
|
+
reply: any
|
|
213
|
+
text?: undefined
|
|
214
|
+
id: any
|
|
215
|
+
chatId: any
|
|
216
|
+
imExtraInfo: {
|
|
217
|
+
wbaid: any
|
|
218
|
+
}
|
|
219
|
+
type: any
|
|
220
|
+
chatter: {
|
|
221
|
+
id: any
|
|
222
|
+
name: any
|
|
223
|
+
username: any
|
|
224
|
+
}
|
|
225
|
+
itIsForward: boolean
|
|
226
|
+
timestamp: any
|
|
227
|
+
}
|
|
228
|
+
export const messageUnifiedMapper: {
|
|
229
|
+
[IM_PLATFORM.TELEGRAM]: ({ imMessage }: { imMessage: any }) =>
|
|
230
|
+
| {
|
|
231
|
+
text: any
|
|
232
|
+
reply?: undefined
|
|
233
|
+
timestamp: string
|
|
234
|
+
forwardInfo: {
|
|
235
|
+
forward_date: any
|
|
236
|
+
forward_from: any
|
|
237
|
+
}
|
|
238
|
+
id: any
|
|
239
|
+
imExtraInfo: {
|
|
240
|
+
tmId: any
|
|
241
|
+
}
|
|
242
|
+
chatId: any
|
|
243
|
+
type: string
|
|
244
|
+
chatter: any
|
|
245
|
+
itIsForward: boolean
|
|
246
|
+
}
|
|
247
|
+
| {
|
|
248
|
+
text?: undefined
|
|
249
|
+
reply?: undefined
|
|
250
|
+
timestamp: string
|
|
251
|
+
forwardInfo: {
|
|
252
|
+
forward_date: any
|
|
253
|
+
forward_from: any
|
|
254
|
+
}
|
|
255
|
+
id: any
|
|
256
|
+
imExtraInfo: {
|
|
257
|
+
tmId: any
|
|
258
|
+
}
|
|
259
|
+
chatId: any
|
|
260
|
+
type: string
|
|
261
|
+
chatter: any
|
|
262
|
+
itIsForward: boolean
|
|
263
|
+
}
|
|
264
|
+
| {
|
|
265
|
+
attachment: string
|
|
266
|
+
animation: any
|
|
267
|
+
text?: undefined
|
|
268
|
+
reply?: undefined
|
|
269
|
+
timestamp: string
|
|
270
|
+
forwardInfo: {
|
|
271
|
+
forward_date: any
|
|
272
|
+
forward_from: any
|
|
273
|
+
}
|
|
274
|
+
id: any
|
|
275
|
+
imExtraInfo: {
|
|
276
|
+
tmId: any
|
|
277
|
+
}
|
|
278
|
+
chatId: any
|
|
279
|
+
type: string
|
|
280
|
+
chatter: any
|
|
281
|
+
itIsForward: boolean
|
|
282
|
+
}
|
|
283
|
+
| {
|
|
284
|
+
reply: {
|
|
285
|
+
id: any
|
|
286
|
+
title: any
|
|
287
|
+
}
|
|
288
|
+
text?: undefined
|
|
289
|
+
timestamp: string
|
|
290
|
+
forwardInfo: {
|
|
291
|
+
forward_date: any
|
|
292
|
+
forward_from: any
|
|
293
|
+
}
|
|
294
|
+
id: any
|
|
295
|
+
imExtraInfo: {
|
|
296
|
+
tmId: any
|
|
297
|
+
}
|
|
298
|
+
chatId: any
|
|
299
|
+
type: string
|
|
300
|
+
chatter: any
|
|
301
|
+
itIsForward: boolean
|
|
302
|
+
}
|
|
303
|
+
[IM_PLATFORM.WHATSAPP]: ({ imMessage }: { imMessage: any }) =>
|
|
304
|
+
| {
|
|
305
|
+
text: any
|
|
306
|
+
reply?: undefined
|
|
307
|
+
id: any
|
|
308
|
+
chatId: any
|
|
309
|
+
imExtraInfo: {
|
|
310
|
+
wbaid: any
|
|
311
|
+
}
|
|
312
|
+
type: any
|
|
313
|
+
chatter: {
|
|
314
|
+
id: any
|
|
315
|
+
name: any
|
|
316
|
+
username: any
|
|
317
|
+
}
|
|
318
|
+
itIsForward: boolean
|
|
319
|
+
timestamp: any
|
|
320
|
+
}
|
|
321
|
+
| {
|
|
322
|
+
text?: undefined
|
|
323
|
+
reply?: undefined
|
|
324
|
+
id: any
|
|
325
|
+
chatId: any
|
|
326
|
+
imExtraInfo: {
|
|
327
|
+
wbaid: any
|
|
328
|
+
}
|
|
329
|
+
type: any
|
|
330
|
+
chatter: {
|
|
331
|
+
id: any
|
|
332
|
+
name: any
|
|
333
|
+
username: any
|
|
334
|
+
}
|
|
335
|
+
itIsForward: boolean
|
|
336
|
+
timestamp: any
|
|
337
|
+
}
|
|
338
|
+
| {
|
|
339
|
+
reply: any
|
|
340
|
+
text?: undefined
|
|
341
|
+
id: any
|
|
342
|
+
chatId: any
|
|
343
|
+
imExtraInfo: {
|
|
344
|
+
wbaid: any
|
|
345
|
+
}
|
|
346
|
+
type: any
|
|
347
|
+
chatter: {
|
|
348
|
+
id: any
|
|
349
|
+
name: any
|
|
350
|
+
username: any
|
|
351
|
+
}
|
|
352
|
+
itIsForward: boolean
|
|
353
|
+
timestamp: any
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
import { IM_PLATFORM } from './im-platform.js'
|