Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Created August 20, 2022 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorDePaula/36a7a47ddb62cab69f70f68ea00995a7 to your computer and use it in GitHub Desktop.
Save IgorDePaula/36a7a47ddb62cab69f70f68ea00995a7 to your computer and use it in GitHub Desktop.
create telegram notification by channels and supergroups
const { Api,TelegramClient } = require("telegram");
const { StringSession, StoreSession} = require("telegram/sessions");
const input = require("input");
const { NewMessage } = require('telegram/events')
const util = require('util')
const apiId = 0;
const apiHash = "0";
const stringSession = new StoreSession("telegram_session");
(async () => {
console.log("Loading interactive example...");
const client = new TelegramClient(stringSession, apiId, apiHash, {
connectionRetries: 5,
});
await client.start({
phoneNumber: async () => "+9",
password: async () => await input.text("Please enter your password: "),
phoneCode: async () =>
await input.text("Please enter the code you received: "),
onError: (err) => console.log(err),
});
console.log("You should now be connected.");
client.session.save()
async function eventPrint(event) {
const message = event.message;
const chat = await message.getChat()
const user = await message.getSender()
console.log(`${chat.title}: (${user.firstName} ${user.lastName}) ${message.text}`)
}
const dialogs = await client.getDialogs();
dialogList = []
dialogs.forEach(
dialog=>{
if(dialog.isChannel || dialog.isGroup || dialog.isUser){
dialogList.push(dialog.id)
}
}
)
client.addEventHandler(eventPrint, new NewMessage({chats: dialogList}));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment