This is the code and the reponse im using.
CODE:
const express = require(‘express’)
const app = express()
const config = require(’./config’);
const request = require(‘request’);
app.get(’/’, (req, res) => {
//this will check if the code parameter is in the url, if not the most likely case is that this is the user’s inital visit to oauth and we need to redirect them (Step 1)
//if there is a code, it most likely means they were redirected here from zoom oauth screen
if (req.query.code) {
// Send bot message
let url = ‘https://zoom.us/oauth/token?grant_type=client_credentials&client_id=’ + config.clientID + ‘&client_secret=’ + config.clientSecret;
//STEP 3
//we need to exchange the code for a oauth token
request.post(url, function (error, response, body) {
//the response should be a JSON payload
body = JSON.parse(body);
console.log(body);
if (body.access_token) {
//STEP 4
//we can now use the access token to make API calls
/*
Send Bot Message /POST v2/im/chat/messages
*/
var options = { method: 'POST',
url: 'https://api.zoom.us/v2/im/chat/messages',
headers: {
Authorization: 'Bearer ' + body.access_token,
'Content-Type': 'application/json'
},
body: {
robot_jid: 'XXXXXX@xmpp.zoom.us', //located in marketplace, bot JID
to_jid: 'XXXXXXXXX', //group jid
account_id: 'XXXXXXXX', //user account ID
content: {
head: {
text: 'Ticket ZOOM-1000 Created'
},
body: [
{
type: 'message',
text: 'ZOOM-1000 New Bot Feature',
editable: true,
event_id: 'Title_Msg_Edit',
event: 'sendHttpMsg'
}
]
}
//message to be group
},
json: true
};
console.log(options);
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
} else {
//handle error, something went wrong
console.log('something went wrong')
}
}).auth(config.clientID, config.clientSecret);
return;
}
//STEP 2
//no code provided, so redirect the user to get the code
res.redirect('https://zoom.us/oauth/authorize?response_type=code&client_id=' + config.clientID + '&redirect_uri=' + config.redirectUrl);
});
app.listen(3000, () => console.log(‘Zoom chat bot sample app listening on port 3000!’))
Output:
C:…\zoom-bot-api-master>node sendBotMessage.js
Zoom chat bot sample app listening on port 3000!
{ access_token:
‘eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJodHRwczovL29hdXRoLnpvb20udXMiLCJ2ZXIiOiIyLjAiLCJuYmYiOjE1NDkzOTE3NzcsImNsaWVudElkIjoiS1dBOElkOXZRMWE3aGd6Q1ZDcE9TUSIsImlzcyI6InVybjp6b29tOmNvbm5lY3Q6Y2xpZW50aWQ6S1dBOElkOXZRMWE3aGd6Q1ZDcE9TUSIsImVudiI6W251bGxdLCJleHAiOjE1NDkzOTUzNzcsInRva2VuVHlwZSI6ImNsaWVudF90b2tlbiIsImlhdCI6MTU0OTM5MTc3NywidXNlcklkIjoiQjJxV2RzYVdRT3VrcE5CRVBDQTdndyIsImp0aSI6ImI3MjRmYzZkLTJhNGItNGFmMS04OGMwLWM4OGNlMDZmZGY0MiJ9.mYn4XxYEwlhywcqr1fdRnHz0PsQl6I61fm94bc5BE8mD5sauKdpRa10UzAU54DIMEJZFgc7beH0yYiEPCjp7dw’,
token_type: ‘bearer’,
expires_in: 3599,
scope:
‘imgroup:read:admin imgroup:write:admin imchat:write:admin imchat:bot imchat:read:admin’ }
{ method: ‘POST’,
url: ‘https://api.zoom.us/v2/im/chat/messages’,
headers:
{ Authorization:
‘Bearer eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJodHRwczovL29hdXRoLnpvb20udXMiLCJ2ZXIiOiIyLjAiLCJuYmYiOjE1NDkzOTE3NzcsImNsaWVudElkIjoiS1dBOElkOXZRMWE3aGd6Q1ZDcE9TUSIsImlzcyI6InVybjp6b29tOmNvbm5lY3Q6Y2xpZW50aWQ6S1dBOElkOXZRMWE3aGd6Q1ZDcE9TUSIsImVudiI6W251bGxdLCJleHAiOjE1NDkzOTUzNzcsInRva2VuVHlwZSI6ImNsaWVudF90b2tlbiIsImlhdCI6MTU0OTM5MTc3NywidXNlcklkIjoiQjJxV2RzYVdRT3VrcE5CRVBDQTdndyIsImp0aSI6ImI3MjRmYzZkLTJhNGItNGFmMS04OGMwLWM4OGNlMDZmZGY0MiJ9.mYn4XxYEwlhywcqr1fdRnHz0PsQl6I61fm94bc5BE8mD5sauKdpRa10UzAU54DIMEJZFgc7beH0yYiEPCjp7dw’,
‘Content-Type’: ‘application/json’ },
body:
{ robot_jid: ‘XXXXXX@xmpp.zoom.us’,
to_jid: ‘XXXXX’,
account_id: 'XXXXX,
content: { head: [Object], body: [Array] } },
json: true }
{ message: ‘String index out of range: -1’, code: 500 }