alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
625 stars 111 forks source link

messages.getAllChats always retrun INPUT_METHOD_INVALID_2271179966_* #279

Open bigbigsir opened 1 year ago

bigbigsir commented 1 year ago

layer: 139

image image image

Is there anyone who can help me?

wind-hx commented 1 year ago

I also encounter the same problem

0xARK commented 1 year ago

Hello, I also have this problem

bigbigsir commented 1 year ago

What happened? It didn't change anything, and all of a sudden it didn't work

bigbigsir commented 1 year ago

@alik0211

0xARK commented 1 year ago

I checked the telegram api docs for update or something else, but I saw nothing related to getAllChats...

destyk commented 1 year ago

This error is true for me too

alexsanderluisdev commented 1 year ago

same for me, has anyone found any solution?

alexsanderluisdev commented 1 year ago

Has anyone found any solution?

destyk commented 1 year ago

@alik0211

0xARK commented 1 year ago

It seems that this method has been removed from telegram API, and getDialogs must be used instead.

See https://github.com/gram-js/gramjs/issues/522

alexsanderluisdev commented 1 year ago

It seems that this method has been removed from telegram API, and getDialogs must be used instead.

See gram-js/gramjs#522

however the getDialogs method gets only recent conversations and not all conversations.

0xARK commented 1 year ago

Oh, didn't noticed that, I just saw this answer... It will be a problem for me too, more digging is necessary :(

alexsanderluisdev commented 1 year ago

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.

alexsanderluisdev commented 1 year ago

@0xARK any solution?

0xARK commented 1 year ago

No, I didn't have time to look into it

0xARK commented 1 year ago

See https://github.com/gram-js/gramjs/issues/522#issuecomment-1538045572 @alexsanderluisdev

alexsanderluisdev commented 1 year ago

@0xARK this don't work for me. Causes a infinity loop.

0xARK commented 1 year ago

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;
        }
alexsanderluisdev commented 1 year ago

don't work, this lists even fewer chats, and chats that have no interaction are still not listed

Endytech commented 1 year ago

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));
    }
joeberetta commented 1 year ago

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)