Integrate with Zalo API easily. Support typescript with types of request and response following Zalo documentation.
Install with npm
npm i zalo-api
or yarn
yarn add zalo-api
Parameters
{
app_id: string,
app_secret: string,
code: string,
redirect_uri?: string
}
Return
{
access_token: string,
expires_in: number
}
Example
import { Social } from 'zalo-api';
const access_token = Social.access_token({
app_id: 'your_app_id', // process.env.zalo_app_id
app_secret: 'your_app_secret', // process.env.zalo_app_secret
code: 'your_oauth_code', // refer document here https://developers.zalo.me/docs/api/social-api/tham-khao/user-access-token-post-4316
})
Send generic message with all available parameters Parameters
{
access_token: string,
recipient: {
message_id?: string,
user_id?: string,
target?: {}
},
message: {
text?: string,
attachment?: {
type: 'template' | 'file',
payload: {
template_type?: 'list' | 'media' | 'request_user_info'
elements?: {} //Depends on types
buttons?: {}
...
}
}
}
}
Return (same for all message API)
{
error?: number,
message: string,
data?: {
message_id: string
}
}
Example
import { OA } from 'zalo-api';
const access_token = OA.message({
access_token: 'your_oa_access_token', // https://developers.zalo.me/docs/api/official-account-api/phu-luc/official-account-access-token-post-4307
recipient: {
user_id: 'user_id'
}
message: {
text: 'Hello Zalo API'
}
})