如何在没有BOT的node.js中接收我自己的电报信息 [英] How to receive my own telegram messages in node.js without bot
本文介绍了如何在没有BOT的node.js中接收我自己的电报信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在NodeJS中有一个非常简单的客户端(示例),它可以接收来自我的联系人的电报消息。我刚刚在互联网上搜索了一下,但是我只得到了机器人的样本。我希望在我无权向我的机器人授予权限的位置接收群消息,所以我想知道是否可以在没有机器人作为中介的情况下接收我自己的消息。
推荐答案
好.其他答案给出了未维护的库中的示例。因此,您不应依赖这些库。
您应该使用telegram-mtproto
的最新电报客户端库1.获取您的api_id
和api_hash
来源:
2.安装所需的客户端库:
npm install telegram-mtproto@beta --save
3.使用从Telegram Apps和phone number
获得的api_id
和api_hash
初始化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;
}
此外,请查看原始repo中的示例:
这篇关于如何在没有BOT的node.js中接收我自己的电报信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文