I’m developing website on Vue.js, there is a news section, I want to grab this news from my Telegram channel, I created and added Telegram bot to my channel with admin permission. Also I have server which is getting these messages from Telegram API by getUpdates method:
<code>const express = require('express');
const axios = require('axios');
const app = express();
const BOT_TOKEN = '7227272857:AAEUqcfcas7Zl78n1Id3lG80kuz-tQ3l32U';
const CHANNEL_ID = -1002224165548;
app.get('/news', async (req, res) => {
try {
const response = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getUpdates`);
const data = response.data;
const messages = await Promise.all(data.result
.filter(update => update.channel_post && update.channel_post.chat.id === CHANNEL_ID)
.map(async update => {
const post = update.channel_post;
let photoUrl = null;
if (post.photo) {
const fileId = post.photo[post.photo.length - 1].file_id; // Используем последнюю фотографию (самую большую)
const fileResponse = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getFile?file_id=${fileId}`);
const filePath = fileResponse.data.result.file_path;
photoUrl = `https://api.telegram.org/file/bot${BOT_TOKEN}/${filePath}`;
}
return {
text: post.caption ?? post.text,
date: new Date(post.date * 1000),
photo: photoUrl,
};
})
);
res.json(messages);
} catch (error) {
console.error(error);
res.status(500).send('Error fetching news');
}
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
</code>
<code>const express = require('express');
const axios = require('axios');
const app = express();
const BOT_TOKEN = '7227272857:AAEUqcfcas7Zl78n1Id3lG80kuz-tQ3l32U';
const CHANNEL_ID = -1002224165548;
app.get('/news', async (req, res) => {
try {
const response = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getUpdates`);
const data = response.data;
const messages = await Promise.all(data.result
.filter(update => update.channel_post && update.channel_post.chat.id === CHANNEL_ID)
.map(async update => {
const post = update.channel_post;
let photoUrl = null;
if (post.photo) {
const fileId = post.photo[post.photo.length - 1].file_id; // Используем последнюю фотографию (самую большую)
const fileResponse = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getFile?file_id=${fileId}`);
const filePath = fileResponse.data.result.file_path;
photoUrl = `https://api.telegram.org/file/bot${BOT_TOKEN}/${filePath}`;
}
return {
text: post.caption ?? post.text,
date: new Date(post.date * 1000),
photo: photoUrl,
};
})
);
res.json(messages);
} catch (error) {
console.error(error);
res.status(500).send('Error fetching news');
}
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
</code>
const express = require('express');
const axios = require('axios');
const app = express();
const BOT_TOKEN = '7227272857:AAEUqcfcas7Zl78n1Id3lG80kuz-tQ3l32U';
const CHANNEL_ID = -1002224165548;
app.get('/news', async (req, res) => {
try {
const response = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getUpdates`);
const data = response.data;
const messages = await Promise.all(data.result
.filter(update => update.channel_post && update.channel_post.chat.id === CHANNEL_ID)
.map(async update => {
const post = update.channel_post;
let photoUrl = null;
if (post.photo) {
const fileId = post.photo[post.photo.length - 1].file_id; // Используем последнюю фотографию (самую большую)
const fileResponse = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getFile?file_id=${fileId}`);
const filePath = fileResponse.data.result.file_path;
photoUrl = `https://api.telegram.org/file/bot${BOT_TOKEN}/${filePath}`;
}
return {
text: post.caption ?? post.text,
date: new Date(post.date * 1000),
photo: photoUrl,
};
})
);
res.json(messages);
} catch (error) {
console.error(error);
res.status(500).send('Error fetching news');
}
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
The problem is when I delete the message API still returns me it. Also I noticed that only after ~2 days it returned me array without deleted messages. I would like to fix this, so it will not give me deleted messages.