从电报频道获取消息 我是频道管理员
我想获取电报群的所有消息。我的机器人是该组的管理员之一。该机器人可以通过 TelegramApi getUpdates 获取消息。现在我面临一个问题。 当我从浏览器 https://api.telegram.org/bot{}/getUpdates?chat_id={}
使用时,我会回复所有消息,这没问题。但是,当我想通过 fetch 或 Axios 使用来自 nodeJs 的相同链接 getUpdates 时,我仅响应 []
。 如果我停止nodejs服务器,然后刷新此浏览器页面https://api.telegram.org/bot{}/getUpdates?chat_id={}
,启动服务器后,我会收到带有数据的响应。如何在不刷新浏览器页面和服务器nodejs的情况下获得所有数据的响应?
const https = require('https');
const fetch = require("node-fetch");
const fs = require('fs');
const express = require('express')
const sequelize = require('./db')
const Messages = require('./models')
const request = require('request');
const axios = require('axios');
const token = ''
const bot = new TelegramApi(token, {polling: true})
const app = express()
app.use(
express.urlencoded({
extended: true
})
)
app.use(express.json())
const saveData = async() =>{
//await sequelize.authenticate()
//await sequelize.sync()
const base_url = "https://api.telegram.org/{}/getUpdates?chat_id={}"
const get = await app.get(base_url)
await fetch('https://api.telegram.org/bot{}/getUpdates?chat_id={}')
.then(res => res.json())
.then(json => {
console.log("First user in the array:");
console.log(json.result);
})
}
saveData()
I want to get all messages from the telegram group. My bot is one of the admins of this group. The bot has access to get messages via TelegramApi getUpdates. Now I am faced with one problem.
When I use from browser https://api.telegram.org/bot{}/getUpdates?chat_id={}
, I respond to all messages, that's ok. However, when I want to use the same link getUpdates from nodeJs via fetch or Axios, I respond only []
.
If I stop nodejs server, then refresh this browser page https://api.telegram.org/bot{}/getUpdates?chat_id={}
, after starting the server, I get a response with data. How can I get a response with all data without refreshing the browser page and server nodejs?
const https = require('https');
const fetch = require("node-fetch");
const fs = require('fs');
const express = require('express')
const sequelize = require('./db')
const Messages = require('./models')
const request = require('request');
const axios = require('axios');
const token = ''
const bot = new TelegramApi(token, {polling: true})
const app = express()
app.use(
express.urlencoded({
extended: true
})
)
app.use(express.json())
const saveData = async() =>{
//await sequelize.authenticate()
//await sequelize.sync()
const base_url = "https://api.telegram.org/{}/getUpdates?chat_id={}"
const get = await app.get(base_url)
await fetch('https://api.telegram.org/bot{}/getUpdates?chat_id={}')
.then(res => res.json())
.then(json => {
console.log("First user in the array:");
console.log(json.result);
})
}
saveData()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论