gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

How to listen to new messages on a specific channel?

Open devcarlosalberto opened this issue 1 year ago • 1 comments

I looked through all the documentation and didn't find anything like that, I was confused. I just wanted to observe whenever a new message arrived on a Telegram channel so that I could activate automations based on the messages that arrived.

devcarlosalberto avatar Apr 15 '24 01:04 devcarlosalberto

do somthing like this :

import { NewMessage } from 'telegram/events'
const callbackFunction= async (event:any) => {
    eventHandler(event); //example function
} 
Client.addEventHandler(callbackFunction, new NewMessage({ incoming: true, channels: ['@something' , '@somthing2']  }) )

//if you want to remove the event for some reason 
Client.removeEventHandler(callbackFunction)

AminAbbar avatar Apr 16 '24 02:04 AminAbbar