Vic*_*ron 15 client node.js telegram
我想在nodejs(一个例子)中有一个非常简单的客户端,可以从电报中的联系人那里接收消息.我只是在网上搜索,但我只得到机器人样本.我希望接收群组消息,我无权访问我的机器人的权限,所以我想知道我是否可以接收我自己的消息,没有机器人作为中介.
gok*_*and 32
嗯......其他答案给出了来自未维护库的示例.因此,您不应该依赖这些库.
您应该使用最新的Telegram客户端库,即telegram-mtproto
api_id
和api_hash
来自:npm install telegram-mtproto@beta --save
api_id
和api_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();
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
如果您想在官方应用程序之一(网站、移动或桌面应用程序等)之外与 Telegram 数据进行交互,您将必须创建一个应用程序,因此您将需要生成 API 密钥和/或使用任何现有的适合您要求的应用程序(在您的情况下是机器人)。
让我强调一下,使用 API 系统,如果您之前没有授予或添加访问权限,那么似乎很难访问受限制的内容……没有人希望任何人都可以访问任何数据……
问候
归档时间: |
|
查看次数: |
7943 次 |
最近记录: |