core-services-sdk 1.3.48 → 1.3.49
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
CHANGED
|
@@ -7,54 +7,24 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @readonly
|
|
9
9
|
* @enum {string}
|
|
10
|
+
* @type {{ [key: string]: string }}
|
|
10
11
|
*
|
|
11
12
|
* @property {"text"} TEXT
|
|
12
|
-
* Represents plain text content.
|
|
13
|
-
*
|
|
14
13
|
* @property {"poll"} POLL
|
|
15
|
-
* Represents a Telegram poll (multiple-choice question).
|
|
16
|
-
*
|
|
17
14
|
* @property {"video"} VIDEO
|
|
18
|
-
* Represents a standard video file.
|
|
19
|
-
*
|
|
20
15
|
* @property {"photo"} PHOTO
|
|
21
|
-
* Represents a Telegram “photo” array (before mapping to IMAGE).
|
|
22
|
-
*
|
|
23
16
|
* @property {"image"} IMAGE
|
|
24
|
-
* Represents an image file (after normalization).
|
|
25
|
-
*
|
|
26
17
|
* @property {"voice"} VOICE
|
|
27
|
-
* Represents Telegram's "voice" messages (OGG encoded voice notes).
|
|
28
|
-
*
|
|
29
18
|
* @property {"audio"} AUDIO
|
|
30
|
-
* Represents general audio files (WhatsApp voice notes, audio uploads).
|
|
31
|
-
*
|
|
32
19
|
* @property {"sticker"} STICKER
|
|
33
|
-
* Represents sticker messages (Telegram or WhatsApp).
|
|
34
|
-
*
|
|
35
20
|
* @property {"contact"} CONTACT
|
|
36
|
-
* Represents a shared contact card.
|
|
37
|
-
*
|
|
38
21
|
* @property {"reaction"} REACTION
|
|
39
|
-
* Represents WhatsApp/Telegram reactions (emojis on messages).
|
|
40
|
-
*
|
|
41
22
|
* @property {"document"} DOCUMENT
|
|
42
|
-
* Represents generic uploaded files, including PDFs.
|
|
43
|
-
*
|
|
44
23
|
* @property {"location"} LOCATION
|
|
45
|
-
* Represents geographic coordinates.
|
|
46
|
-
*
|
|
47
24
|
* @property {"contacts"} CONTACTS
|
|
48
|
-
* Represents WhatsApp contacts array (before mapping to CONTACT).
|
|
49
|
-
*
|
|
50
25
|
* @property {"video_note"} VIDEO_NOTE
|
|
51
|
-
* Represents Telegram's circular "video note".
|
|
52
|
-
*
|
|
53
26
|
* @property {"button_click"} BUTTON_CLICK
|
|
54
|
-
* Represents a button press (interactive replies).
|
|
55
|
-
*
|
|
56
27
|
* @property {"button_click_multiple"} BUTTON_CLICK_MULTIPLE
|
|
57
|
-
* Represents list/menu selection (e.g., WhatsApp list_reply).
|
|
58
28
|
*/
|
|
59
29
|
export const MESSAGE_MEDIA_TYPE = {
|
|
60
30
|
TEXT: 'text',
|
|
@@ -75,7 +45,6 @@ export const MESSAGE_MEDIA_TYPE = {
|
|
|
75
45
|
BUTTON_CLICK: 'button_click',
|
|
76
46
|
BUTTON_CLICK_MULTIPLE: 'button_click_multiple',
|
|
77
47
|
}
|
|
78
|
-
|
|
79
48
|
/**
|
|
80
49
|
* Additional high-level message categories.
|
|
81
50
|
*
|
|
@@ -83,6 +52,7 @@ export const MESSAGE_MEDIA_TYPE = {
|
|
|
83
52
|
*
|
|
84
53
|
* @readonly
|
|
85
54
|
* @enum {string}
|
|
55
|
+
* @type {{ [key: string]: string }}
|
|
86
56
|
*
|
|
87
57
|
* @property {"message"} MESSAGE
|
|
88
58
|
* Regular message container (base type in some providers).
|
|
@@ -125,3 +95,27 @@ export const MESSAGE_MEDIA_TYPE_MAPPER = {
|
|
|
125
95
|
[MESSAGE_MEDIA_TYPE.PHOTO]: MESSAGE_MEDIA_TYPE.IMAGE,
|
|
126
96
|
[MESSAGE_MEDIA_TYPE.CONTACTS]: MESSAGE_MEDIA_TYPE.CONTACT,
|
|
127
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Unified message media types based on existing MESSAGE_MEDIA_TYPE and MESSAGE_TYPE.
|
|
101
|
+
*
|
|
102
|
+
* This enum flattens and merges all raw message media types
|
|
103
|
+
* into a single canonical type list.
|
|
104
|
+
*
|
|
105
|
+
* VOICE → AUDIO
|
|
106
|
+
* PHOTO → IMAGE
|
|
107
|
+
* CONTACTS → CONTACT
|
|
108
|
+
*
|
|
109
|
+
* @readonly
|
|
110
|
+
* @enum {string}
|
|
111
|
+
* @type {{ [key: string]: string }}
|
|
112
|
+
*/
|
|
113
|
+
export const UNIFIED_MESSAGE_MEDIA_TYPE = {
|
|
114
|
+
...MESSAGE_MEDIA_TYPE,
|
|
115
|
+
...MESSAGE_TYPE,
|
|
116
|
+
|
|
117
|
+
// Normalized equivalents
|
|
118
|
+
AUDIO: MESSAGE_MEDIA_TYPE.AUDIO,
|
|
119
|
+
IMAGE: MESSAGE_MEDIA_TYPE.IMAGE,
|
|
120
|
+
CONTACT: MESSAGE_MEDIA_TYPE.CONTACT,
|
|
121
|
+
}
|
|
@@ -39,7 +39,6 @@ describe('Telegram unified message mapper – all mock samples', () => {
|
|
|
39
39
|
|
|
40
40
|
expect(unifiedMessage).toBeTypeOf('object')
|
|
41
41
|
expect(unifiedType).toBeTypeOf('string')
|
|
42
|
-
|
|
43
42
|
expect(unifiedMessage.type).toBe(
|
|
44
43
|
MESSAGE_MEDIA_TYPE_MAPPER[unifiedType] || unifiedType,
|
|
45
44
|
)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
MESSAGE_TYPE,
|
|
4
|
+
MESSAGE_MEDIA_TYPE,
|
|
5
|
+
MESSAGE_MEDIA_TYPE_MAPPER,
|
|
6
|
+
UNIFIED_MESSAGE_MEDIA_TYPE,
|
|
7
|
+
} from '../../src/instant-messages/message-types.js'
|
|
8
|
+
|
|
9
|
+
describe('UNIFIED_MESSAGE_MEDIA_TYPE', () => {
|
|
10
|
+
it('should include all keys from MESSAGE_MEDIA_TYPE via spread', () => {
|
|
11
|
+
for (const key of Object.keys(MESSAGE_MEDIA_TYPE)) {
|
|
12
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE).toHaveProperty(key)
|
|
13
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE[key]).toBe(MESSAGE_MEDIA_TYPE[key])
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should include all keys from MESSAGE_TYPE via spread', () => {
|
|
18
|
+
for (const key of Object.keys(MESSAGE_TYPE)) {
|
|
19
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE).toHaveProperty(key)
|
|
20
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE[key]).toBe(MESSAGE_TYPE[key])
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('should include normalized AUDIO mapped from VOICE', () => {
|
|
25
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE.AUDIO).toBe(MESSAGE_MEDIA_TYPE.AUDIO)
|
|
26
|
+
expect(MESSAGE_MEDIA_TYPE_MAPPER[MESSAGE_MEDIA_TYPE.VOICE]).toBe(
|
|
27
|
+
MESSAGE_MEDIA_TYPE.AUDIO,
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should include normalized IMAGE mapped from PHOTO', () => {
|
|
32
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE.IMAGE).toBe(MESSAGE_MEDIA_TYPE.IMAGE)
|
|
33
|
+
expect(MESSAGE_MEDIA_TYPE_MAPPER[MESSAGE_MEDIA_TYPE.PHOTO]).toBe(
|
|
34
|
+
MESSAGE_MEDIA_TYPE.IMAGE,
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should include normalized CONTACT mapped from CONTACTS', () => {
|
|
39
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE.CONTACT).toBe(MESSAGE_MEDIA_TYPE.CONTACT)
|
|
40
|
+
expect(MESSAGE_MEDIA_TYPE_MAPPER[MESSAGE_MEDIA_TYPE.CONTACTS]).toBe(
|
|
41
|
+
MESSAGE_MEDIA_TYPE.CONTACT,
|
|
42
|
+
)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should define UNKNOWN correctly', () => {
|
|
46
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE.UNKNOWN_MESSAGE_TYPE).toBe(
|
|
47
|
+
MESSAGE_TYPE.UNKNOWN_MESSAGE_TYPE,
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should not contain unexpected duplicates', () => {
|
|
52
|
+
const values = Object.values(UNIFIED_MESSAGE_MEDIA_TYPE)
|
|
53
|
+
const uniqueValues = new Set(values)
|
|
54
|
+
expect(values.length).toBe(uniqueValues.size)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should contain required high-level unified types', () => {
|
|
58
|
+
const required = [
|
|
59
|
+
'TEXT',
|
|
60
|
+
'IMAGE',
|
|
61
|
+
'AUDIO',
|
|
62
|
+
'VIDEO',
|
|
63
|
+
'DOCUMENT',
|
|
64
|
+
'STICKER',
|
|
65
|
+
'CONTACT',
|
|
66
|
+
'LOCATION',
|
|
67
|
+
'POLL',
|
|
68
|
+
'VIDEO_NOTE',
|
|
69
|
+
'BUTTON_CLICK',
|
|
70
|
+
'BUTTON_CLICK_MULTIPLE',
|
|
71
|
+
'REACTION',
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
for (const key of required) {
|
|
75
|
+
expect(UNIFIED_MESSAGE_MEDIA_TYPE).toHaveProperty(key)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -2,37 +2,64 @@
|
|
|
2
2
|
* *
|
|
3
3
|
*/
|
|
4
4
|
export type MESSAGE_MEDIA_TYPE = string
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Enumerates all supported incoming media/content types
|
|
7
|
+
* across messaging platforms (Telegram, WhatsApp, etc).
|
|
8
|
+
*
|
|
9
|
+
* This is the unified taxonomy used inside the system
|
|
10
|
+
* after normalization of the raw message payload.
|
|
11
|
+
*
|
|
12
|
+
* @readonly
|
|
13
|
+
* @enum {string}
|
|
14
|
+
* @type {{ [key: string]: string }}
|
|
15
|
+
*
|
|
16
|
+
* @property {"text"} TEXT
|
|
17
|
+
* @property {"poll"} POLL
|
|
18
|
+
* @property {"video"} VIDEO
|
|
19
|
+
* @property {"photo"} PHOTO
|
|
20
|
+
* @property {"image"} IMAGE
|
|
21
|
+
* @property {"voice"} VOICE
|
|
22
|
+
* @property {"audio"} AUDIO
|
|
23
|
+
* @property {"sticker"} STICKER
|
|
24
|
+
* @property {"contact"} CONTACT
|
|
25
|
+
* @property {"reaction"} REACTION
|
|
26
|
+
* @property {"document"} DOCUMENT
|
|
27
|
+
* @property {"location"} LOCATION
|
|
28
|
+
* @property {"contacts"} CONTACTS
|
|
29
|
+
* @property {"video_note"} VIDEO_NOTE
|
|
30
|
+
* @property {"button_click"} BUTTON_CLICK
|
|
31
|
+
* @property {"button_click_multiple"} BUTTON_CLICK_MULTIPLE
|
|
32
|
+
*/
|
|
33
|
+
export const MESSAGE_MEDIA_TYPE: {
|
|
34
|
+
[key: string]: string
|
|
23
35
|
}
|
|
24
36
|
/**
|
|
25
37
|
* *
|
|
26
38
|
*/
|
|
27
39
|
export type MESSAGE_TYPE = string
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Additional high-level message categories.
|
|
42
|
+
*
|
|
43
|
+
* These represent logical groupings rather than raw media types.
|
|
44
|
+
*
|
|
45
|
+
* @readonly
|
|
46
|
+
* @enum {string}
|
|
47
|
+
* @type {{ [key: string]: string }}
|
|
48
|
+
*
|
|
49
|
+
* @property {"message"} MESSAGE
|
|
50
|
+
* Regular message container (base type in some providers).
|
|
51
|
+
*
|
|
52
|
+
* @property {"button_click"} BUTTON_CLICK
|
|
53
|
+
* A click on a single interactive button.
|
|
54
|
+
*
|
|
55
|
+
* @property {"button_click_multiple"} BUTTON_CLICK_MULTIPLE
|
|
56
|
+
* A selection from a list of interactive reply choices.
|
|
57
|
+
*
|
|
58
|
+
* @property {"unknown_message_type"} UNKNOWN_MESSAGE_TYPE
|
|
59
|
+
* Used when the system cannot identify or normalize the message type.
|
|
60
|
+
*/
|
|
61
|
+
export const MESSAGE_TYPE: {
|
|
62
|
+
[key: string]: string
|
|
36
63
|
}
|
|
37
64
|
/**
|
|
38
65
|
* *
|
|
@@ -60,3 +87,24 @@ export const MESSAGE_MEDIA_TYPE_MAPPER: {
|
|
|
60
87
|
[MESSAGE_MEDIA_TYPE.PHOTO]: string
|
|
61
88
|
[MESSAGE_MEDIA_TYPE.CONTACTS]: string
|
|
62
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* *
|
|
92
|
+
*/
|
|
93
|
+
export type UNIFIED_MESSAGE_MEDIA_TYPE = string
|
|
94
|
+
/**
|
|
95
|
+
* Unified message media types based on existing MESSAGE_MEDIA_TYPE and MESSAGE_TYPE.
|
|
96
|
+
*
|
|
97
|
+
* This enum flattens and merges all raw message media types
|
|
98
|
+
* into a single canonical type list.
|
|
99
|
+
*
|
|
100
|
+
* VOICE → AUDIO
|
|
101
|
+
* PHOTO → IMAGE
|
|
102
|
+
* CONTACTS → CONTACT
|
|
103
|
+
*
|
|
104
|
+
* @readonly
|
|
105
|
+
* @enum {string}
|
|
106
|
+
* @type {{ [key: string]: string }}
|
|
107
|
+
*/
|
|
108
|
+
export const UNIFIED_MESSAGE_MEDIA_TYPE: {
|
|
109
|
+
[key: string]: string
|
|
110
|
+
}
|