Zalo connection with JavaScript
Author: Cu Nguyen <cunguyen.dev@gmail.com>
Deploy to Netlify: https://zalo-connection.netlify.app/
Step by step to add zalo chat plugin into your app
Go to Zalo API to create and get an OAID (Offcial Account ID).
class ZaloChatPlugin {
constructor(oaid) {
this.oaid = oaid;
this.body = document.querySelector('body');
}
/**
* Render zalo chat window with welcome message
* @param {string} message
*/
render() {
const zaloNode = document.createElement('div');
zaloNode.setAttribute('class', 'zalo-chat-widget');
zaloNode.setAttribute('data-oaid', this.oaid);
this.body.appendChild(zaloNode);
}
}
export default ZaloChatPlugin;
Note that, you have to pass your OAID when call the constructor
import ZaloChatPlugin from '../plugins/zalo';
/**
* Your oaid (Offcial Account)
* Read the document here: https://developers.zalo.me/docs/api/official-account-api-147
*/
const zaloChatPlugin = new ZaloChatPlugin('2445522973757062543');
zaloChatPlugin.render();
Step by step to run this app in your local
At your directory root, run:
npm/yarn install
npm/yarn start
Open on web: http://localhost:1234 (this is by default, you can custom it)
npm/yarn run build
You can update the source structures to follow your patterns.
Note: Live-reload is supported