@warriorteam/zalo-webhook-types
Version:
TypeScript types for Zalo Personal webhook events from automation-web
85 lines • 3.22 kB
TypeScript
/**
* Utility Functions for Zalo Webhook Events
*
* Helper functions for working with webhook events and message content.
*/
import { ZaloWebhookEvent, ZaloMessageEventData } from '../types/base';
import { ZaloWebhookEventType, ZaloMessageType, ZaloMessageCategory, ZaloThreadType, MessageEventType } from '../enums';
import { ZaloMessageContent } from '../types/content';
/**
* Detect message type from SDK msgType
*/
export declare function detectMessageType(msgType: string): ZaloMessageType;
/**
* Get message category from message type
*/
export declare function getMessageCategory(msgType: ZaloMessageType): ZaloMessageCategory;
/**
* Create detailed message event type from basic info
*/
export declare function createDetailedMessageEventType(msgType: ZaloMessageType, threadType: ZaloThreadType, isSelf: boolean): MessageEventType;
/**
* Check if message has attachment based on message type
*/
export declare function hasAttachment(msgType: ZaloMessageType): boolean;
/**
* Extract thread ID from message data
*/
export declare function extractThreadId(data: ZaloMessageEventData): string;
/**
* Format timestamp from SDK ts string to number
*/
export declare function formatTimestamp(ts: string): number;
/**
* Get display name for thread
*/
export declare function getThreadDisplayName(data: ZaloMessageEventData, threadType: ZaloThreadType): string;
/**
* Check if message is from self
*/
export declare function isFromSelf(data: ZaloMessageEventData, currentUserId: string): boolean;
/**
* Get message content as string (for text messages)
*/
export declare function getTextContent(content: ZaloMessageContent): string;
/**
* Get file size in human readable format
*/
export declare function formatFileSize(bytes: number): string;
/**
* Format duration from milliseconds to human readable format
*/
export declare function formatDuration(milliseconds: number): string;
/**
* Get event category from event type
*/
export declare function getEventCategory(eventType: ZaloWebhookEventType): 'message' | 'interaction' | 'social' | 'system';
/**
* Check if event is sent event (from self)
*/
export declare function isSentEvent(eventType: ZaloWebhookEventType): boolean;
/**
* Check if event is received event (from others)
*/
export declare function isReceivedEvent(eventType: ZaloWebhookEventType): boolean;
/**
* Check if event is user event (1-on-1 chat)
*/
export declare function isUserEvent(eventType: ZaloWebhookEventType): boolean;
/**
* Check if event is group event (group chat)
*/
export declare function isGroupEvent(eventType: ZaloWebhookEventType): boolean;
/**
* Create a basic message event data structure
*/
export declare function createMessageEventData(msgId: string, msgType: ZaloMessageType, uidFrom: string, idTo: string, content: ZaloMessageContent, threadType: ZaloThreadType, isSelf: boolean, dName?: string, ts?: string): ZaloMessageEventData;
/**
* Validate webhook event structure
*/
export declare function validateWebhookEvent(event: any): event is ZaloWebhookEvent;
/**
* Sanitize message content for logging
*/
export declare function sanitizeContentForLogging(content: ZaloMessageContent): string;
//# sourceMappingURL=index.d.ts.map