从电报频道获取消息 我是频道管理员

发布于 2025-01-11 08:49:41 字数 1312 浏览 0 评论 0原文

我想获取电报群的所有消息。我的机器人是该组的管理员之一。该机器人可以通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文