查尔斯的回答为我指明了正确的方向。对于那些对 Node.js 版本感兴趣的人,我设法通过使用 telegram-link 模块并将 connectionType 设置为 TCP 来使其工作:
var telegramLink = require('telegram.link')();
// set the environment
var app = {
// NOTE: if you FORK the project you MUST use your APP ID.
// Otherwise YOUR APPLICATION WILL BE BLOCKED BY TELEGRAM
// You can obtain your own APP ID for your application here: https://my.telegram.org
id: 12345,
hash: 'somehashcode',
version: require('../package.json').version,
lang: 'en',
deviceModel: os.type().replace('Darwin', 'OS_X'),
systemVersion: os.platform() + '/' + os.release(),
connectionType: 'TCP'
};
//var primaryDC = telegramLink.TEST_PRIMARY_DC;
var primaryDC = telegramLink.PROD_PRIMARY_DC;
...
telegramLink.createClient(app, dataCenter, function() {
...
简单点就是,改成TCP就能达到你想要的效果,你会在registerOnUpdates中收到推送给你的消息:
clientProxy.getClient().account.updateStatus(false).then(function() {
clientProxy.getClient().registerOnUpdates(function(update) {
console.log('update', update.toPrintable());
clientProxy.getClient().messages.receivedMessages(update.id, function(err) { console.log(err); });
});
...
注意 receiveMessages - 如果您不调用此消息,那么 Telegram 将不会向您发送任何新的更新。如果您的 telegram-link 中未定义 returnedMessages,请将以下代码添加到 lib/api/messages.js:
// ***
// messages.**receivedMessages(max_id, [callback])**
// Return a Promise to Confirms receipt of messages by a client, cancels PUSH-notification sending.
// [Click here for more details](https://core.telegram.org/method/messages.receivedMessages)
Messages.prototype.receivedMessages = function(max_id, callback) {
return utility.callService(api.service.messages.receivedMessages, this.client, this.client._channel, callback, arguments);
};