zendframework / zfbot

Chatbot for the Zend Framework Slack
MIT License
8 stars 5 forks source link

Implements Discourse webhooks #1

Closed weierophinney closed 7 years ago

weierophinney commented 7 years ago

There were a couple big stumbling blocks.

First, the webhooks API is completely undocumented. As such, I have no idea how to properly register a webhook via the API to ensure it listens to only the events I'm interested in, in the specific category or categories I'm interested in. As such, I had to choose not to allow registering new webhooks via Slack; we'll need to register hooks manually, mapping them to the appropriate room in the Slack.

Second, the Discourse API does not return sub-categories for its "categories" endpoint, making discovery of all categories pretty much impossible. This is particularly problematic as the webhooks provide category identifiers in their payloads, but no other category details. We could fetch this information on the fly (by introspecting the first topic returned for a given category endpoint, e.g., /c/{slug}.json), but since the HTTP client shipped with hubot is async, this leads to callback hell.

What I opted for was the following architecture:

I used the slack-htmlify package to make the post (comment) text work within Slack (as it comes in as HTML).

Finally, I updated the nginx configuration to allow forwarding /discourse URIs to the bot to manage.

TODO