Skip to main content

I have a bot that has been graduated and is able to make calls to the endpoint to get posts:

https://platform.ringcentral.com/team-messaging/v1/chats/XXX/posts/PPP

I am also able to receive information about the same posts via webhook. In both cases, the bot is using the persistent token retrieved by the bot using the code we receive when added to the environment.

However, I am not able to retrieve the contents of the post attachments using that same token. The content URI comes in this format:

https://dl.mvp.ringcentral.com/file/NNN

I have tried using a browser, Postman, and code (C#). I have tried providing the token in the Authorization header ("Bearer TTT") as well as on the query string as shown in another example, but all responses are always 404 with this JSON:

{ "errors":
[
{
"errorCode": "CMN-102",
"message": "Resource for parameter [fileId] is not found.",
"parameterName": "fileId" } ]}


Can the bot persistent token be used to retrieve attachment data? If not, how can I obtain the token that will work to download attachment data without user interaction?

Thanks!

First of all, your bot access token has the right to read posts and attachments under a team/chat/conversation the bot is a member of.

In your case, I don't see the code nor the environment so it's hard for me to tell what could be wrong. This is how I could successfully download a binary file attachment in my bot using Node JS.

const url = require('url')
try{
var attachmentUri = "https://dl.mvp.ringcentral.com/file/NNN"
var accessToken = "Valid-AccessToken"
download(attachmentUri, accessToken, (err, content) => {
console.log("Done")
})
}catch(e){
console.log(e)
}
var https = require('https');
const download = function(attachmentUri, token, cb) {
var file = fs.createWriteStream("testing.png");
var u = url.parse(attachmentUri);
var options = {
host: u.host,
path: u.pathname,
method: "GET",
headers: {
Authorization: `Bearer ${token}`
}
}

const req = https.request(options, res => {
var chunks = [];
res.setEncoding('binary');
res.on('data', (chunk) => {
chunks += chunk;
}).on('end', () => {
file.write(chunks, 'binary');
file.on('finish', () => {
console.log('File Saved !');
});
res.pipe(file);
})
})
req.on('error', error => {
console.error(error)
})
req.end()
}

If you believe that your code is correct and you still receive the error, I recommend to submit a dev support ticket so you can provide more details for the investigation.


Some code for your reference: https://github.com/tylerlong/rc-team-messaging-attachment-download/blob/main/src/demo.ts

It works for me.


Reply