zalo-api-service

A wrapper library to help integrate with Zalo API.

Usage no npm install needed!

<script type="module">
  import zaloApiService from 'https://cdn.skypack.dev/zalo-api-service';
</script>

README

Zalo API

Integrate with Zalo API easily. Support typescript with types of request and response following Zalo documentation.

Getting started

Install with npm

npm i zalo-api

or yarn

yarn add zalo-api

Zalo API mapping

| Zalo docs | This library | Status | |:-|:-|:-:| | Social API | | Get access token | Social.access_token() | :white_check_mark: | | Send message to friend | Social.message() | :white_check_mark: | | Invite friend | Social.app_request() | :white_check_mark: | Post feed | Social.feed() | :white_check_mark: | | List friends | Social.friends() | :white_check_mark: | | Invitable friends | Social.invitable_friends() | :white_check_mark: | | Get profile | Social.profile() | :white_check_mark: | | Official Account API | | Reply follower's message | OA.reply_message() | :white_check_mark: | | Send message | OA.message()
Shortcut APIs:
OA.text_message()
OA.media_message()
OA.list_message()
OA.request_info_message() | :white_check_mark: | | Broadcast | OA.broadcast() | :white_check_mark: | | Update follower info | OA.update_follower_info() | :white_check_mark: | | Manage IP | OA.register_ip()
OA.remove_ip() | :white_check_mark: | | Get infos | OA.get_followers()
OA.get_profile()
OA.get_info()
OA.get_recent_chat()
OA.get_conversation() | :white_check_mark: | | Upload image/file | OA.upload_image()
OA.upload_gif()
OA.upload_file() | :white_check_mark: | | Get/assign/remove tags | OA.list_tags()
OA.assign_tag()
OA.remove_follower_tag()
OA.delete_tag() | :white_check_mark: | | Shop API| | Attributes type CRUD | | :white_square_button: | | Upload photo | | :white_square_button: | | Get industry | | :white_square_button: | | Category | | :white_square_button: | | Create order | | :white_square_button: | | Manage order | | :white_square_button: | | Products | | :white_square_button: | | Article API| | Create article | | :white_square_button: | | Upload video for article | | :white_square_button: | | Get article ID | | :white_square_button: | | Get article details | | :white_square_button: | | Get list articles | | :white_square_button: | | Delete article | | :white_square_button: | | Update article | | :white_square_button: |

Using Zalo API integration

Social API

Get access token

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
})

Official Account API

OA Message

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'
  }
})