Zoom Node.js Chatbot Library
The Zoom Node.js Chatbot Library wraps OAuth2, receiving slash commands and user actions, sending messages, and making requests to the Zoom API into easy to use functions you can import in your Node.js app.
Installation
To get started install the @zoomus/chatbot NPM package.
$ npm install @zoomus/chatbot --save
const { oauth2, client, setting, log } = require('@zoomus/chatbot');
Log
const { oauth2, client, setting, log } = require('@zoomus/chatbot');
log(function(info) {
let { type, message } = info;
if (type === 'http') {
let { request, error, response } = message;
}
});
SendMessage Chatbot Message
const { oauth2, client, setting, log } = require('@zoomus/chatbot');
const oauth2Client = oauth2('{{ CLIENT_ID }}', '{{ CLIENT_SECRET }}');
let chatbot = client(
'{{ CLIENT_ID }}',
'{{ VERIFICATION_TOKEN }}',
'{{ BOT_JID }}'
).defaultAuth(oauth2Client.connect());
let zoomApp = chatbot.create();
await zoomApp.sendMessage({
to_jid: 'to_jid: can get from webhook response or GET /users/{userID}',
account_id:
'account_id: can get from webhook response or from JWT parsed access_token or GET /users/{userID}',
content: {
head: {
text: 'Hello World'
}
}
});
Get ZOOM IM channel message
const { oauth2, client, setting, log } = require('@zoomus/chatbot');
let chatbot = client('{{ CLIENT_ID }}', '{{ VERIFICATION_TOKEN }}', '{{ BOT_JID }}')
.defaultAuth(oauth2Client.connect());
app.post('/webhook',async function(req,res){
try{
let data = await chatbot.handle({ body, headers });
let { event, command?,type, payload } = data;
}
catch(e){
}
});
OAuth2 Credentials Flow(prepare for request zoom openapi)
const { oauth2, client, setting, log } = require('@zoomus/chatbot');
const oauth2Client = oauth2(
'{{ CLIENT_ID }}',
'{{ CLIENT_SECRET }}',
'{{ REDIRECT_URI }}'
);
let chatbot = client(
'{{ CLIENT_ID }}',
'{{ VERIFICATION_TOKEN }}',
'{{ BOT_JID }}'
).defaultAuth(oauth2Client.connect());
let middleZoomAuth = async (req, res, next) => {
let { code } = req.query;
try {
let connection = await oauth2Client.connectByCode(code);
let zoomApp = chatbot.create({ auth: connection });
res.locals.zoomApp = zoomApp;
next();
} catch (error) {
console.log(error);
res.send(error);
}
};
app.get('/authorize', middleZoomAuth, async (req, res) => {
res.send('Thanks for installing!');
let { zoomApp } = res.locals;
let tokens = zoomApp.auth.getTokens();
});
Request Zoom Open Api and Refreshing the Access Token(must do oauth2 first)
If the access_token is expired, this function will request a new access_token, so you can update the tokens in your zoomApp
instance and database.
let zoomApp = chatbot.create({ auth:connection });
zoomApp.auth.setTokens({
access_token: database.get('zoom_access_token'),
refresh_token: database.get('zoom_refresh_token'),
expires_date: database.get('zoom_access_token_expire_time')
});
zoomApp.auth.callbackRefreshTokens((tokens,error) => {
if(error){
}
else{
try {
await database.update({
id:'id',
access_token:tokens.access_token
refresh_token:tokens.refresh_token,
expires_date: moment().add( tokens.expires_in, 'seconds' ).format()
});
} catch (e) {
console.log(e);
}
}
});
await zoomApp.request({url:'/v2/users/me', method:'get'});
case sensitive in zoom IM message,default false
setting.caseSensitive(false);
Slash Commands and User Actions
Slash commands are what the user types in Zoom Chat to interact with your Chatbot.
User Actions are user interactions with the Editable Text, Form Field, Dropdown, or Buttons message types in Zoom Chat.
Need Support?
The first place to look for help is on our Developer Forum, where Zoom Marketplace Developers can ask questions for public answers.
If you can’t find the answer in the Developer Forum or your request requires sensitive information to be relayed, please email us at developersupport@zoom.us.