You need to send the webViewLink to discord, where you change the usp query parameter in the URL from drivesdk to sharing.
For reference, this is the discord incoming webhook API: https://discord.com/developers/docs/resources/webhook#execute-webhook
the google drive rest API:
https://developers.google.com/drive/api/v3/reference/files#resource
Check out a simple implementation of it here:
const { Integration } = require('@fusebit-int/framework');
const superagent = require('superagent')
const integration = new Integration();
const router = integration.router;
const googleConnector = 'googleConnector';
const discordConnector = 'discordConnector';
router.post('/api/tenant/:tenantId/test', async (ctx) => {
try {
const googleClient = await integration.tenant.getSdkByTenant(ctx, googleConnector, ctx.params.tenantId);
const files = await googleClient
.drive({
version: 'v3',
})
.files.list({fields: 'files(id, mimeType, webViewLink)'});
const file = files.data.files[0]
file.webViewLink = file.webViewLink.replace('drivesdk', 'sharing')
await discordSendMessage(ctx, file.webViewLink)
ctx.body = {
message: `Message with embed sent to discord.`,
};
} catch (e) {console.log(e)}
});
async function discordSendMessage(ctx, content) {
const discordClient = await integration.tenant.getSdkByTenant(
ctx,
discordConnector,
ctx.params.tenantId
);
const webhook = discordClient?.fusebit?.credentials?.webhook;
if (!webhook) {
ctx.throw(404, `The installation does not have a default webhook channel.`);
}
try {
return await superagent.post(webhook.url).send({ content })} catch (e) {console.log(e)}
}
module.exports = integration;