
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@warriorteam/zalo-webhook-types
Advanced tools
TypeScript types for Zalo Personal webhook events from automation-web
TypeScript types and utilities for Zalo Personal webhook events.
This SDK provides comprehensive type definitions for all 57 webhook event types from Zalo Personal API, organized into 4 main categories:
npm install @warriorteam/zalo-webhook-types
import {
ZaloWebhookEvent,
ZaloTextMessageEvent,
ZaloImageMessageEvent,
isTextMessage,
isImageMessage,
ZaloWebhookEventType
} from '@warriorteam/zalo-webhook-types';
// Type-safe event handling
function handleWebhookEvent(event: ZaloWebhookEvent) {
if (isTextMessage(event)) {
// TypeScript knows this is ZaloTextMessageEvent
console.log('Text message:', event.data.content);
} else if (isImageMessage(event)) {
// TypeScript knows this is ZaloImageMessageEvent
console.log('Image message:', event.data.content.href);
}
}
// Create events with proper typing
const textEvent: ZaloTextMessageEvent = {
eventType: ZaloWebhookEventType.TEXT_MESSAGE_RECEIVED_FROM_USER,
sessionId: 'session123',
userUuid: 'user456',
timestamp: Date.now(),
data: {
msgId: 'msg789',
content: 'Hello world!',
msgType: 'webchat',
// ... other required fields
}
};
TEXT_MESSAGE_SENT_TO_USERTEXT_MESSAGE_SENT_TO_GROUPTEXT_MESSAGE_RECEIVED_FROM_USERTEXT_MESSAGE_RECEIVED_FROM_GROUPLINK_MESSAGE_SENT_TO_USERLINK_MESSAGE_SENT_TO_GROUPLINK_MESSAGE_RECEIVED_FROM_USERLINK_MESSAGE_RECEIVED_FROM_GROUPFILE_MESSAGE_SENT_TO_USERFILE_MESSAGE_SENT_TO_GROUPFILE_MESSAGE_RECEIVED_FROM_USERFILE_MESSAGE_RECEIVED_FROM_GROUPTYPING - User typing indicatorSEEN_MESSAGES - Messages marked as readDELIVERED_MESSAGES - Messages delivered to recipientsREACTION - Message reactions (like, love, etc.)UNDO - Message recall/deletionFRIEND_EVENT - Friend requests, adds, removes, etc.GROUP_EVENT - Group joins, leaves, updates, etc.CONNECTION_STATUS - WebSocket connection statusERROR - System errorsOLD_MESSAGES - Historical message loadingOLD_REACTIONS - Historical reaction loadingUPLOAD_ATTACHMENT - File upload progressCIPHER_KEY - Encryption key updatesThe SDK provides comprehensive type guards for runtime type checking:
import {
isMessageEvent,
isInteractionEvent,
isSystemEvent,
isSocialEvent,
isTextMessage,
isImageMessage,
isVideoMessage,
isTypingEvent,
isReactionEvent
} from '@warriorteam/zalo-webhook-types';
function processEvent(event: ZaloWebhookEvent) {
// Category-level guards
if (isMessageEvent(event)) {
console.log('This is a message event');
}
// Specific type guards
if (isTextMessage(event)) {
console.log('Text content:', event.data.content);
}
if (isImageMessage(event)) {
console.log('Image URL:', event.data.content.href);
console.log('Image size:', event.data.content.width, 'x', event.data.content.height);
}
if (isTypingEvent(event)) {
console.log('User is typing:', event.data.isTyping);
}
}
The SDK provides specific content types for different message types:
import {
ZaloImageContent,
ZaloVideoContent,
ZaloVoiceContent,
ZaloFileContent,
ZaloLocationContent,
ZaloStickerContent
} from '@warriorteam/zalo-webhook-types';
// Image content
const imageContent: ZaloImageContent = {
href: 'https://example.com/image.jpg',
width: 1920,
height: 1080,
fileSize: 2048576,
fileName: 'image.jpg',
checksum: 'abc123',
caption: 'Beautiful sunset'
};
// Video content
const videoContent: ZaloVideoContent = {
href: 'https://example.com/video.mp4',
width: 1920,
height: 1080,
duration: 30000, // 30 seconds in milliseconds
fileSize: 10485760,
fileName: 'video.mp4',
checksum: 'def456'
};
// Location content
const locationContent: ZaloLocationContent = {
latitude: 10.762622,
longitude: 106.660172,
address: 'Ho Chi Minh City, Vietnam',
name: 'Landmark 81'
};
The SDK includes helpful utility functions:
import {
detectMessageType,
getMessageCategory,
createDetailedMessageEventType,
hasAttachment,
formatFileSize,
formatDuration,
sanitizeContentForLogging
} from '@warriorteam/zalo-webhook-types';
// Detect message type from SDK msgType
const messageType = detectMessageType('chat.photo'); // ZaloMessageType.PHOTO
// Get message category
const category = getMessageCategory(messageType); // ZaloMessageCategory.MEDIA
// Check if message has attachment
const hasFile = hasAttachment(messageType); // true
// Format file size
const sizeText = formatFileSize(2048576); // "2 MB"
// Format duration
const durationText = formatDuration(90000); // "1:30"
// Sanitize content for logging
const logText = sanitizeContentForLogging(imageContent); // "[Attachment: image.jpg]"
This SDK is built with TypeScript and provides full type safety:
import {
ZaloWebhookEvent,
isMessageEvent,
isTextMessage,
isImageMessage,
isTypingEvent,
isConnectionStatusEvent,
ZaloConnectionStatus
} from '@warriorteam/zalo-webhook-types';
class ZaloWebhookHandler {
handleEvent(event: ZaloWebhookEvent) {
console.log(`Received event: ${event.eventType}`);
if (isMessageEvent(event)) {
this.handleMessageEvent(event);
} else if (isTypingEvent(event)) {
this.handleTypingEvent(event);
} else if (isConnectionStatusEvent(event)) {
this.handleConnectionEvent(event);
}
}
private handleMessageEvent(event: ZaloAllMessageEvents) {
if (isTextMessage(event)) {
console.log(`Text from ${event.data.dName}: ${event.data.content}`);
} else if (isImageMessage(event)) {
console.log(`Image from ${event.data.dName}: ${event.data.content.href}`);
}
}
private handleTypingEvent(event: ZaloTypingEvent) {
const status = event.data.isTyping ? 'started' : 'stopped';
console.log(`${event.data.fromName} ${status} typing`);
}
private handleConnectionEvent(event: ZaloConnectionStatusEvent) {
if (event.data.status === ZaloConnectionStatus.CONNECTED) {
console.log('Connected to Zalo');
} else if (event.data.status === ZaloConnectionStatus.DISCONNECTED) {
console.log('Disconnected from Zalo');
}
}
}
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions, please open an issue on GitHub.
FAQs
TypeScript types for Zalo Personal webhook events from automation-web
We found that @warriorteam/zalo-webhook-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.