Developing a integration for Slack is not easy task. Slack’s API is pretty great and allows a lot of freedom. But when you start adding buttons, integrations and, more recently, interactions with blocks your code will quickly become a never-ending list of if/the/else clauses.
While developing integrations the new slack interactions we were writing were becoming unmangeable. For every new button there would be a new if block_id == "feedback-button"
so new solutions needed to be found.
The best one was using Django’s routing mechanism to treat the interactions as urls on a website. Once this mindset was introduced everything became much easier. Let’s start with some examples. First the main methods that make this possible:
1 | def slack_resolver(url: str) -> ResolverMatch: |
As the method signatures show the slack_resolver
method receives the current url being processed and return the resolver to call the view’s function.