HomePage - 18F/charlie GitHub Wiki

Charlie developer documentation > Home page

Charlie displays a home page when users open it in Slack. That page and its interactions are handled by the home script, but that script uses the HomePage utilities to know what to put on the home page. Bots also use these utilities to register themselves to have an opportunity to add content to the home page when the user requests it.

getDidYouKnow(String userId) : [SlackMessageBlock]

Get a list of Slack message blocks used to populate Charlie's home page for the requesting user. This method is used by the home script and is unlikely to be useful for bots.

Argument Description
userId The Slack user ID of the user to fetch this information for. Bots may return different information based on the user being shown the home page.

Returns

  • An array of objects matching the DidYouKnow interface (see registerDidYouKnow) below for information about this interface.

getInteractive(String userId) : [SlackMessageBlock]

Get a list of Slack message blocks used to populate Charlie's home page for the requesting user. This method is used by the home script and is unlikely to be useful for bots.

Argument Description
userId The Slack user ID of the user to fetch this information for. Bots may return different information based on the user being shown the home page.

Returns

  • An array of objects matching the Interactive interface (see registerInteractive) below for information about this interface.

refresh(String userId, SlackClient client) : Promise

Refreshes the home page for a given user. The home page needs to be manually refreshed if any of the information on it should be updated. Bots should call this as-needed, but be mindful about whether or not it's actually needed. If a user toggles a checkbox, for example, Slack updates the UI immediately and it is not necessary to refresh the home page.

Argument Description
userId The Slack user ID of the user whose home page needs to be updated. This will end up being passed back to the bots that registered home page handlers so they can build their information accordingly.
client A Slack web API client from Bolt. This can be obtained from the client property of objects passed to Bolt handlers. Unlike other APIs, the client is actually required here.

Returns

  • A promise. Its behavior is undefined, but the current implementation will always resolve with no value.

registerDidYouKnow(Function<SlackMessageBlock> callback)

Register a callback to provide content for the "did you know" section of the home page. This callback function will be called when the home page is first loaded or when it is refreshed. The function will be given the ID of the user who is viewing the home page and must return a Slack message block object that will be inserted into the message sent to Slack.

Argument Description
callback The function to be called when the home page is being rendered or refreshed. This function is passed a user ID and must return a Slack message block.

registerInteractive(Function<SlackMessageBlock> callback)

Register a callback to provide content for the interactive section of the home page. This callback function will be called when the home page is first loaded or when it is refreshed. The function will be given the ID of the user who is viewing the home page and must return a Slack message block object that will be inserted into the message sent to Slack.

Argument Description
callback The function to be called when the home page is being rendered or refreshed. This function is passed a user ID and must return a Slack message block.

registerRefresh(Function callback)

Set a function to be called in place of the refresh function above. The default refresh does nothing because it doesn't have the necessary context. Instead, the home script creates and registers a refresh function. Bots should not need to call this.

Argument Description
callback The function to use as refresh instead of the default no-op.