Creating your first slackbot

So I started writing my first slack bot for a friend of mine.

The general idea is that it hosts a set of questionnaires that you can select from, and then it walks you through it collecting your answers, and at the end will post the response. Longer term it will likely send an email as well to an alias for the company to put into a zendesk ticket system, etc.

It is VERY raw right now, nothing is idiomatic, and almost all if it is strictly proof of concept. HEAVY refactoring will come once I have sorted out the actual workings of a slack bot.

There is a REALLY good package that helps get this going pretty fast:

So, what did I learn so far:

1 - Your bot gets a LOT of information, ALL of the time.
2 - Determining if the message was TO your bot wasn’t obvious
3 - An @ message will include the handle of the message, so you have to parse out the prefix to get the actual message.

All in all, it’s going pretty well so far. I’m interested in other peoples experience writing slack bots as well.

10 Likes

@corylanou nice!

I did a quick check and there’s one tiny bug. When receiving mentions format is <@UID(|name)?>. There’s an optional |name that will set the name for the mention. That means some clients might be sending <@BOTID|BOTNAME>.

3 Likes

I have two Slackbots “in production”, both of them based on https://github.com/trinchan/slackbot so they are limited to responding to Slash Commands but that is fine for what they do :smiley:

One of my bots are open source: https://github.com/athega/whistler

2 Likes

omg, thank you for pointing that out! I didn’t read that anywhere. I’ve read through some of the slack API documentation, and it might be some of the most confusing API docs I’ve ever read. No simple code examples, just examples that don’t tell you any edge cases. I’m curious what your experience has been working with it.

There are some great things in the Slack API and some not so great.

The worst parts are:

  • Documentation of some of the docs such as dispersed information and undocumented error codes.
  • Inactivity on their docs on github: api.slack.com has a repository in GitHub, but it’s a fork that is not kept in sync with live docs and for months nobody would attend to issues and PRs from that repo.
  • Undocumented endpoints. Some bits of the API are undocumented because are subject to change.
  • Busted OAuth provider. Like Google and Github, their provider doesn’t follow the spec, which means the goauth2 package will not work with the provider until it’s whitelisted.
  • Inconsistencies around the API. e.g: having fields ts and timestamp for timestamps, having identifiers be timestamp.sequence_id and not providing a different timestamp field.
  • Lack of some methods. e.g: if somebody converts a public channel into a private group there’s no details about the change, they simply delete the channel and create the new group without any indication it was a transformation.
  • No way to create bots or slash commands from the API, which requires manual setup from users.
  • Tail latency can be pretty bad. Posting messages via the RTM API takes ~20ms, posting via the HTTP API, since it requires more transformations, takes hundreds of milliseconds and tail latency can get to several seconds. Since the operation is not idempotent we cannot try to mitigate effects of tail latency by making more than one request and cancel the slower ones.

With this being said, it’s worth noting that up until a few of months ago their platform team was quite small and they are hiring now. I expect this to get better with time.

4 Likes

Awesome! Thanks for the summary. Very helpful!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.