zalo-api
Version:
A wrapper library to help integrate with Zalo API.
296 lines (295 loc) • 8.06 kB
TypeScript
interface BaseOptions {
access_token: string;
}
interface PagingResponse<T> {
data: [T];
paging: {
next?: string;
previous?: string;
};
summary: {
total_count: number;
};
}
interface SocialBaseResponse {
error?: any;
}
export declare type AccessTokenOptions = {
app_id: string;
app_secret: string;
code: string;
redirect_uri?: string;
};
export interface AccessTokenResponse extends SocialBaseResponse {
access_token: string;
expires_in: number;
}
export interface ProfileOptions extends BaseOptions {
fields?: string;
}
export interface ProfileResponse extends SocialBaseResponse {
id?: string;
name?: string;
gender?: string;
birthday?: string;
picture?: {
data: {
url: string;
};
};
}
export interface FriendsOptions extends ProfileOptions {
limit: number;
offset: number;
}
export declare type FriendsResponse = PagingResponse<ProfileResponse>;
export interface SocialMessageOptions extends BaseOptions {
message: string;
link?: string;
to: string;
}
export interface SocialMessageResponse extends SocialBaseResponse {
to: string;
}
export interface AppRequestOptions extends BaseOptions {
message: string;
to: string;
}
export interface AppRequestResponse extends SocialBaseResponse {
to: [string];
}
export interface FeedOptions extends BaseOptions {
message: string;
link: string;
}
export interface FeedResponse extends SocialBaseResponse {
id: string;
}
interface OaMessageFactory<RT, MT> extends BaseOptions {
recipient: RT;
message: MT;
}
declare type OaBaseResponse = {
error: number;
message: string;
};
interface OaBaseResponseWithData<T> {
error: number;
message: string;
data: T;
}
/** Message recipient types */
declare type ReplyMessageRecipient = {
message_id: string;
};
declare type SendMessageRecipient = {
user_id: string;
};
declare type BroadcastRecipient = {
target: {
ages?: string;
gender?: string;
locations?: string;
cities?: string;
platforms?: string;
telcos?: string;
};
};
declare type MessageRecipientTypes = ReplyMessageRecipient | SendMessageRecipient;
declare type AllRecipientTypes = MessageRecipientTypes | BroadcastRecipient;
/** Mesage configs */
declare type UrlOpenAction = {
type: 'oa.open.url';
url: string;
};
declare type QueryShowHideAction = {
type: 'oa.query.show' | 'oa.query.hide';
payload: string;
};
declare type SmsOpenAction = {
type: 'oa.open.sms';
payload: {
content: string;
phone_code: string;
};
};
declare type PhoneOpenAction = {
type: 'oa.open.phone';
payload: {
phone_code: string;
};
};
declare type ListElementsOptions = {
title: string;
subtitle?: string;
image_url?: string;
default_action?: UrlOpenAction | QueryShowHideAction | SmsOpenAction | PhoneOpenAction;
};
declare type ButtonsOptions = {
title: string;
type: 'oa.open.url' | 'oa.query.show' | 'oa.query.hide' | 'oa.open.sms' | 'oa.open.phone';
payload: string | {
url: string;
} | {
phone_code: string;
content?: string;
};
};
/** Message types */
interface TextMessage {
text: string;
}
interface TemplateMessage<T> extends TextMessage {
attachment: {
type: 'template';
payload: T;
};
}
declare type ListTemplateMessage = TemplateMessage<{
template_type: 'list';
elements?: [ListElementsOptions];
buttons?: [ButtonsOptions];
}>;
declare type MediaTemplateMessage = TemplateMessage<{
template_type: 'media';
elements: [
{
media_type: string;
attachment_id: string;
width?: number;
height?: number;
}
];
}>;
declare type RequestInfoTemplateMessage = TemplateMessage<{
template_type: 'request_user_info';
elements: [ListElementsOptions];
}>;
declare type FileMessage = {
attachment: {
type: 'file';
payload: {
token: string;
};
};
};
declare type AllMessageTypes = TextMessage | ListTemplateMessage | MediaTemplateMessage | RequestInfoTemplateMessage | FileMessage;
export declare type OaMessageOptions = OaMessageFactory<AllRecipientTypes, AllMessageTypes>;
export declare type OaMessageResponse = OaBaseResponseWithData<{
message_id: string;
}>;
export declare type OaTextMessageOptions = OaMessageFactory<MessageRecipientTypes, TextMessage>;
export declare type OaMediaMessageOptions = OaMessageFactory<MessageRecipientTypes, MediaTemplateMessage>;
export declare type OaListMessageOptions = OaMessageFactory<MessageRecipientTypes, ListTemplateMessage>;
export declare type OaFileMessageOptions = OaMessageFactory<MessageRecipientTypes, FileMessage>;
export declare type OaRequestMessageOptions = OaMessageFactory<MessageRecipientTypes, RequestInfoTemplateMessage>;
export declare type OaBroadcastOptions = OaMessageFactory<BroadcastRecipient, MediaTemplateMessage>;
export declare type OaReplyMessageOptions = OaMessageFactory<ReplyMessageRecipient, AllMessageTypes>;
/** OA IPs */
export interface OaManageIpOptions extends BaseOptions {
ip: string;
name: string;
}
export declare type OaManageIpResponse = OaBaseResponse;
/** OA Get infos */
export interface OaGetFollowersOptions extends BaseOptions {
data: {
offset: number;
count: number;
};
}
export declare type OaGetFollowersResponse = OaBaseResponseWithData<{
total: number;
followers: [
{
user_id: string;
}
];
}>;
export interface OaGetProfileOptions extends BaseOptions {
data: {
user_id: string;
};
}
export declare type OaGetProfileResponse = OaBaseResponseWithData<{
user_gender: number;
user_id: number;
user_id_by_app: number;
avatar: string;
avatars: {
120: string;
240: string;
};
display_name: string;
birth_date: number;
shared_info: string;
tags_and_notes_info: {
tags_name: [any];
notes: [any];
};
}>;
export interface OaGetInfoOptions extends BaseOptions {
}
export declare type OaGetInfoResponse = OaBaseResponseWithData<{
oa_id: number;
description: string;
name: string;
avatar: string;
cover: string;
}>;
declare type OaChatData = {
msg_id: string;
src: number;
time: number;
type: string;
message: string;
links: string;
thumb: string;
url: string;
description: string;
from_id: string;
to_id: string;
from_display_name: string;
from_avatar: string;
to_display_name: string;
to_avatar: string;
location: string;
};
export interface OaGetRecentChatOptions extends OaGetFollowersOptions {
}
export declare type OaGetRecentChatResponse = OaBaseResponseWithData<[OaChatData]>;
export interface OaGetConversationOptions extends OaListMessageOptions {
user_id: number;
}
export declare type OaGetConversationResponse = OaGetRecentChatResponse;
/** OA Update follower info */
export interface OaUpdateFollowerInfoOptions extends BaseOptions {
user_id: number;
name: string;
phone: string;
address: string;
city_id: number;
district_id: number;
}
export declare type OaUpdateFollowerInfoReponse = OaBaseResponse;
/** OA upload APIs */
export interface OaUploadOptions extends BaseOptions {
file: BinaryType;
}
export declare type OaUploadImageResponse = OaBaseResponseWithData<{
attachment_id: string;
}>;
export declare type OaUploadFileResponse = OaBaseResponseWithData<{
token: string;
}>;
/** OA Tags management APIs */
export declare type OaListTagsOptions = BaseOptions;
export declare type OaListTagsResponse = OaBaseResponseWithData<[string]>;
export interface OaManageTagOptions extends BaseOptions {
tag_name: string;
}
export interface OaManageFollowerTagOptions extends OaManageTagOptions {
user_id: number;
}
export declare type OaManageTagResponse = OaBaseResponse;
export {};