Created
August 20, 2022 20:38
-
-
Save IgorDePaula/36a7a47ddb62cab69f70f68ea00995a7 to your computer and use it in GitHub Desktop.
create telegram notification by channels and supergroups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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