I've managed to retrieve images from Google Drive using Google drive API. This is the file I've managed to retrieved.
This is the code:
drive.files.get({fileId: '1z7GeGoxcbtUyGX4vBhR0-KKM-QnwrQhe', fields: "*"},(err, res) => {
console.log(res.data);
});
I want my telegram Bot (using telegraf) to send this image to whoever request it. Like this:
This is the full code:
const { Telegraf } = require('telegraf');
require('dotenv').config();
const { google } = require('googleapis');
const credentials = require('./credentials.json');
const scopes = [
'https://www.googleapis.com/auth/drive'
];
const auth = new google.auth.JWT(
credentials.client_email, null,
credentials.private_key, scopes
);
const drive = google.drive({ version: "v3", auth });
drive.files.get({fileId: '1z7GeGoxcbtUyGX4vBhR0-KKM-QnwrQhe', fields: "*"},(err, res) => {
console.log(res.data);
// Send this image to telegram bot
});
const {
PORT,
BOT_TOKEN: TOKEN,
WEBHOOK_DOMAIN: webhookDomain,
} = process.env;
const bot = new Telegraf(TOKEN);
bot.start((ctx) => ctx.reply('Welcome'));
bot.command('photos', async (ctx) => {
return await ctx.replyWithPhoto({
url: 'https://picsum.photos/200/300/?random',
filename: 'kitten.jpg'
})
});
bot.command('hipster', Telegraf.reply('λ'));
bot.launch();
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
The problem is that I cannot figure out how to send the image. I've tried the replyWithPhoto API but can't seem to make it work. I've sent the webContentLink and webViewLink retrieved from Google Drive API but the image isn't showing on Telegram Bot. I've seen this post:
Telegram Bot to Download files from Google Drive
But can't really connect the dots.