Jose Sabater
Jose Sabater

Reputation: 103

Read Telegram channel from Node JS

I am creating an application in Node Js that needs to read a message from a Telegram channel, does anyone know how to do it?

I found a lot of information about creating a Telegram Bot, but that does not help. To read information from a public Telegram channel, no bot should be needed.

Thanks and best regards.

Upvotes: 3

Views: 4824

Answers (2)

UntoldHacker-Dev
UntoldHacker-Dev

Reputation: 16

You can do that by various different means (packages)

  1. Telegraf: read the channel's message using the channel_post event listener, example snippet:
const { Telegraf } = require('telegraf');
const bot = new Telegraf('YOUR_BOT_TOKEN');

// The bot listens to all channel messages
bot.on('channel_post', (ctx) => {
    const message = ctx.channelPost.text; // You can access message details here
    console.log(`New message in channel: ${message}`);
    // You can do further processing with the message
});

bot.launch();
  1. Using gramjs events listener: https://painor.gitbook.io/gramjs/getting-started/updates-events, (example):
...
async function eventPrint(event) {
    // const message = event.message;
    // ...
}
client.addEventHandler(eventPrint, new NewMessage({}));
  1. or using grammyjs: https://grammy.dev/guide/filter-queries#filtering-by-message-sender-type, method:
// Channel posts sent by 'ctx.senderChat'
bot.on("channel_post");

Upvotes: 0

Mehdi Mohammadpour
Mehdi Mohammadpour

Reputation: 1130

You can use telegram mtproto api. some good efrence is here :

https://openbase.io/js/@mtproto/core/documentation
https://core.telegram.org/methods

Upvotes: 1

Related Questions