@warriorteam/redai-zalo-sdk 1.12.0 → 1.12.2

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.
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ /**
3
+ * Type guard utilities for Zalo SDK webhook events
4
+ *
5
+ * This file provides type-safe functions to check webhook event types
6
+ * and narrow down TypeScript types for better development experience.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isUserSendGroupTextEvent = isUserSendGroupTextEvent;
10
+ exports.isUserSendGroupImageEvent = isUserSendGroupImageEvent;
11
+ exports.isUserSendGroupVideoEvent = isUserSendGroupVideoEvent;
12
+ exports.isUserSendGroupAudioEvent = isUserSendGroupAudioEvent;
13
+ exports.isUserSendGroupFileEvent = isUserSendGroupFileEvent;
14
+ exports.isUserGroupMessageEvent = isUserGroupMessageEvent;
15
+ exports.isOASendTextEvent = isOASendTextEvent;
16
+ exports.isOASendImageEvent = isOASendImageEvent;
17
+ exports.isOASendFileEvent = isOASendFileEvent;
18
+ exports.isOASendStickerEvent = isOASendStickerEvent;
19
+ exports.isOASendGifEvent = isOASendGifEvent;
20
+ exports.isOASendGroupTextEvent = isOASendGroupTextEvent;
21
+ exports.isOASendGroupImageEvent = isOASendGroupImageEvent;
22
+ exports.isOASendGroupFileEvent = isOASendGroupFileEvent;
23
+ exports.isOASendGroupStickerEvent = isOASendGroupStickerEvent;
24
+ exports.isOASendGroupGifEvent = isOASendGroupGifEvent;
25
+ exports.isOAMessageEvent = isOAMessageEvent;
26
+ exports.isUserMessageEvent = isUserMessageEvent;
27
+ exports.hasAttachments = hasAttachments;
28
+ exports.isFromGroup = isFromGroup;
29
+ exports.isFromPersonal = isFromPersonal;
30
+ const webhook_1 = require("../types/webhook");
31
+ /**
32
+ * Check if event is a user sending text message to group
33
+ */
34
+ function isUserSendGroupTextEvent(event) {
35
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT;
36
+ }
37
+ /**
38
+ * Check if event is a user sending image message to group
39
+ */
40
+ function isUserSendGroupImageEvent(event) {
41
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_IMAGE;
42
+ }
43
+ /**
44
+ * Check if event is a user sending video message to group
45
+ */
46
+ function isUserSendGroupVideoEvent(event) {
47
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO;
48
+ }
49
+ /**
50
+ * Check if event is a user sending audio message to group
51
+ */
52
+ function isUserSendGroupAudioEvent(event) {
53
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO;
54
+ }
55
+ /**
56
+ * Check if event is a user sending file to group
57
+ */
58
+ function isUserSendGroupFileEvent(event) {
59
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_FILE;
60
+ }
61
+ /**
62
+ * Check if event is any user group message event
63
+ */
64
+ function isUserGroupMessageEvent(event) {
65
+ return [
66
+ webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT,
67
+ webhook_1.WebhookEventName.USER_SEND_GROUP_IMAGE,
68
+ webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO,
69
+ webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO,
70
+ webhook_1.WebhookEventName.USER_SEND_GROUP_FILE,
71
+ ].includes(event.event_name);
72
+ }
73
+ // ===== OA MESSAGE TYPE GUARDS =====
74
+ /**
75
+ * Check if event is OA sending text message to user
76
+ */
77
+ function isOASendTextEvent(event) {
78
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_TEXT;
79
+ }
80
+ /**
81
+ * Check if event is OA sending image message to user
82
+ */
83
+ function isOASendImageEvent(event) {
84
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_IMAGE;
85
+ }
86
+ /**
87
+ * Check if event is OA sending file to user
88
+ */
89
+ function isOASendFileEvent(event) {
90
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_FILE;
91
+ }
92
+ /**
93
+ * Check if event is OA sending sticker to user
94
+ */
95
+ function isOASendStickerEvent(event) {
96
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_STICKER;
97
+ }
98
+ /**
99
+ * Check if event is OA sending GIF to user
100
+ */
101
+ function isOASendGifEvent(event) {
102
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GIF;
103
+ }
104
+ // ===== OA GROUP MESSAGE TYPE GUARDS =====
105
+ /**
106
+ * Check if event is OA sending text message to group
107
+ */
108
+ function isOASendGroupTextEvent(event) {
109
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_TEXT;
110
+ }
111
+ /**
112
+ * Check if event is OA sending image to group
113
+ */
114
+ function isOASendGroupImageEvent(event) {
115
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_IMAGE;
116
+ }
117
+ /**
118
+ * Check if event is OA sending file to group
119
+ */
120
+ function isOASendGroupFileEvent(event) {
121
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_FILE;
122
+ }
123
+ /**
124
+ * Check if event is OA sending sticker to group
125
+ */
126
+ function isOASendGroupStickerEvent(event) {
127
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_STICKER;
128
+ }
129
+ /**
130
+ * Check if event is OA sending GIF to group
131
+ */
132
+ function isOASendGroupGifEvent(event) {
133
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_GIF;
134
+ }
135
+ // ===== COMBINED TYPE GUARDS =====
136
+ /**
137
+ * Check if event is any OA message event (personal or group)
138
+ */
139
+ function isOAMessageEvent(event) {
140
+ return [
141
+ webhook_1.WebhookEventName.OA_SEND_TEXT,
142
+ webhook_1.WebhookEventName.OA_SEND_IMAGE,
143
+ webhook_1.WebhookEventName.OA_SEND_FILE,
144
+ webhook_1.WebhookEventName.OA_SEND_STICKER,
145
+ webhook_1.WebhookEventName.OA_SEND_GIF,
146
+ webhook_1.WebhookEventName.OA_SEND_GROUP_TEXT,
147
+ webhook_1.WebhookEventName.OA_SEND_GROUP_IMAGE,
148
+ webhook_1.WebhookEventName.OA_SEND_GROUP_FILE,
149
+ webhook_1.WebhookEventName.OA_SEND_GROUP_STICKER,
150
+ webhook_1.WebhookEventName.OA_SEND_GROUP_GIF,
151
+ ].includes(event.event_name);
152
+ }
153
+ /**
154
+ * Check if event is any user message event (personal or group)
155
+ */
156
+ function isUserMessageEvent(event) {
157
+ return [
158
+ webhook_1.WebhookEventName.USER_SEND_TEXT,
159
+ webhook_1.WebhookEventName.USER_SEND_IMAGE,
160
+ webhook_1.WebhookEventName.USER_SEND_AUDIO,
161
+ webhook_1.WebhookEventName.USER_SEND_VIDEO,
162
+ webhook_1.WebhookEventName.USER_SEND_FILE,
163
+ webhook_1.WebhookEventName.USER_SEND_STICKER,
164
+ webhook_1.WebhookEventName.USER_SEND_LOCATION,
165
+ webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT,
166
+ webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO,
167
+ webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO,
168
+ webhook_1.WebhookEventName.USER_SEND_GROUP_FILE,
169
+ ].includes(event.event_name);
170
+ }
171
+ /**
172
+ * Check if event has message attachments
173
+ */
174
+ function hasAttachments(event) {
175
+ if ('message' in event && event.message && 'attachments' in event.message) {
176
+ return Array.isArray(event.message.attachments) && event.message.attachments.length > 0;
177
+ }
178
+ return false;
179
+ }
180
+ /**
181
+ * Check if event is from a group context
182
+ */
183
+ function isFromGroup(event) {
184
+ return 'group_id' in event || event.event_name.includes('group');
185
+ }
186
+ /**
187
+ * Check if event is from a personal context
188
+ */
189
+ function isFromPersonal(event) {
190
+ return !isFromGroup(event);
191
+ }
192
+ //# sourceMappingURL=type-guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAwCH,4DAIC;AAKD,8DAIC;AAKD,8DAIC;AAKD,8DAIC;AAKD,4DAIC;AAKD,0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