繁体   English   中英

如何在没有bot的情况下在node.js中接收我自己的电报消息

[英]How to receive my own telegram messages in node.js without bot

我想在nodejs(一个例子)中有一个非常简单的客户端,可以从电报中的联系人那里接收消息。 我只是在网上搜索,但我只得到机器人样本。 我希望接收群组消息,我无权访问我的机器人的权限,所以我想知道我是否可以接收我自己的消息,没有机器人作为中介。

嗯......其他答案给出了来自未维护库的示例。 因此,您不应该依赖这些库。

见: telegram.link已经死了


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

1. 从以下位置获取api_idapi_hash

电报应用程序

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

npm install telegram-mtproto@beta --save

3. 使用来自Telegram Apps的 api_idapi_hash以及您的phone number 初始化您的node.js应用程序

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;
}

此外,看一下原始回购中的例子:

如果您想在官方应用程序(网站,移动或桌面应用程序等)之外与Telegram数据交互, 您将需要创建一个应用程序,因此您将需要生成API密钥和/或使用任何已有的符合您要求的应用程序(在您的情况下为机器人)。

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

问候

您可以使用以下库。

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

(谢谢@gokcand的反馈)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM