我尝试使用telegram.link lib(不是bot API,而是本机CLI)读取NodeJS中的Telegram消息。
设置我的客户端后,我收到此错误:
Error: Client is not yet ready!
at Client.isReady (C:\Users\Guilh\WebstormProjects\telegram-link-test\node_modules\telegram.link\lib\telegram.link.js:353:28)
at Object.callService (C:\Users\Guilh\WebstormProjects\telegram-link-test\node_modules\telegram.link\lib\utility.js:22:17)
at Account.updateStatus (C:\Users\Guilh\WebstormProjects\telegram-link-test\node_modules\telegram.link\lib\api\account.js:45:20)
at Timeout.setTimeout (C:\Users\Guilh\WebstormProjects\telegram-link-test\app\main.js:30:24)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
我的代码如下:
var t = require('telegram.link');
var os = require('os');
var telegramLink = require('telegram.link')();
// set the environment
var app = {
id: 000000,
hash: 'A HASH KEY',
version: require('../package.json').version,
lang: 'en',
deviceModel: os.type(),
systemVersion: os.platform() + '/' + os.release(),
connectionType: 'TCP'
};
var primaryDC = t.TEST_PRIMARY_DC;
//var primaryDC = t.PROD_PRIMARY_DC;
var client = telegramLink.createClient(app, primaryDC, ()=> {
console.log('Created');
client.account.updateStatus(false).then(()=> {
client.registerOnUpdates((update)=> {
console.log('Update received');
client.messages.receivedMessages(update.id, (err)=> {
console.log(err);
});
});
});
});
即使放入setTimeout,我也会收到此错误。 我认为我错过了认证的一步。 谢谢你的帮助。