【问题标题】:How to receive my own telegram messages in node.js without bot如何在没有机器人的情况下在 node.js 中接收我自己的电报消息
【发布时间】:2018-04-04 12:39:04
【问题描述】:

我想在 nodejs 中有一个非常简单的客户端(一个示例),它可以接收来自我的电报联系人的消息。我只是在互联网上搜索,但我只得到机器人样本。我想在我无权授予我的机器人特权的情况下接收群组消息,因此我想知道我是否可以在没有机器人作为中介的情况下接收自己的消息。

【问题讨论】:

    标签: node.js client telegram


    【解决方案1】:

    如果您想在官方应用程序之一(网站、移动或桌面应用程序等...)之外与 Telegram 数据进行交互您将必须创建一个应用程序,因此您 will be required to generate API key 和/或使用任何现有的符合您要求的应用程序(在您的情况下为机器人)。

    让我强调一下,使用 API 系统似乎很难访问受限制的内容,如果您之前没有授予或添加访问权限...没有人希望任何人都可以访问任何数据...

    问候

    【讨论】:

      【解决方案2】:

      您可以使用以下库。

      它们提供抽象来构建应用程序以与电报交互。有关如何使用 telegram-js 的示例,您可以使用https://github.com/dot-build/telegram-js/blob/master/sample.js

      (感谢@gokcand 的反馈)

      【讨论】:

        【解决方案3】:

        嗯... 其他答案给出了 unmaintained 库中的示例。因此,您不应依赖这些库。

        请参阅:telegram.link is dead


        您应该使用最新的 Telegram 客户端库 telegram-mtproto

        1. 从以下地址获取您的api_idapi_hash

        Telegram Apps

        2. 安装所需的客户端库:

        npm install telegram-mtproto@beta --save

        3. 初始化您的 node.js 应用程序,使用您从 Telegram Apps 获得的 api_idapi_hash 以及您的 phone number

        import MTProto from 'telegram-mtproto'
        
        const phone = {
          num : '+90555555555', // basically it is your phone number
          code: '22222' // your 2FA code
        }
        
        const api = {
          layer          : 57,
          initConnection : 0x69796de9,
          api_id         : 111111
        }
        
        const server = {
          dev: true //We will connect to the test server.
        }           //Any empty configurations fields can just not be specified
        
        const client = MTProto({ server, api })
        
        async function connect(){
          const { phone_code_hash } = await client('auth.sendCode', {
            phone_number  : phone.num,
            current_number: false,
            api_id        : 111111, // obtain your api_id from telegram
            api_hash      : 'fb050b8fjernf323FDFWS2332' // obtain api_hash from telegram
          })
          const { user } = await client('auth.signIn', {
            phone_number   : phone.num,
            phone_code_hash: phone_code_hash,
            phone_code     : phone.code
          })
              console.log('signed as ', user);
            }
        
            connect();
        

        4. 接收消息(有趣的部分!??‍?)

        const telegram = require('./init') // take a look at the init.js from the examples repo
        
        const getChat = async () => {
          const dialogs = await telegram('messages.getDialogs', {
            limit: 50,
          })
          const { chats } = dialogs;
          const selectedChat = await selectChat(chats);
        
          return selectedChat;
        }
        

        此外,看看原始 repo 中的示例:

        【讨论】:

        猜你喜欢
        • 2021-10-12
        • 1970-01-01
        • 1970-01-01
        • 2017-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-08
        相关资源
        最近更新 更多