Node.js Ignore fetching replies in a telegram channel

62 views Asked by At

Im trying to write a code that fetches the latest messages of a specific private telegram channel.

I want to to ignore messages replies in the channel, I couldnt find anything to help me with that.

this is my code

const { api } = require('./mtproto');

function startListener() {
    console.log('[+] starting listener');
    const newChannelMessages = [];

    api.mtproto.updates.on('updates', ({ updates }) => {
        const filteredMessages = updates
            .filter((update) => 
                update._ === 'updateNewChannelMessage' && 
                update.message.peer_id.channel_id == '12345678' && 
                update.message.message.startsWith('$') &&
                !update.message.message.split(' ').some(word => ['T1', 'T2', 'T3', 'T4', 'T5', 'T6'].includes(word))
            .map(({ message }) => message);
        
        newChannelMessages.push(...filteredMessages);

        for (const message of filteredMessages) {
            console.log(message.message);
        }
    });

    return newChannelMessages;
}

module.exports = {

    startListener,
    
  };

Appreciate your support

0

There are 0 answers