iliiliiliili / easy-telegram-mtproto

Telegram Client API wrapper for telegram-mtproto
MIT License
10 stars 0 forks source link

How to subscribe on update on telegram events #3

Open NickCashFlow opened 4 years ago

NickCashFlow commented 4 years ago

I try to subscribe on telegram events

`const EventEmitter = require('events'); let evEmmiter = new EventEmitter();

evEmmiter.on('updateShortChatMessage', (newOrderBook) => {

      console.log('updateShortChatMessage ', newOrderBook);

    });

`

But I don't get any response when I get/send a new message. Please, help me with this, probably, I do something wrong and your lib has some methods for subscribing on telegram events.

iliiliiliili commented 4 years ago

Hi, In your code you create an event emitter that is not connected to the TelegramClient in any way. You can use it, but you have to manually emit events when it's needed.

Currently, it does not have built in event emitter, but you can call actions like chatHistory and if it changed, emit event. Anyway, you can use all telegram-mtproto methods by using call function. From README.md:

NickCashFlow commented 4 years ago

Unfortunately, method chatHistory don't give enough effectively, and I can't get chatHistory often then once every 1000ms. If I try to make the request often than once every 1000ms I get Flood error! It means that mtproto server bans me on 1 second. And next requests increase time of bans. In php-lib MadelineProto is an EventHandler that through socks gets updates. Maybe, you will implement something like that in easy-telegram-mtproto?

iliiliiliili commented 4 years ago

I understand. But, unfortunately, I can't guarantee you that I will be able to find time to add this in the near future. If you are wiling to fix it, I would be glad to check a pull-request. It's possible that telegram-mtproto (which my library wraps around) has something for it. If yes, it should be possible to be done with inner telegramMtproto object.