@warriorteam/redai-zalo-sdk 1.1.0 → 1.2.0

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,806 @@
1
+ # Webhook Events Documentation
2
+
3
+ This document describes the webhook event types and DTOs for Zalo Official Account webhooks.
4
+
5
+ ## Overview
6
+
7
+ The Zalo SDK provides comprehensive TypeScript types for all webhook events sent by Zalo to your application. These events are strongly typed and include proper payload structures for each event type.
8
+
9
+ ## Event Categories
10
+
11
+ ### 1. Message Events
12
+
13
+ Events triggered when users interact with your Official Account through messages.
14
+
15
+ ### 2. User Action Events
16
+
17
+ Events triggered when users perform actions like following your Official Account.
18
+
19
+ ### 3. Legacy Events
20
+
21
+ Backward compatibility events for existing integrations.
22
+
23
+ ## Message Events
24
+
25
+ ### User Send Text Event
26
+
27
+ ```typescript
28
+ import { UserSendTextEvent } from "redai-zalo-sdk";
29
+
30
+ const textEvent: UserSendTextEvent = {
31
+ app_id: "3482178216594085616",
32
+ user_id_by_app: "3216904426693862293",
33
+ event_name: "user_send_text",
34
+ timestamp: "1754405178258",
35
+ sender: { id: "4411682737790366300" },
36
+ recipient: { id: "579745863508352884" },
37
+ message: {
38
+ msg_id: "message_id_123",
39
+ text: "Hello from user",
40
+ },
41
+ };
42
+ ```
43
+
44
+ ### User Send Image Event
45
+
46
+ ```typescript
47
+ import { UserSendImageEvent } from "redai-zalo-sdk";
48
+
49
+ const imageEvent: UserSendImageEvent = {
50
+ app_id: "3482178216594085616",
51
+ user_id_by_app: "3216904426693862293",
52
+ event_name: "user_send_image",
53
+ timestamp: "1754405178258",
54
+ sender: { id: "4411682737790366300" },
55
+ recipient: { id: "579745863508352884" },
56
+ message: {
57
+ msg_id: "message_id_123",
58
+ text: "Check out this image",
59
+ attachments: [
60
+ {
61
+ type: "image",
62
+ payload: {
63
+ thumbnail: "https://example.com/thumb.jpg",
64
+ url: "https://example.com/image.jpg",
65
+ },
66
+ },
67
+ ],
68
+ },
69
+ };
70
+ ```
71
+
72
+ ### User Send Location Event
73
+
74
+ ```typescript
75
+ import { UserSendLocationEvent } from "redai-zalo-sdk";
76
+
77
+ const locationEvent: UserSendLocationEvent = {
78
+ app_id: "3482178216594085616",
79
+ user_id_by_app: "3216904426693862293",
80
+ event_name: "user_send_location",
81
+ timestamp: "1754405178257",
82
+ sender: { id: "4411682737790366300" },
83
+ recipient: { id: "579745863508352884" },
84
+ message: {
85
+ msg_id: "message_id_123",
86
+ text: "My current location",
87
+ attachments: [
88
+ {
89
+ type: "location",
90
+ payload: {
91
+ coordinates: {
92
+ latitude: "10.7642473",
93
+ longitude: "106.6564313999999",
94
+ },
95
+ },
96
+ },
97
+ ],
98
+ },
99
+ };
100
+ ```
101
+
102
+ ### User Send Link Event
103
+
104
+ ```typescript
105
+ import { UserSendLinkEvent } from "redai-zalo-sdk";
106
+
107
+ const linkEvent: UserSendLinkEvent = {
108
+ app_id: "3482178216594085616",
109
+ user_id_by_app: "3216904426693862293",
110
+ event_name: "user_send_link",
111
+ timestamp: "1754405178258",
112
+ sender: { id: "4411682737790366300" },
113
+ recipient: { id: "579745863508352884" },
114
+ message: {
115
+ msg_id: "message_id_123",
116
+ text: "Check this link",
117
+ attachments: [
118
+ {
119
+ type: "link",
120
+ payload: {
121
+ thumbnail: "https://example.com/thumb.jpg",
122
+ description: "Interesting article",
123
+ url: "https://example.com/article",
124
+ },
125
+ },
126
+ ],
127
+ },
128
+ };
129
+ ```
130
+
131
+ ### User Send Sticker Event
132
+
133
+ ```typescript
134
+ import { UserSendStickerEvent } from "redai-zalo-sdk";
135
+
136
+ const stickerEvent: UserSendStickerEvent = {
137
+ app_id: "3482178216594085616",
138
+ user_id_by_app: "3216904426693862293",
139
+ event_name: "user_send_sticker",
140
+ timestamp: "1754405178259",
141
+ sender: { id: "4411682737790366300" },
142
+ recipient: { id: "579745863508352884" },
143
+ message: {
144
+ msg_id: "message_id_123",
145
+ text: "😊",
146
+ attachments: [
147
+ {
148
+ type: "sticker",
149
+ payload: {
150
+ id: "sticker_123",
151
+ url: "https://example.com/sticker.png",
152
+ },
153
+ },
154
+ ],
155
+ },
156
+ };
157
+ ```
158
+
159
+ ### User Send GIF Event
160
+
161
+ ```typescript
162
+ import { UserSendGifEvent } from "redai-zalo-sdk";
163
+
164
+ const gifEvent: UserSendGifEvent = {
165
+ app_id: "3482178216594085616",
166
+ user_id_by_app: "3216904426693862293",
167
+ event_name: "user_send_gif",
168
+ timestamp: "1754405178259",
169
+ sender: { id: "4411682737790366300" },
170
+ recipient: { id: "579745863508352884" },
171
+ message: {
172
+ msg_id: "message_id_123",
173
+ text: "Funny GIF",
174
+ attachments: [
175
+ {
176
+ type: "gif",
177
+ payload: {
178
+ thumbnail: "https://example.com/gif_thumb.jpg",
179
+ url: "https://example.com/funny.gif",
180
+ },
181
+ },
182
+ ],
183
+ },
184
+ };
185
+ ```
186
+
187
+ ### User Send Audio Event
188
+
189
+ ```typescript
190
+ import { UserSendAudioEvent } from "redai-zalo-sdk";
191
+
192
+ const audioEvent: UserSendAudioEvent = {
193
+ app_id: "3482178216594085616",
194
+ user_id_by_app: "3216904426693862293",
195
+ event_name: "user_send_audio",
196
+ timestamp: "1754405178259",
197
+ sender: { id: "4411682737790366300" },
198
+ recipient: { id: "579745863508352884" },
199
+ message: {
200
+ msg_id: "message_id_123",
201
+ text: "Voice message",
202
+ attachments: [
203
+ {
204
+ type: "audio",
205
+ payload: {
206
+ url: "https://example.com/voice.mp3",
207
+ },
208
+ },
209
+ ],
210
+ },
211
+ };
212
+ ```
213
+
214
+ ### User Send Video Event
215
+
216
+ ```typescript
217
+ import { UserSendVideoEvent } from "redai-zalo-sdk";
218
+
219
+ const videoEvent: UserSendVideoEvent = {
220
+ app_id: "3482178216594085616",
221
+ user_id_by_app: "3216904426693862293",
222
+ event_name: "user_send_video",
223
+ timestamp: "1754405178261",
224
+ sender: { id: "4411682737790366300" },
225
+ recipient: { id: "579745863508352884" },
226
+ message: {
227
+ msg_id: "message_id_123",
228
+ text: "Check out this video",
229
+ attachments: [
230
+ {
231
+ type: "video",
232
+ payload: {
233
+ thumbnail: "https://example.com/video_thumb.jpg",
234
+ description: "Amazing video content",
235
+ url: "https://example.com/video.mp4",
236
+ },
237
+ },
238
+ ],
239
+ },
240
+ };
241
+ ```
242
+
243
+ ### User Send File Event
244
+
245
+ ```typescript
246
+ import { UserSendFileEvent } from "redai-zalo-sdk";
247
+
248
+ const fileEvent: UserSendFileEvent = {
249
+ app_id: "3482178216594085616",
250
+ user_id_by_app: "3216904426693862293",
251
+ event_name: "user_send_file",
252
+ timestamp: "1754405178261",
253
+ sender: { id: "4411682737790366300" },
254
+ recipient: { id: "579745863508352884" },
255
+ message: {
256
+ msg_id: "message_id_123",
257
+ attachments: [
258
+ {
259
+ type: "file",
260
+ payload: {
261
+ url: "https://example.com/document.pdf",
262
+ size: "1024000",
263
+ name: "important_document.pdf",
264
+ checksum: "abc123def456",
265
+ type: "application/pdf",
266
+ },
267
+ },
268
+ ],
269
+ },
270
+ };
271
+ ```
272
+
273
+ ### User Received Message Event
274
+
275
+ ```typescript
276
+ import { UserReceivedMessageEvent } from "redai-zalo-sdk";
277
+
278
+ const receivedEvent: UserReceivedMessageEvent = {
279
+ app_id: "3482178216594085616",
280
+ user_id_by_app: "3216904426693862293",
281
+ event_name: "user_received_message",
282
+ timestamp: "1754405178259",
283
+ sender: { id: "579745863508352884" }, // OA sent
284
+ recipient: { id: "4411682737790366300" }, // User received
285
+ message: {
286
+ msg_id: "message_id_123",
287
+ },
288
+ };
289
+ ```
290
+
291
+ ### User Seen Message Event
292
+
293
+ ```typescript
294
+ import { UserSeenMessageEvent } from "redai-zalo-sdk";
295
+
296
+ const seenEvent: UserSeenMessageEvent = {
297
+ app_id: "3482178216594085616",
298
+ user_id_by_app: "3216904426693862293",
299
+ event_name: "user_seen_message",
300
+ timestamp: "1754405178259",
301
+ sender: { id: "579745863508352884" }, // OA
302
+ recipient: { id: "4411682737790366300" }, // User
303
+ message: {
304
+ msg_ids: ["message_id_123", "message_id_124"],
305
+ },
306
+ };
307
+ ```
308
+
309
+ ## User Action Events
310
+
311
+ ### User Follow Event
312
+
313
+ ```typescript
314
+ import { UserFollowEvent } from "redai-zalo-sdk";
315
+
316
+ const followEvent: UserFollowEvent = {
317
+ app_id: "3482178216594085616",
318
+ user_id_by_app: "3216904426693862293",
319
+ event_name: "follow",
320
+ timestamp: "1754405178260",
321
+ oa_id: "579745863508352884",
322
+ source: "testing_webhook",
323
+ follower: {
324
+ id: "4411682737790366300",
325
+ },
326
+ };
327
+ ```
328
+
329
+ ### User Unfollow Event
330
+
331
+ ```typescript
332
+ import { UserUnfollowEvent } from "redai-zalo-sdk";
333
+
334
+ const unfollowEvent: UserUnfollowEvent = {
335
+ app_id: "3482178216594085616",
336
+ user_id_by_app: "3216904426693862293",
337
+ event_name: "unfollow",
338
+ timestamp: "1754405178260",
339
+ oa_id: "579745863508352884",
340
+ source: "testing_webhook",
341
+ follower: {
342
+ id: "4411682737790366300",
343
+ },
344
+ };
345
+ ```
346
+
347
+ ### User Submit Info Event
348
+
349
+ ```typescript
350
+ import { UserSubmitInfoEvent } from "redai-zalo-sdk";
351
+
352
+ const submitInfoEvent: UserSubmitInfoEvent = {
353
+ app_id: "3482178216594085616",
354
+ user_id_by_app: "3216904426693862293",
355
+ event_name: "user_submit_info",
356
+ timestamp: "1754405178260",
357
+ sender: { id: "4411682737790366300" },
358
+ recipient: { id: "579745863508352884" },
359
+ info: {
360
+ address: "123 Main Street",
361
+ phone: "0123456789",
362
+ city: "Ho Chi Minh City",
363
+ district: "District 1",
364
+ name: "John Doe",
365
+ ward: "Ward 1",
366
+ },
367
+ };
368
+ ```
369
+
370
+ ## Shop Events
371
+
372
+ ### Shop Has Order Event
373
+
374
+ ```typescript
375
+ import { ShopHasOrderEvent } from "redai-zalo-sdk";
376
+
377
+ const orderEvent: ShopHasOrderEvent = {
378
+ app_id: "3482178216594085616",
379
+ user_id_by_app: "3216904426693862293",
380
+ event_name: "shop_has_order",
381
+ timestamp: "1754405178260",
382
+ oa_id: "579745863508352884",
383
+ customer: {
384
+ id: "4411682737790366300",
385
+ },
386
+ };
387
+ ```
388
+
389
+ ## OA Message Events
390
+
391
+ ### OA Send Text Event
392
+
393
+ ```typescript
394
+ import { OASendTextEvent } from "redai-zalo-sdk";
395
+
396
+ const oaTextEvent: OASendTextEvent = {
397
+ app_id: "3482178216594085616",
398
+ user_id_by_app: "3216904426693862293",
399
+ event_name: "oa_send_text",
400
+ timestamp: "1754405178260",
401
+ sender: { id: "579745863508352884" },
402
+ recipient: { id: "4411682737790366300" },
403
+ message: {
404
+ msg_id: "oa_message_123",
405
+ text: "Hello from Official Account",
406
+ },
407
+ };
408
+ ```
409
+
410
+ ### OA Send Image Event
411
+
412
+ ```typescript
413
+ import { OASendImageEvent } from "redai-zalo-sdk";
414
+
415
+ const oaImageEvent: OASendImageEvent = {
416
+ app_id: "3482178216594085616",
417
+ user_id_by_app: "3216904426693862293",
418
+ event_name: "oa_send_image",
419
+ timestamp: "1754405178260",
420
+ sender: { id: "579745863508352884" },
421
+ recipient: { id: "4411682737790366300" },
422
+ message: {
423
+ msg_id: "oa_message_123",
424
+ text: "Check out our product",
425
+ attachments: [
426
+ {
427
+ type: "image",
428
+ payload: {
429
+ thumbnail: "https://example.com/thumb.jpg",
430
+ url: "https://example.com/product.jpg",
431
+ },
432
+ },
433
+ ],
434
+ },
435
+ };
436
+ ```
437
+
438
+ ### OA Send List Event (Interactive Message)
439
+
440
+ ```typescript
441
+ import { OASendListEvent } from "redai-zalo-sdk";
442
+
443
+ const oaListEvent: OASendListEvent = {
444
+ app_id: "3482178216594085616",
445
+ user_id_by_app: "3216904426693862293",
446
+ event_name: "oa_send_list",
447
+ timestamp: "1754405178260",
448
+ sender: { id: "579745863508352884" },
449
+ recipient: { id: "4411682737790366300" },
450
+ message: {
451
+ msg_id: "oa_message_123",
452
+ text: "Choose from our options",
453
+ attachments: [
454
+ {
455
+ type: "link",
456
+ payload: {
457
+ thumbnail: "https://example.com/option1.jpg",
458
+ description: "Option 1 description",
459
+ url: "https://example.com/option1",
460
+ title: "Option 1",
461
+ },
462
+ },
463
+ {
464
+ type: "link",
465
+ payload: {
466
+ thumbnail: "https://example.com/option2.jpg",
467
+ description: "Option 2 description",
468
+ url: "https://example.com/option2",
469
+ title: "Option 2",
470
+ },
471
+ },
472
+ ],
473
+ },
474
+ };
475
+ ```
476
+
477
+ ### OA Send File Event
478
+
479
+ ```typescript
480
+ import { OASendFileEvent } from "redai-zalo-sdk";
481
+
482
+ const oaFileEvent: OASendFileEvent = {
483
+ app_id: "3482178216594085616",
484
+ user_id_by_app: "3216904426693862293",
485
+ event_name: "oa_send_file",
486
+ timestamp: "1754405178261",
487
+ sender: { id: "579745863508352884" },
488
+ recipient: { id: "4411682737790366300" },
489
+ message: {
490
+ msg_id: "oa_message_123",
491
+ attachments: [
492
+ {
493
+ type: "file",
494
+ payload: {
495
+ url: "https://example.com/document.pdf",
496
+ size: "1024000",
497
+ name: "important_document.pdf",
498
+ checksum: "abc123def456",
499
+ type: "application/pdf",
500
+ },
501
+ },
502
+ ],
503
+ },
504
+ };
505
+ ```
506
+
507
+ ### OA Send Sticker Event
508
+
509
+ ```typescript
510
+ import { OASendStickerEvent } from "redai-zalo-sdk";
511
+
512
+ const oaStickerEvent: OASendStickerEvent = {
513
+ app_id: "3482178216594085616",
514
+ user_id_by_app: "3216904426693862293",
515
+ event_name: "oa_send_sticker",
516
+ timestamp: "1754405178261",
517
+ sender: { id: "579745863508352884" },
518
+ recipient: { id: "4411682737790366300" },
519
+ message: {
520
+ msg_id: "oa_message_123",
521
+ text: "Have a great day!",
522
+ attachments: [
523
+ {
524
+ type: "sticker",
525
+ payload: {
526
+ id: "sticker_123",
527
+ url: "https://example.com/sticker.png",
528
+ },
529
+ },
530
+ ],
531
+ },
532
+ };
533
+ ```
534
+
535
+ ## User Interaction Events
536
+
537
+ ### User Click Chat Now Event
538
+
539
+ ```typescript
540
+ import { UserClickChatNowEvent } from "redai-zalo-sdk";
541
+
542
+ const clickChatEvent: UserClickChatNowEvent = {
543
+ app_id: "3482178216594085616",
544
+ user_id_by_app: "3216904426693862293",
545
+ event_name: "user_click_chatnow",
546
+ timestamp: "1754405178261",
547
+ oa_id: "579745863508352884",
548
+ user_id: "4411682737790366300",
549
+ };
550
+ ```
551
+
552
+ ### User Reacted Message Event
553
+
554
+ ```typescript
555
+ import { UserReactedMessageEvent } from "redai-zalo-sdk";
556
+
557
+ const userReactionEvent: UserReactedMessageEvent = {
558
+ app_id: "3482178216594085616",
559
+ user_id_by_app: "3216904426693862293",
560
+ event_name: "user_reacted_message",
561
+ timestamp: "1754405178261",
562
+ sender: { id: "4411682737790366300" },
563
+ recipient: { id: "579745863508352884" },
564
+ message: {
565
+ msg_id: "message_123",
566
+ react_icon: "👍",
567
+ },
568
+ };
569
+ ```
570
+
571
+ ### OA Reacted Message Event
572
+
573
+ ```typescript
574
+ import { OAReactedMessageEvent } from "redai-zalo-sdk";
575
+
576
+ const oaReactionEvent: OAReactedMessageEvent = {
577
+ app_id: "3482178216594085616",
578
+ user_id_by_app: "3216904426693862293",
579
+ event_name: "oa_reacted_message",
580
+ timestamp: "1754405178261",
581
+ sender: { id: "579745863508352884" },
582
+ recipient: { id: "4411682737790366300" },
583
+ message: {
584
+ msg_id: "message_123",
585
+ react_icon: "❤️",
586
+ },
587
+ };
588
+ ```
589
+
590
+ ## Consent Events
591
+
592
+ ### OA Send Consent Event
593
+
594
+ ```typescript
595
+ import { OASendConsentEvent } from "redai-zalo-sdk";
596
+
597
+ const consentEvent: OASendConsentEvent = {
598
+ app_id: "3482178216594085616",
599
+ user_id_by_app: "3216904426693862293",
600
+ event_name: "oa_send_consent",
601
+ timestamp: "1754405178261",
602
+ oa_id: "579745863508352884",
603
+ request_type: "SENT",
604
+ create_time: "1754405178261",
605
+ expired_time: "1754405178261",
606
+ phone: "84773543888",
607
+ };
608
+ ```
609
+
610
+ ### User Reply Consent Event
611
+
612
+ ```typescript
613
+ import { UserReplyConsentEvent } from "redai-zalo-sdk";
614
+
615
+ const replyConsentEvent: UserReplyConsentEvent = {
616
+ app_id: "3482178216594085616",
617
+ user_id_by_app: "3216904426693862293",
618
+ event_name: "user_reply_consent",
619
+ timestamp: "1754405178261",
620
+ oa_id: "579745863508352884",
621
+ expired_time: "1754405178261",
622
+ confirmed_time: "1754405178261",
623
+ phone: "84773543888",
624
+ };
625
+ ```
626
+
627
+ ## Anonymous User Events
628
+
629
+ ### Anonymous Send Text Event
630
+
631
+ ```typescript
632
+ import { AnonymousSendTextEvent } from "redai-zalo-sdk";
633
+
634
+ const anonymousTextEvent: AnonymousSendTextEvent = {
635
+ app_id: "3482178216594085616",
636
+ user_id_by_app: "3216904426693862293",
637
+ event_name: "anonymous_send_text",
638
+ timestamp: "1754405178261",
639
+ sender: { id: "4411682737790366300" },
640
+ recipient: { id: "579745863508352884" },
641
+ message: {
642
+ msg_id: "message_123",
643
+ text: "Anonymous message",
644
+ conversation_id: "conversation_123",
645
+ },
646
+ };
647
+ ```
648
+
649
+ ### Anonymous Send Image Event
650
+
651
+ ```typescript
652
+ import { AnonymousSendImageEvent } from "redai-zalo-sdk";
653
+
654
+ const anonymousImageEvent: AnonymousSendImageEvent = {
655
+ app_id: "3482178216594085616",
656
+ user_id_by_app: "3216904426693862293",
657
+ event_name: "anonymous_send_image",
658
+ timestamp: "1754405178262",
659
+ sender: { id: "4411682737790366300" },
660
+ recipient: { id: "579745863508352884" },
661
+ message: {
662
+ msg_id: "message_123",
663
+ text: "Anonymous image",
664
+ conversation_id: "conversation_123",
665
+ attachments: [
666
+ {
667
+ type: "image",
668
+ payload: {
669
+ thumbnail: "https://example.com/thumb.jpg",
670
+ url: "https://example.com/image.jpg",
671
+ },
672
+ },
673
+ ],
674
+ },
675
+ };
676
+ ```
677
+
678
+ ### Anonymous Send File Event
679
+
680
+ ```typescript
681
+ import { AnonymousSendFileEvent } from "redai-zalo-sdk";
682
+
683
+ const anonymousFileEvent: AnonymousSendFileEvent = {
684
+ app_id: "3482178216594085616",
685
+ user_id_by_app: "3216904426693862293",
686
+ event_name: "anonymous_send_file",
687
+ timestamp: "1754405178262",
688
+ sender: { id: "4411682737790366300" },
689
+ recipient: { id: "579745863508352884" },
690
+ message: {
691
+ msg_id: "message_123",
692
+ conversation_id: "conversation_123",
693
+ attachments: [
694
+ {
695
+ type: "file",
696
+ payload: {
697
+ url: "https://example.com/document.pdf",
698
+ size: "1024000",
699
+ name: "document.pdf",
700
+ checksum: "abc123def456",
701
+ type: "application/pdf",
702
+ },
703
+ },
704
+ ],
705
+ },
706
+ };
707
+ ```
708
+
709
+ ## Type Guards and Utilities
710
+
711
+ ### Check Event Type
712
+
713
+ ```typescript
714
+ import {
715
+ isMessageEvent,
716
+ isFollowEvent,
717
+ hasAttachments,
718
+ WebhookEvent,
719
+ } from "redai-zalo-sdk";
720
+
721
+ function handleWebhook(event: WebhookEvent) {
722
+ if (isMessageEvent(event)) {
723
+ console.log("Message event:", event.event_name);
724
+
725
+ if (hasAttachments(event.message)) {
726
+ console.log("Has attachments:", event.message.attachments.length);
727
+ }
728
+ }
729
+
730
+ if (isFollowEvent(event)) {
731
+ console.log("New follower:", event.follower.id);
732
+ }
733
+ }
734
+ ```
735
+
736
+ ### Using Enums
737
+
738
+ ```typescript
739
+ import { WebhookEventName, AttachmentType } from "redai-zalo-sdk";
740
+
741
+ function processEvent(event: WebhookEvent) {
742
+ switch (event.event_name) {
743
+ case WebhookEventName.USER_SEND_TEXT:
744
+ console.log("Text message received");
745
+ break;
746
+
747
+ case WebhookEventName.USER_SEND_IMAGE:
748
+ console.log("Image message received");
749
+ break;
750
+
751
+ case WebhookEventName.FOLLOW:
752
+ console.log("User followed OA");
753
+ break;
754
+ }
755
+ }
756
+ ```
757
+
758
+ ## Webhook Handler Setup
759
+
760
+ ```typescript
761
+ import { WebhookHandlers, UserSendTextEvent } from "redai-zalo-sdk";
762
+
763
+ const handlers: WebhookHandlers = {
764
+ user_send_text: async (event: UserSendTextEvent) => {
765
+ console.log(`User ${event.sender.id} sent: ${event.message.text}`);
766
+ // Handle text message
767
+ },
768
+
769
+ user_send_image: async (event) => {
770
+ console.log(`User sent image: ${event.message.attachments[0].payload.url}`);
771
+ // Handle image message
772
+ },
773
+
774
+ follow: async (event) => {
775
+ console.log(`New follower: ${event.follower.id}`);
776
+ // Handle follow event
777
+ },
778
+
779
+ "*": async (event) => {
780
+ console.log(`Unhandled event: ${event.event_name}`);
781
+ // Catch-all handler
782
+ },
783
+ };
784
+ ```
785
+
786
+ ## Best Practices
787
+
788
+ 1. **Type Safety**: Always use the specific event types instead of generic ones
789
+ 2. **Type Guards**: Use provided type guards to safely check event types
790
+ 3. **Error Handling**: Implement proper error handling for webhook processing
791
+ 4. **Validation**: Validate webhook signatures for security
792
+ 5. **Async Processing**: Use async handlers for database operations or API calls
793
+
794
+ ## Migration from Legacy Types
795
+
796
+ If you're migrating from the old `UserSendMessageEvent` type:
797
+
798
+ ```typescript
799
+ // Old way (deprecated)
800
+ user_send_text?: WebhookHandler<UserSendMessageEvent>;
801
+
802
+ // New way (recommended)
803
+ user_send_text?: WebhookHandler<UserSendTextEvent>;
804
+ ```
805
+
806
+ The new types provide better type safety and more specific payload structures for each event type.