Pagination

Some Plugin SDK methods return paginated results. For example, the listMessages and listChannels methods return paginated results. Returning paginated results improves performance but requires that you implement the pagination strategy described in this topic when using these methods.

A method that returns paginated results will include a paginationToken parameter and a nextPageToken return value. Refer to the Context API reference to determine whether specific methods are paginated.

How to handle paginated results

Complete the following steps to iterate through paginated results:

  1. Call the method without the pagination token to return the first page of results. For example, listMessages()
  2. Display the first page of results to the user.
  3. Note the nextPageToken returned by the method. For example:
    {
      nextPageToken: "eyJvZmZzZXQiOjUwfQ==",
      results: [...]
    }
    
  4. If the user requests the next page (through a button or other input), make a subsequent call to the method with the value of the page token included. For example, listMessages(eyJvZmZzZXQiOjUwfQ==)

    πŸ“˜

    Wait for user input to request the next page - do not display all results at once

    For performance reasons, do not iterate through all the pages and display the results all at once. The best practice is to provide pagination buttons to the user in the plugin so that the user requests only the results they need.

  5. Repeat this process until the nextPageToken returns undefined. If the page token is undefined, disable the button that requests another page.