gramjs
gramjs copied to clipboard
New Message Event With Big Channels
Hello,
I'm having a problem with a feature that's supposed to show new messages. I'm trying to get messages from 7 different groups, and each group has more than 60,000 people in it. The issue is that sometimes the feature works and shows new messages, but other times it doesn't work at all.
I've tried a few things to fix it. I've put a special function right after the connection starts, and I've also set up another thing that checks every 2 seconds if there are new messages using that function. But no matter what I do, the problem still happens.
I could really use some help to figure out how to make this feature work all the time. If anyone has any ideas, I'd really appreciate it. Thank you!
Also, here is my code
const { TelegramClient } = require("telegram");
const { StoreSession } = require("telegram/sessions");
const dotenv = require("dotenv");
const input = require("input");
// Loads .env files
dotenv.config();
class TelegramClientAdapter {
client;
#session;
constructor() {
this.#session = new StoreSession("telegram-session");
this.client = new TelegramClient(
this.#session,
Number(process.env.TELEGRAM_API_ID),
process.env.TELEGRAM_API_HASH,
{ connectionRetries: 5 }
);
this.#bootstrap();
}
async #bootstrap() {
await this.client.start({
phoneNumber: async () => await input.text("Please enter your number: "),
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),
});
await this.client.connect();
await this.client.getMe();
await this.#keep();
}
async #keep() {
setInterval(async () => {
if (!this.client.connected) {
console.log("Não estava conectado");
await this.client.connect();
}
if (this.client.checkAuthorization()) {
await this.client.getMe();
console.log(
"Estado da conexão: ",
(await this.client.checkAuthorization())
? "CONECTADO"
: "DESCONECTADO"
);
}
}, 10000);
}
}
module.exports = { TelegramClientAdapter };
Does anyone can help here?
What method did you use to check if there are new messages? Telegram will sometimes skip these events for big channels if you don't show interest in them. You can try using getEntity or getMessages or GetChannelDifference on them from time to time to show telegram that you are interested in these channels.
What method did you use to check if there are new messages? Telegram will sometimes skip these events for big channels if you don't show interest in them. You can try using getEntity or getMessages or GetChannelDifference on them from time to time to show telegram that you are interested in these channels.
Thanks for the reply, as you can see in the photo, I used the New Message Event Handler. Also, how would you implement the logic that you described? Like, would you create a setInterval with getEntity or getMessages or GetChannelDifference on each channel to show interest on the channels?
@painor Hey, do you have any updates?
What method did you use to check if there are new messages? Telegram will sometimes skip these events for big channels if you don't show interest in them. You can try using getEntity or getMessages or GetChannelDifference on them from time to time to show telegram that you are interested in these channels.
Thanks for the reply, as you can see in the photo, I used the New Message Event Handler. Also, how would you implement the logic that you described? Like, would you create a setInterval with getEntity or getMessages or GetChannelDifference on each channel to show interest on the channels?
Yes you are exactly right. you would create an interval and calll one of these method (or all) on the channels that you want.
What method did you use to check if there are new messages? Telegram will sometimes skip these events for big channels if you don't show interest in them. You can try using getEntity or getMessages or GetChannelDifference on them from time to time to show telegram that you are interested in these channels.
Thanks for the reply, as you can see in the photo, I used the New Message Event Handler. Also, how would you implement the logic that you described? Like, would you create a setInterval with getEntity or getMessages or GetChannelDifference on each channel to show interest on the channels?
Yes you are exactly right. you would create an interval and calll one of these method (or all) on the channels that you want.
@painor Actually I've implemented a function called keepInterestOnChannels that periodically calls getChannelDifference
every 5 seconds, but it doesn't seem to be working as expected. Can you help me identify what I might have done wrong?
Hey, guys! Any updates? @painor
Can someone help me?
This is still not working can someone please help, I am not getting messages from a few channels even though I am listening to the NewMessage event.
This is still not working can someone please help, I am not getting messages from a few channels even though I am listening to the NewMessage event.
Same as me, still not working. I event put all the listeners for channels before using NewMessage Event, but no success
here is the channel information which i am listing
{ "fullChat": { "flags": 1073741857, "canViewParticipants": false, "canSetUsername": false, "canSetStickers": false, "hiddenPrehistory": false, "canSetLocation": false, "hasScheduled": false, "canViewStats": false, "blocked": false, "flags2": 0, "canDeleteChannel": false, "antispam": false, "participantsHidden": false, "translationsDisabled": false, "id": "1407365889", "about": "Get all Tricks, Offers & Price Error info.\n\nContact: @dealsspoint_bot\n\nFor Deals & Loot : \n\nTricks, Loot, Offers, Deals, Sale\n\nJoin : https://t.me/dealspoint", "participantsCount": 175293, "adminsCount": null, "kickedCount": null, "bannedCount": null, "onlineCount": null, "readInboxMaxId": 5624, "readOutboxMaxId": 0, "unreadCount": 0, "chatPhoto": { "flags": 0, "hasStickers": false, "id": "6125304864192968694", "accessHash": "3144352252819430474", "fileReference": { "type": "Buffer", "data": [ 0, 101, 32, 60, 20, 40, 21, 236, 132, 4, 20, 105, 25, 52, 146, 49, 27, 78, 54, 136, 62 ] }, "date": 1688231778, "sizes": [ { "type": "a", "w": 160, "h": 160, "size": 9617, "className": "PhotoSize" }, { "type": "b", "w": 320, "h": 320, "size": 28450, "className": "PhotoSize" }, { "type": "c", "w": 640, "h": 640, "size": 82039, "className": "PhotoSize" }, { "type": "i", "bytes": { "type": "Buffer", "data": [ 1, 40, 40, 209, 227, 140, 255, 0, 42, 145, 113, 232, 63, 42, 140, 99, 130, 113, 129, 235, 82, 46, 8, 200, 57, 247, 20, 0, 236, 15, 65, 70, 7, 160, 160, 30, 72, 239, 71, 90, 0, 82, 6, 58, 10, 41, 59, 81, 64, 21, 229, 77, 241, 109, 24, 207, 4, 103, 214, 171, 73, 152, 137, 45, 41, 78, 9, 194, 131, 129, 154, 188, 6, 84, 82, 21, 234, 49, 201, 239, 64, 211, 104, 169, 27, 20, 144, 57, 102, 61, 120, 0, 158, 57, 227, 222, 150, 51, 43, 70, 204, 89, 246, 18, 56, 98, 114, 61, 186, 85, 208, 131, 210, 157, 180, 127, 147, 74, 195, 230, 25, 18, 178, 199, 134, 247, 199, 57, 197, 21, 33, 233, 69, 50, 72, 192, 197, 1, 136, 45, 242, 55, 7, 243, 162, 138, 0, 60, 195, 255, 0, 60, 223, 242, 20, 187, 207, 252, 243, 127, 210, 138, 40, 1, 205, 208, 209, 69, 20, 1 ] }, "className": "PhotoStrippedSize" } ], "videoSizes": null, "dcId": 5, "className": "Photo" }, "notifySettings": { "flags": 3, "showPreviews": true, "silent": false, "muteUntil": null, "iosSound": null, "androidSound": null, "otherSound": null, "storiesMuted": null, "storiesHideSender": null, "storiesIosSound": null, "storiesAndroidSound": null, "storiesOtherSound": null, "className": "PeerNotifySettings" }, "exportedInvite": null, "botInfo": [], "migratedFromChatId": null, "migratedFromMaxId": null, "pinnedMsgId": 2060, "stickerset": null, "availableMinId": null, "folderId": null, "linkedChatId": null, "location": null, "slowmodeSeconds": null, "slowmodeNextSendDate": null, "statsDc": null, "pts": 14678, "call": null, "ttlPeriod": null, "pendingSuggestions": null, "groupcallDefaultJoinAs": null, "themeEmoticon": null, "requestsPending": null, "recentRequesters": null, "defaultSendAs": null, "availableReactions": { "reactions": [ { "emoticon": "❤", "className": "ReactionEmoji" }, { "emoticon": "🔥", "className": "ReactionEmoji" } ], "className": "ChatReactionsSome" }, "className": "ChannelFull" }, "chats": [ { "flags": 8288, "creator": false, "left": false, "broadcast": true, "verified": false, "megagroup": false, "restricted": false, "signatures": false, "min": false, "scam": false, "hasLink": false, "hasGeo": false, "slowmodeEnabled": false, "callActive": false, "callNotEmpty": false, "fake": false, "gigagroup": false, "noforwards": false, "joinToSend": false, "joinRequest": false, "forum": false, "flags2": 0, "id": "1407365889", "accessHash": "377086738214023781", "title": "Dealspoint 2.0", "username": "dealspointricks", "photo": { "flags": 2, "hasVideo": false, "photoId": "6125304864192968694", "strippedThumb": { "type": "Buffer", "data": [ 1, 8, 8, 212, 77, 249, 199, 203, 143, 214, 138, 40, 160, 15 ] }, "dcId": 5, "className": "ChatPhoto" }, "date": 1673162210, "restrictionReason": null, "adminRights": null, "bannedRights": null, "defaultBannedRights": null, "participantsCount": null, "usernames": null, "className": "Channel" } ], "users": [], "className": "messages.ChatFull" }
This is working fine using telethon library, but not in gram.js. seems something going wrong with the library. Since there is a lot of code I cannot move to python and also, this can take time. Can someone please help here? :(
This is working fine using telethon library, but not in gram.js. seems something going wrong with the library. Since there is a lot of code I cannot move to python and also, this can take time. Can someone please help here? :(
Oh, wow! Is that working on Telethon? Could you please share some code made with Telethon or even some URLs? I'm really stuck with this NewMessage Event thing
This is working fine using telethon library, but not in gram.js. seems something going wrong with the library. Since there is a lot of code I cannot move to python and also, this can take time. Can someone please help here? :(
Oh, wow! Is that working on Telethon? Could you please share some code made with Telethon or even some URLs? I'm really stuck with this NewMessage Event thing
Hey, I don't think you need the python code now, just uninstall the current telegram npm package and reinstall it, this issue will be fixed and this is fixed for me
Same problem, specific channels does not receive notifications, no matter the channel size or other settings... All the other chans receive newmessage events normally.... Using latest version