I’m having a problem listening for new messages. After a couple of minutes, the addEventHandler
method stops working. What could be happening?
this.client = this.client = new TelegramClient(this.stringSession, TELEGRAM_API_ID, TELEGRAM_API_HASH, {
connectionRetries: 5
})
this.client.addEventHandler(this.eventHandler.bind(this), new NewMessage({ chats: CHANNELS_TO_LISTEN }))
private async eventHandler(event: NewMessageEvent) {
try {
if (!event) {
logger.error(`The msg received is null or undefined`)
}
logger.trace(`New msg received: ${event.message.message}`)
this.emit('call', event.message)
} catch (error) {
logger.error(`Error handling event: ${error}`)
}
}
I don’t think it’s a connection problem since it always stays connected without any problems.
New contributor
SanzEneko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.