UNPKG

@warriorteam/redai-zalo-sdk

Version:

Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Group Messaging, and Social APIs

219 lines 10 kB
import { ZaloClient } from "../clients/zalo-client"; import { ZNSMessage, ZNSSendResult, ZNSTemplateList, ZNSTemplateDetails, ZNSCreateTemplateRequest, ZNSUpdateTemplateRequest, ZNSTemplateCreateEditResponse, ZNSUploadImageResult, ZNSHashPhoneMessage, ZNSDevModeMessage, ZNSRsaMessage, ZNSJourneyMessage, ZNSMessageStatusInfo, ZNSQuotaInfo, ZNSAllowedContentTypes, ZNSTemplateSampleData, ZNSCustomerRatingResponse, ZNSOAQualityInfo } from "../types/zns"; /** * Service for Zalo Notification Service (ZNS) * * Requirements for using ZNS API: * - Official Account must be approved and have ZNS sending permission * - Valid Official Account access token * - ZNS template must be approved before use * - Recipient phone number must be in correct format and valid * - Template data must match defined parameters * - Comply with message quantity limits according to service package * * Reference: https://developers.zalo.me/docs/zalo-notification-service/ */ export declare class ZNSService { private readonly client; private readonly endpoints; constructor(client: ZaloClient); /** * Send ZNS message * @param accessToken OA access token * @param message ZNS message data * @returns Send result */ sendMessage(accessToken: string, message: ZNSMessage): Promise<ZNSSendResult>; /** * Send ZNS message with phone hash * @param accessToken OA access token * @param message ZNS message with hashed phone * @returns Send result */ sendHashPhoneMessage(accessToken: string, message: ZNSHashPhoneMessage): Promise<ZNSSendResult>; /** * Send ZNS message in development mode * @param accessToken OA access token * @param message ZNS dev mode message * @returns Send result */ sendDevModeMessage(accessToken: string, message: ZNSDevModeMessage): Promise<ZNSSendResult>; /** * Send ZNS message with RSA encryption * @param accessToken OA access token * @param message ZNS RSA message * @returns Send result */ sendRsaMessage(accessToken: string, message: ZNSRsaMessage): Promise<ZNSSendResult>; /** * Send ZNS journey message * @param accessToken OA access token * @param message ZNS journey message * @returns Send result */ sendJourneyMessage(accessToken: string, message: ZNSJourneyMessage): Promise<ZNSSendResult>; /** * Get ZNS message status * @param accessToken OA access token * @param messageId Message ID * @returns Message status info * * Response data: * - delivery_time: Thời gian thiết bị nhận được thông báo * - status: Trạng thái thông báo * * -1: The message does not exist * * 0: The message is pushed successfully to Zalo server but has not yet delivered to user's phone * * 1: The message was delivered to the user's phone * - message: Mô tả trạng thái thông báo */ getMessageStatus(accessToken: string, messageId: string): Promise<ZNSMessageStatusInfo>; /** * Get ZNS quota information * @param accessToken OA access token * @returns Quota information * * Response data: * - dailyQuota: Số thông báo ZNS OA được gửi trong 1 ngày * - remainingQuota: Số thông báo ZNS OA được gửi trong ngày còn lại * - dailyQuotaPromotion: Số tin ZNS hậu mãi OA được gửi trong ngày (null từ 1/11) * - remainingQuotaPromotion: Số tin ZNS hậu mãi còn lại OA được gửi trong ngày (null từ 1/11) * - monthlyPromotionQuota: Số tin ZNS hậu mãi OA được gửi trong tháng * - remainingMonthlyPromotionQuota: Số tin ZNS hậu mãi còn lại OA được gửi trong tháng * - estimatedNextMonthPromotionQuota: Số tin ZNS hậu mãi dự kiến mà OA có thể gửi trong tháng tiếp theo */ getQuotaInfo(accessToken: string): Promise<ZNSQuotaInfo>; /** * Get ZNS allowed content types * @param accessToken OA access token * @returns Allowed content types * * Response data: * - Mảng các loại nội dung mà OA có thể gửi: * * "TRANSACTION": Giao dịch (cấp độ 1) * * "CUSTOMER_CARE": Chăm sóc khách hàng (cấp độ 2) * * "PROMOTION": Hậu mãi (cấp độ 3) * - Dựa theo chất lượng gửi ZNS của OA, Zalo sẽ tự động điều chỉnh loại nội dung OA được gửi */ getAllowedContentTypes(accessToken: string): Promise<ZNSAllowedContentTypes>; /** * Get ZNS template list * @param accessToken OA access token * @param offset Offset for pagination (template được tạo gần nhất có thứ tự 0) * @param limit Limit for pagination (tối đa 100) * @param status Template status filter (optional) * @returns Template list * * Status values: * - 1: ENABLE templates * - 2: PENDING_REVIEW templates * - 3: REJECT templates * - 4: DISABLE templates * - undefined: All templates */ getTemplateList(accessToken: string, offset?: number, limit?: number, status?: 1 | 2 | 3 | 4): Promise<ZNSTemplateList>; /** * Get ZNS template details * @param accessToken OA access token * @param templateId Template ID * @returns Template details * * Response data: * - templateId: ID của template * - templateName: Tên của template * - status: Trạng thái template (ENABLE, PENDING_REVIEW, DELETE, REJECT, DISABLE) * - reason: Lý do template có trạng thái hiện tại * - listParams: Danh sách các thuộc tính của template * - listButtons: Danh sách các buttons/CTAs của template * - timeout: Thời gian timeout của template * - previewUrl: Đường dẫn đến bản xem trước của template * - templateQuality: Chất lượng template (null từ 10/12) * - templateTag: Loại nội dung (TRANSACTION, CUSTOMER_CARE, PROMOTION) * - price: Đơn giá của template */ getTemplateDetails(accessToken: string, templateId: string): Promise<ZNSTemplateDetails>; /** * Get ZNS template sample data * @param accessToken OA access token * @param templateId Template ID * @returns Template sample data * * Response data: * - Chứa tham số và dữ liệu mẫu của template * - Ví dụ: { "balance_debt": 2000, "due_date": "01/01/1970", "customer_name": "customer_name_sample" } */ getTemplateSampleData(accessToken: string, templateId: string): Promise<ZNSTemplateSampleData>; /** * Get customer rating information * @param accessToken OA access token * @param templateId Template ID * @param fromTime Start time (timestamp in milliseconds) * @param toTime End time (timestamp in milliseconds) * @param offset Position of first rating to return * @param limit Maximum number of ratings to return * @returns Customer rating information * * Lưu ý: * - Chỉ có thể lấy thông tin đánh giá từ template đánh giá dịch vụ được tạo bởi ứng dụng * - Access token phải ứng với template ID được tạo bởi app và OA * - Thời gian theo định dạng timestamp (millisecond) */ getCustomerRating(accessToken: string, templateId: string, fromTime: number, toTime: number, offset: number, limit: number): Promise<ZNSCustomerRatingResponse>; /** * Get OA ZNS sending quality information * @param accessToken OA access token * @returns OA quality information * * Response data: * - oaCurrentQuality: Chất lượng gửi ZNS trong 48 giờ gần nhất * - oa7dayQuality: Chất lượng gửi ZNS trong 7 ngày gần nhất * * Quality levels: * - HIGH: Mức độ chất lượng tốt * - MEDIUM: Mức độ chất lượng trung bình * - LOW: Mức độ chất lượng kém * - UNDEFINED: Chưa được xác định (OA không gửi ZNS trong khung thời gian đánh giá) */ getOAQuality(accessToken: string): Promise<ZNSOAQualityInfo>; /** * Create ZNS template * @param accessToken OA access token * @param templateData Template creation data theo chuẩn Zalo API * @returns Created template response * * API: POST https://business.openapi.zalo.me/template/create */ createTemplate(accessToken: string, templateData: ZNSCreateTemplateRequest): Promise<ZNSTemplateCreateEditResponse>; /** * Edit ZNS template (chỉnh sửa template có trạng thái REJECT) * @param accessToken OA access token * @param templateData Template edit data theo chuẩn Zalo API * @returns Edited template response * * Lưu ý: * - Chỉ có thể chỉnh sửa template có trạng thái REJECT * - Template sau khi chỉnh sửa sẽ chuyển về trạng thái PENDING_REVIEW * - Daily quota: 100 requests/ngày * - Cần quyền "Quản lý tài sản" * * API: POST https://business.openapi.zalo.me/template/edit */ updateTemplate(accessToken: string, templateData: ZNSUpdateTemplateRequest): Promise<ZNSTemplateCreateEditResponse>; /** * Upload image for ZNS template * @param accessToken OA access token * @param imageFile Image file (Buffer or ReadableStream) * @param filename Filename with extension * @returns Upload result with media_id * * Lưu ý: * - Định dạng hỗ trợ: JPG, PNG * - Dung lượng tối đa: 500KB * - Hạn mức: 5000 ảnh/tháng/app * - Logo: PNG, 400x96px * - Hình ảnh: JPG/PNG, tỉ lệ 16:9 * - Cần quyền "Quản lý tài sản" */ uploadImage(accessToken: string, imageFile: Buffer | NodeJS.ReadableStream, filename?: string): Promise<ZNSUploadImageResult>; private handleZNSError; } //# sourceMappingURL=zns.service.d.ts.map