Chat Bot Message Index Out Of Range

After installing the Chatbot and running tests we encountered an error while trying to send a message. We cant figure out how we should send the message through node, we’ve tried with your rich text options and simple strings.

Also, we are now testing with a local host url redirect. What should type of url/server should we get for it to work on a production environment.

Hi @jorge.canavati,

Can you share with us the error that you are receiving and perhaps the full payload? Which message content are you using? To make sure your production environment, can you confirm if your publishable url is working?

Here is an example of the content that should work.
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”
}
]
}

Also one more question, the bot seems to be installed on many of the users without any request to do so, it just installed automatically in their accounts and
sent a “Hello” message. Is there any way in which I can disable this property so it can get just installed in my account for development and testing?

Best Regards,

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 }

Error still persist, any help will be appreciated.

Thanks in advance

Hi @jorge.canavati,

Sorry for the delay, just wanted to let you know that we’re still troubleshooting your issue and will get back to you as soon as we find a workaround for you.

Thanks

Hi @jorge.canavati,

A workaround would be to create the bot on another test account of testing/developing purposes.

I think you need to include double quotes “” for the property and value for the content object simliar to sample I gave earlier in the thread.

Let us know if that works.

Did you meant something like this?

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: ‘v1tdfvixv3tcqmtweqnze66a@xmpp.zoom.us’, //located in marketplace, bot JID
to_jid: ‘fj1lWHcPSfi2bppKuoB-Ig’, //group jid
account_id: ‘fcN-RcaRRi-5PTFKtkjsLA’, //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);
});

I Did tried it before and it still didnt work, same response from the server was achieved.

Hi @jorge.canavati,

Can you try to do this in postman or a curl request? I wanted to make sure it’s not the code base that is somehow causing the error.

Thanks

Hi @michael_p.zoom, ive tried with the curl request example you guys have on the guide:

curl -X POST \
  https://api.zoom.us/v2/im/chat/messages \
  -H 'Authorization: Bearer xxxxxxxxxxxxx' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
	"robot_jid":"xxxxx@xmpp.zoom.us",
	"to_jid":"xxxxxx",
	"account_id": "xxxxxxxx",
	"content": {
    "head": {
      "text": "Ticket ZOOM-1000 Created"
    },
    "body": [
      {
        "type": "message",
        "text": "ZOOM-1000 New Bot Feature"
      }
    ]
  }
}'

I left it as it is but with our data instead of the “xxxxx”, i still get the same response:

{“message”:“String index out of range: -1”,“code”:500}

Hi @jorge.canavati,

Let me expedite this issue to our Engineers, to see why the error is happening. I’ll follow back up with you as soon as possible.

Thanks

Ive tried by even testing in your marketplace api description. Still wont work.

Hi @jorge.canavati,

I recently tested the below curl request using the same content payload and it worked for me.

curl -X POST
https://api.zoom.us/v2/im/chat/messages
-H ‘Authorization: Bearer XXXX’
-H ‘Cache-Control: no-cache’
-H ‘Content-Type: application/json’
-H ‘Postman-Token: XXXXX’
-d '{
“robot_jid”:"1xbim5frtyim5cgq@xmpp.zoom.us",
“to_jid”:"1eb8f3e7a5c52@conference.xmpp.zoom.us",
“account_id”: “qsmdmkg”,
“content”: {
“head”: {
“text”: “Ticket ZOOM-1000 Created”
},
“body”: [
{
“type”: “message”,
“text”: “ZOOM-1000 New Bot Feature”
}
]
}
}

Can you send us an email at developersupport@zoom.us with your account ID, robot_jid, and to_jid from there we’ll do some more testing by end of the day to see why this error is occurring on your end.

Thanks