keybase / keybase-issues

A single repo for managing publicly recognized issues with the keybase client, installer, and website.
902 stars 37 forks source link

Pagination broken when reading messages from a channel in a big team in Chat API #4042

Open heupchurch opened 3 years ago

heupchurch commented 3 years ago

The chat API will read only the latest 1000 messages per each API call. For a one-on-one chat, one reaches the next page this by setting a value for "next" and running a second query.

Following the instructions at keybase chat api -h, I read the first page of messages in a one-on-one chat.

{"method": "read", 
    "params": {
         "options": {
            "channel": {
                "name": "you,them"
            }, 
            "pagination": {
                "num": 1000
}}}}}

Some JSON ensues, ending in a pagination block.

"pagination": {
            "next": "next_value",
            "previous": "prev_value",
            "num": 1000
        }
    }

One then takes next_value from the JSON result and runs a second query.

{"method": "read", 
    "params": {
         "options": {
            "channel": {
                "name": "you,them"
            }, 
            "pagination": {
                "next": "next_value",
                "num": 1000
}}}}

This returns the second page of chat results and may be iterated until one reaches the last message. It seems to me that this same process should work for the messages in a channel in a team: however, this is not the case.

If I follow the help docs and read messages in a channel in a team as follows...

 {"method": "read",
    "params": {
        "options": {
            "channel": {
                "name": "treehouse",
                "members_type": "team",
                "topic_name": "meetings",
            "pagination": {
                "num": 1000
}}}}}

... I do in fact get 1000 messages followed by a pagination block as above. However, when I take next_value from the JSON results as before and pass a second query...

{"method": "read",
    "params": {
        "options": {
            "channel": {
                "name": "treehouse",
                "members_type": "team",
                "topic_name": "meetings",
            "pagination": {
                "next": "next_value",
                "num": 1000
}}}}}

... it appears that the API does not process the request. Instead, the first page of results is returned a second time.

If you attempt to incorporate the pagination function into a script or bot that has to read beyond the first page of message results, everything breaks. Maybe I am doing something wrong but everything in the available documentation suggests that pagination should work for channels in teams as it does for one-on-one chats.