npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zalo-sdk

v2.0.4

Published

NodeJS Library for Zalo

Downloads

47

Readme

Zalo SDK NodeJs

Zalo SDK is a library of functions that support Zalo Login and call OpenAPI. With Zalo SDK, you can easily use Open APIs of Zalo.

Getting Started

These instructions will get you a copy of the project up and run on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Installing Zalo SDK NodeJs

Install with:

npm install --save zalo-sdk

And import to your project:

// Using require() in ES5 
var Zalo = require('zalo-sdk');

Use Social API

Provides a way for your application to access data on Zalo's platform. Through the HTTP protocol, applications can query user data, friend data, post new information, and more.

To use the Social API, you need to register for the application on Zalo and follow the terms of Zalo. Click to view Zalo Developer Documentation For Open API.

Create an instance of the ZaloSocial class

var ZaloSocial = require('zalo-sdk').ZaloSocial;

var zsConfig = {
	appId: '1131677296116040198',
	redirectUri: 'http://localhost/login/zalo-callback',
	secretkey: 'your app secret'
};
var ZSClient = new ZaloSocial(zsConfig);

Before call any API, you must have Access Token . You can get Access Token by Oauth Code and set value of access_token after you initialize ZaloSocial Instance , (access_token will be exipred in 3600s). Click Social API Document to see how to get Oauth Code for your App.

var code = 'Your oauth code';
ZSClient.getAccessTokenByOauthCode(code, function(response) {
	if (response && response.access_token) {
		ZSClient.setAccessToken(response.access_token);
	}
});

Access User Information

ZSClient.api('me', 'GET', { fields: 'id, name, birthday, gender, picture' }, function(response) {
	console.log(response);
});

Access Friends List

ZSClient.api('me/friends', function(response) {
	console.log(response);
});

//Get list of your friends with offset and limit
ZSClient.api('me/friends', {offset: 10, limit: 50}, function(response) {
	console.log(response);
});

//Get  list of your friends who you can intvite to use your App.
ZSClient.api('me/invitable_friends', {offset: 10, limit: 50, fields: 'id, name, picture'}, function(response) {
	console.log(response);
});

Post Feed

ZSClient.api('me/feed', 'POST', {message: 'Lorem ipsum dolor sit amet !', link: 'https://developers.zalo.me/'}, function(response) {
	console.log(response);
});

Invite To Use The App

ZSClient.api('apprequests', 'POST', {to: '8549377444104328082', message: 'Lorem ipsum dolor sit amet !'},  function(response) {
	console.log(response);
});

Send A Message To Friends

ZSClient.api('me/message', 'POST', {to: '8549377444104328082', message: 'Lorem ipsum dolor sit amet !', link: 'https://developers.zalo.me/'},  function(response) {
	console.log(response);
});

Get Login Url

var loginUrl = ZSClient.getLoginUrl();
Format Login Url: https://oauth.zaloapp.com/v3/auth?app_id={1}&redirect_uri={2}

Login Flow

  1. Get login URL via ZSClient.getLoginUrl();
  2. After User login Zalo, Zalo Server will redirect to callback URL of App with OAuth Code and UserId. You can use this code to get Access Token via ZSClient.getAccessTokenByOauthCode(code).
  3. Get User's Profile by userId to verify User.

Use Official Account Open API

Provides a way for your application to access data on Zalo's platform. Through the HTTPS protocol, applications can interact with interested people on behalf of the Zalo Official Account.

To use the Official Account Open API you need to create an official account and register as 3rd party and follow the terms of Zalo.

Click to view Zalo Developer Documentation For Official Account Open API.

Create an instance of the ZaloOA class

var ZaloOA = require('zalo-sdk').ZaloOA;

var zaConfig = {
	oaid: '2491302944280861639',
	secretkey: 'your secret key'
}
var ZOAClient = new ZaloOA(zaConfig);

Get Profile Follower

var userId = 'user id or phone number';
ZOAClient.api('getprofile', { uid: userId }, function(response) {
	console.log(response);
})

Send Text Message

var userId = 'user id';
ZOAClient.api('sendmessage/text', 'POST', {uid: userId, message: 'Zalo SDK Nodejs Test Message'}, function(response) {
	console.log(response);
})

Get Message Status

ZOAClient.api('getmessagestatus', {msgid: 'fdb4c7ad668f37d16e9e'}, function(response) {
	console.log(response);
})

Upload Image

var fileUrl = 'url of file you want to upload or absolute file path';
ZOAClient.api('upload/image','POST', {file: fileUrl}, function(response) {
	console.log(response);
})

Upload Image Gif

var fileUrl = 'url of file you want to upload or absolute file path';
ZOAClient.api('upload/gif','POST', {file: fileUrl}, function(response) {
	console.log(response);
})

Send Image Message

ZOAClient.api('sendmessage/image', 'POST', {uid: '', message: 'Zalo SDK Nodejs', 'imageid': ''}, function(response) {
	console.log(response);
})

Send Gif Message

ZOAClient.api('sendmessage/gif', 'POST', {uid: '', width: '', height: '', 'imageid': ''}, function(response) {
	console.log(response);
})

Send Link Message

var params = {
	uid: '',
	links: [{
		link: 'https://developers.zalo.me/',
		linktitle: 'Zalo For Developers',
		linkdes: 'Document For Developers',
		linkthumb: 'https://developers.zalo.me/web/static/prodution/images/bg.jpg'
	}]
}
ZOAClient.api('sendmessage/links', 'POST', params, function(response) {
	console.log(response);
})

Send Interactive Messages

var params = {
	uid: '',
	actionlist: [{
		action: 'oa.open.inapp',
		title: 'Send interactive messages',
		description: 'This is a test for API send interactive messages',
		thumb: 'https://developers.zalo.me/web/static/prodution/images/bg.jpg',
		href: 'https://developers.zalo.me',
		data: 'https://developers.zalo.me',
		popup: {
			title: 'Open Website Zalo For Developers',
			desc: 'Click ok to visit Zalo For Developers and read more Document',
			ok: 'ok',
			cancel: 'cancel'
		}
	}]
}
ZOAClient.api('sendmessage/actionlist', 'POST', params, function(response) {
	console.log(response);
})

Send A Message Customer Support To The Phone Number

var params = {
	phone: '',
	templateid: '',
	templatedata: {}
}
ZOAClient.api('sendmessage/phone/cs', 'POST', params, function(response) {
	console.log(response);
})

Send A Message Customer Support

var params = {
	uid: '',
	templateid: '',
	templatedata: {}
}
ZOAClient.api('sendmessage/cs', 'POST', params, function(response) {
	console.log(response);
})

Send Sticker

ZOAClient.api('sendmessage/sticker', 'POST', {uid: '', stickerid: ''}, function(response) {
	console.log(response);
})

Reply Text Messages

ZOAClient.api('sendmessage/reply/text', 'POST', {msgid: '', message: ''}, function(response) {
	console.log(response);
})

Reply Image Messages

ZOAClient.api('sendmessage/reply/image', 'POST', {msgid: '', imageid: '', message: ''}, function(response) {
	console.log(response);
})

Reply Link Messages

ZOAClient.api('sendmessage/reply/links', 'POST', {msgid: '', links: ''}, function(response) {
	console.log(response);
})

Create QR Code

ZOAClient.api('qrcode', 'POST', {qrdata: '', size: ''}, function(response) {
	console.log(response);
})

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We will update more features in next version.

Authors

  • Tung Nguyen

License

This project is licensed under the MIT License - see the LICENSE.md file for details