![](/img/trans.png)
[英]Is there a way to receive telegram messages in node.js without bot?
[英]How to receive my own telegram messages in node.js without bot
我想在nodejs(一個例子)中有一個非常簡單的客戶端,可以從電報中的聯系人那里接收消息。 我只是在網上搜索,但我只得到機器人樣本。 我希望接收群組消息,我無權訪問我的機器人的權限,所以我想知道我是否可以接收我自己的消息,沒有機器人作為中介。
嗯......其他答案給出了來自未維護庫的示例。 因此,您不應該依賴這些庫。
您應該使用最新的Telegram客戶端庫,即telegram-mtproto
api_id
和api_hash
: npm install telegram-mtproto@beta --save
api_id
和api_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();
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.