Open bigbigsir opened 1 year ago
I also encounter the same problem
Hello, I also have this problem
What happened? It didn't change anything, and all of a sudden it didn't work
@alik0211
I checked the telegram api docs for update or something else, but I saw nothing related to getAllChats...
This error is true for me too
same for me, has anyone found any solution?
Has anyone found any solution?
@alik0211
It seems that this method has been removed from telegram API, and getDialogs must be used instead.
It seems that this method has been removed from telegram API, and getDialogs must be used instead.
however the getDialogs method gets only recent conversations and not all conversations.
Oh, didn't noticed that, I just saw this answer... It will be a problem for me too, more digging is necessary :(
Oh, didn't noticed that, I just saw this answer... It will be a problem for me too, more digging is necessary :(
I don't understand the Telegram have removed this method without any notice, causing a breaking change.
@0xARK any solution?
No, I didn't have time to look into it
See https://github.com/gram-js/gramjs/issues/522#issuecomment-1538045572 @alexsanderluisdev
@0xARK this don't work for me. Causes a infinity loop.
it's working on my side, check the adapted method for mtproto :
const getAllChats = async () => {
const LIMIT = 100;
const offsetId = 0;
const offsetPeer = {
_: 'inputPeerEmpty'
};
let resultCount = LIMIT;
let offsetDate = 0;
let chats = [];
while (resultCount >= LIMIT) {
const result = await mtproto.call('messages.getDialogs', {
offset_id: offsetId,
offset_peer: offsetPeer,
offset_date: offsetDate,
limit: LIMIT
}).catch(e => {
if (e.error_message.includes('FLOOD_WAIT')) {
log.warn("Telegram", `API rate limit reached, please wait ${e.error_message.replace('FLOOD_WAIT_', '')} seconds`);
} else log.error("Telegram", e.message);
})
resultCount = result.dialogs.length;
if (result.chats && result.chats.length > 0) {
chats = [...chats, ...result.chats];
}
if (result.messages.length > 0) {
offsetDate = result.messages[result.messages.length - 1].date;
} else {
break;
}
}
return chats;
}
don't work, this lists even fewer chats, and chats that have no interaction are still not listed
I used messages.getAllChats to get all chats and then filter chats to get only chats that we need.
To get chats according to a pre-known list I used two method. First try to find by @name. If @name do not exists then find by search and filter by chat.title.
static async getChatsByUsername(username) {
let resolvedPeer = { chats: [] };
try {
resolvedPeer = await api.call('contacts.resolveUsername', {
username,
});
} catch (error) {
console.warn('Error to get chat', username);
}
const chat = resolvedPeer.chats.find((chat) => (chat.id === resolvedPeer.peer.channel_id));
return chat;
}
static async searchChatsByTitle(title) {
const searchResult = await api.call('contacts.search', {
q: title,
});
return searchResult.chats.find((chat) => (chat.title === title));
}
Oh, didn't noticed that, I just saw this answer... It will be a problem for me too, more digging is necessary :(
I don't understand the Telegram have removed this method without any notice, causing a breaking change.
U're able to check their changelog here https://core.telegram.org/api/layers
They removed support of this method in 158 layer and yes, looks strange cuz older versions have to work (while it's supported by any of telegram server)
layer: 139
Is there anyone who can help me?