@warriorteam/redai-zalo-sdk 1.11.1 → 1.12.1

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,184 @@
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.isUserSendGroupVideoEvent = isUserSendGroupVideoEvent;
11
+ exports.isUserSendGroupAudioEvent = isUserSendGroupAudioEvent;
12
+ exports.isUserSendGroupFileEvent = isUserSendGroupFileEvent;
13
+ exports.isUserGroupMessageEvent = isUserGroupMessageEvent;
14
+ exports.isOASendTextEvent = isOASendTextEvent;
15
+ exports.isOASendImageEvent = isOASendImageEvent;
16
+ exports.isOASendFileEvent = isOASendFileEvent;
17
+ exports.isOASendStickerEvent = isOASendStickerEvent;
18
+ exports.isOASendGifEvent = isOASendGifEvent;
19
+ exports.isOASendGroupTextEvent = isOASendGroupTextEvent;
20
+ exports.isOASendGroupImageEvent = isOASendGroupImageEvent;
21
+ exports.isOASendGroupFileEvent = isOASendGroupFileEvent;
22
+ exports.isOASendGroupStickerEvent = isOASendGroupStickerEvent;
23
+ exports.isOASendGroupGifEvent = isOASendGroupGifEvent;
24
+ exports.isOAMessageEvent = isOAMessageEvent;
25
+ exports.isUserMessageEvent = isUserMessageEvent;
26
+ exports.hasAttachments = hasAttachments;
27
+ exports.isFromGroup = isFromGroup;
28
+ exports.isFromPersonal = isFromPersonal;
29
+ const webhook_1 = require("../types/webhook");
30
+ /**
31
+ * Check if event is a user sending text message to group
32
+ */
33
+ function isUserSendGroupTextEvent(event) {
34
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT;
35
+ }
36
+ /**
37
+ * Check if event is a user sending video message to group
38
+ */
39
+ function isUserSendGroupVideoEvent(event) {
40
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO;
41
+ }
42
+ /**
43
+ * Check if event is a user sending audio message to group
44
+ */
45
+ function isUserSendGroupAudioEvent(event) {
46
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO;
47
+ }
48
+ /**
49
+ * Check if event is a user sending file to group
50
+ */
51
+ function isUserSendGroupFileEvent(event) {
52
+ return event.event_name === webhook_1.WebhookEventName.USER_SEND_GROUP_FILE;
53
+ }
54
+ /**
55
+ * Check if event is any user group message event
56
+ */
57
+ function isUserGroupMessageEvent(event) {
58
+ return [
59
+ webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT,
60
+ webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO,
61
+ webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO,
62
+ webhook_1.WebhookEventName.USER_SEND_GROUP_FILE,
63
+ ].includes(event.event_name);
64
+ }
65
+ // ===== OA MESSAGE TYPE GUARDS =====
66
+ /**
67
+ * Check if event is OA sending text message to user
68
+ */
69
+ function isOASendTextEvent(event) {
70
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_TEXT;
71
+ }
72
+ /**
73
+ * Check if event is OA sending image message to user
74
+ */
75
+ function isOASendImageEvent(event) {
76
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_IMAGE;
77
+ }
78
+ /**
79
+ * Check if event is OA sending file to user
80
+ */
81
+ function isOASendFileEvent(event) {
82
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_FILE;
83
+ }
84
+ /**
85
+ * Check if event is OA sending sticker to user
86
+ */
87
+ function isOASendStickerEvent(event) {
88
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_STICKER;
89
+ }
90
+ /**
91
+ * Check if event is OA sending GIF to user
92
+ */
93
+ function isOASendGifEvent(event) {
94
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GIF;
95
+ }
96
+ // ===== OA GROUP MESSAGE TYPE GUARDS =====
97
+ /**
98
+ * Check if event is OA sending text message to group
99
+ */
100
+ function isOASendGroupTextEvent(event) {
101
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_TEXT;
102
+ }
103
+ /**
104
+ * Check if event is OA sending image to group
105
+ */
106
+ function isOASendGroupImageEvent(event) {
107
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_IMAGE;
108
+ }
109
+ /**
110
+ * Check if event is OA sending file to group
111
+ */
112
+ function isOASendGroupFileEvent(event) {
113
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_FILE;
114
+ }
115
+ /**
116
+ * Check if event is OA sending sticker to group
117
+ */
118
+ function isOASendGroupStickerEvent(event) {
119
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_STICKER;
120
+ }
121
+ /**
122
+ * Check if event is OA sending GIF to group
123
+ */
124
+ function isOASendGroupGifEvent(event) {
125
+ return event.event_name === webhook_1.WebhookEventName.OA_SEND_GROUP_GIF;
126
+ }
127
+ // ===== COMBINED TYPE GUARDS =====
128
+ /**
129
+ * Check if event is any OA message event (personal or group)
130
+ */
131
+ function isOAMessageEvent(event) {
132
+ return [
133
+ webhook_1.WebhookEventName.OA_SEND_TEXT,
134
+ webhook_1.WebhookEventName.OA_SEND_IMAGE,
135
+ webhook_1.WebhookEventName.OA_SEND_FILE,
136
+ webhook_1.WebhookEventName.OA_SEND_STICKER,
137
+ webhook_1.WebhookEventName.OA_SEND_GIF,
138
+ webhook_1.WebhookEventName.OA_SEND_GROUP_TEXT,
139
+ webhook_1.WebhookEventName.OA_SEND_GROUP_IMAGE,
140
+ webhook_1.WebhookEventName.OA_SEND_GROUP_FILE,
141
+ webhook_1.WebhookEventName.OA_SEND_GROUP_STICKER,
142
+ webhook_1.WebhookEventName.OA_SEND_GROUP_GIF,
143
+ ].includes(event.event_name);
144
+ }
145
+ /**
146
+ * Check if event is any user message event (personal or group)
147
+ */
148
+ function isUserMessageEvent(event) {
149
+ return [
150
+ webhook_1.WebhookEventName.USER_SEND_TEXT,
151
+ webhook_1.WebhookEventName.USER_SEND_IMAGE,
152
+ webhook_1.WebhookEventName.USER_SEND_AUDIO,
153
+ webhook_1.WebhookEventName.USER_SEND_VIDEO,
154
+ webhook_1.WebhookEventName.USER_SEND_FILE,
155
+ webhook_1.WebhookEventName.USER_SEND_STICKER,
156
+ webhook_1.WebhookEventName.USER_SEND_LOCATION,
157
+ webhook_1.WebhookEventName.USER_SEND_GROUP_TEXT,
158
+ webhook_1.WebhookEventName.USER_SEND_GROUP_VIDEO,
159
+ webhook_1.WebhookEventName.USER_SEND_GROUP_AUDIO,
160
+ webhook_1.WebhookEventName.USER_SEND_GROUP_FILE,
161
+ ].includes(event.event_name);
162
+ }
163
+ /**
164
+ * Check if event has message attachments
165
+ */
166
+ function hasAttachments(event) {
167
+ if ('message' in event && event.message && 'attachments' in event.message) {
168
+ return Array.isArray(event.message.attachments) && event.message.attachments.length > 0;
169
+ }
170
+ return false;
171
+ }
172
+ /**
173
+ * Check if event is from a group context
174
+ */
175
+ function isFromGroup(event) {
176
+ return 'group_id' in event || event.event_name.includes('group');
177
+ }
178
+ /**
179
+ * Check if event is from a personal context
180
+ */
181
+ function isFromPersonal(event) {
182
+ return !isFromGroup(event);
183
+ }
184
+ //# 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;;AAsCH,4DAIC;AAKD,8DAIC;AAKD,8DAIC;AAKD,4DAIC;AAKD,0DASC;AAOD,8CAIC;AAKD,gDAIC;AAKD,8CAIC;AAKD,oDAIC;AAKD,4CAIC;AAOD,wDAIC;AAKD,0DAIC;AAKD,wDAIC;AAKD,8DAIC;AAKD,sDAIC;AAOD,4CAeC;AAKD,gDAgBC;AAKD,wCAKC;AAKD,kCAEC;AAKD,wCAEC;AAlPD,8CAoB0B;AAa1B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