Search code examples
slack-apislack

How to write minimal Slack script without a server?


I joined a Slack team and now I want to play with the bots there. But there seem to be lots of different ways and they all involve some server with API.

Isn't there an easy way to write a script (is that a bot) for end users? I write a file, load it into the slack app and it works?

My first idea (just to try it out) was to respond to certain keywords automatically from my own account.


Solution

  • There are four types of custom Slack integrations:

    • Incoming webhooks: your code sends an HTTP POST to Slack to post a message
    • Custom slash commands: Slack sends your code an HTTP POST when someone says /<whatever>
    • Outgoing webhooks: roughly the same as slash commands, but they can respond to any word at the beginning of a message
    • Bot users: your code connects to Slack via a WebSocket and sends and receives events

    In all of these cases, you need code running somewhere to actually do the work. (In the case of the bot, that code can run anywhere with network connectivity. In the other cases, you'll need a server that's listening on the internet for incoming HTTP/HTTPS requests.)

    Slack itself never hosts/runs custom code. I'd say https://beepboophq.com/ is the closest thing to what you're looking for, since they provide hosting specifically for Slack bots.

    Another option for things like slash commands is https://www.webscript.io (which I own). E.g., here's the entirety of a slash command running on Webscript that flips a coin:

    return {
        response_type = 'in_channel',
        text = (math.random(2) == 1 and 'Heads!' or 'Tails!')
    }