If everyone in your team hates you because they think you’re an ass, you could change your behavior to fix that. Or create a bot that is even worse than you, giving you a step up to “not that good but seriously there’s worse”, using Azure bot framework, connected to Slack, with very little code, and costing between $0 and pennies.

This is what we aiming at

tl;dr

  • Connect to Azure portal
  • Create a Bot Service
  • Select the “Basic” template
  • Configure CI through GitHub integration
  • Add Slack channel and follow the wizard
  • Look at the code, modify it to react to messages
  • Done.

Basic concept

We’re going to create a bot using the bot framework, setup the CI pipeline for it, and plug it to Slack.

Bot Framework is a template that gets deployed to an Azure Function app. You don’t directly operate the app, but instead get to interact with the function code, and a configuration panel that makes things really easy.

Functions (Microsoft’s equivalent to lambdas) are very inexpensive, billing is based on consumption, the first few thousand seconds are free.


graph LR;

GitHub -. stores .-> FW
Function -. hosts .-> FW[Bot framework]
Function[Azure Function] -- Pull from --> GitHub
Slack -- Triggers --> Function

We’re going to create a bot user in Slack, which you’ll then be able to add to channels. Properly configured, Slack will callback the function on each message received by the bot user, then we’ll filter messages and respond to a select few, distilling good advice and common knowledge, with the appropriate condescending tone.

Create the service

Start through the Azure portal, then add a service (Click the “+” on top left), filter bot service out, then click create.

Create bot service

First step is to create a corresponding Microsoft App, which will be useful if you want to publish your bot for the world to use in the future. Give your bot a name, and copy the password that gets generated. You don’t necessarily need to save it anywhere if you don’t plan to publish the app.

Create application

Then paste it in the next screen as instructed, and pick your template. You can go crazy and integrate with Luis to process complex language and stuff. For now we’ll stick with something simple and just use regex to understand what’s happening (and use node in this example). So pick the “Basic” template and select “Node” as the language.

Templates

Click “Create”. Voilà, your bot is alive. You can start discussing with it on the light client on the right - it just echoes what you says.

Setup CI

Before starting playing around, let’s start by setting up our CI pipeline. Like with node webapps and functions, it’s as simple as connection Azure with GitHub.

Go to the settings tab, then click “Setup” next to “Continuous integration”, select GitHub.

Setup CI

Go to GitHub, create a new repository, and copy the “clone” url.

Then download the zip file, unzip it somewhere, and initialize a Git repository in the unzipped folder. You should more or less follow these steps:

git init
git remote add origin [PASTE THE CLONE URL]
echo ".vscode" > .gitignore
echo "node_modules" >> .gitignore
git add -A
git commit -m "Initial commit"
git push origin master

Back to the bot framework setup panel, click Continuous Integration and configure the repository you just created, and pick the master branch.

Setup CI

You need to provide read permissions, then you’re all set for CI. Anytime you push to the master branch on GitHub, the bot will get re-deployed. Which means you’ll need to test before you deploy to get an uninterrupted harassment experience.

Setup Slack

Now that CI is setup, let’s plug Slack. Go to the “Channels” tab, and pick Slack.

Channels

This will trigger another wizard, which is fairly comprehensive:

Slack configuration

Some of the pictures are out of date, but you’ll find the information by browsing the different tabs in Slack. Give your bot a nice name (such as TaaS - Terrible person As A Service), and upload an avatar. That’s how you’ll be able to interact with him.

Once you granted Slack access to Azure, go to your Slack team, and start a Direct Message with your bot, by hitting Cmd-K and typing its name. It should echo back what you’re saying.

Teach harassment to your bot

Your bot is now alive, we just have to make it smarter and meaner.

First, we’re going to create a new JavaScript file to keep things a bit cleaner. We’ll go ahead and put that in a nice message.js file:

var process = (message) =>
{
  return {respond: false, text: ""};
};

module.exports = {
  process
};

and edit the index.js to use this object instead of directly replying:

"use strict";
var messages = require("./messages");
// [...]

bot.dialog('/', function (session) {
    var response = messages.process(session.message);
    if (response.respond)
        session.send(response.text);
});

This way we can leave the default cabling of the bot alone, and focus on processing the message and providing a response in a very isolated manner.

Let’s go ahead and add some tests. First off, we’ll add mocha and should, for the sake of it:

npm install --saveDev mocha
npm install --saveDev should

We’ll add two simple tests: our bot should not react to everything, but should harass you on select pieces:

  it("shouldn't react to triviality", () => {
    var response = processor.process({text: "Hello, how are you?"});
    response.respond.should.be.false();
  });

  it("should be talking down to people when stuff is broken", () => {
    ["The build is broken", "It doesn't work", 
     "It's not working", "The build failed.", 
     "Some tests are failing"].forEach((message) =>
      var response = processor.process({text: message});
      response.respond.should.be.true();
      response.text.should.equal("What are you doing wrong? It works on my machine.");
  });

Now all we have to do is make these tests pass. Let’s go back to our process function and make it do the job.

var respond = function(message){
  response = {
    respond: false,
    text: ""
  };

  setResponse = (response) =>
  {
    response.respond = true;
    response.text = response;
  };

  switch (true)
  {
    case /not working/.test(message.text):
    case /doesn\'t work/.test(message.text):
    case /\bfail/.test(message.text):
    case /\bbroken\b/.test(message.text):
      setResponse(quotes.notWorking);
      break;
  }

  return response;
};

Run the tests again, they should pass. Commit everything to git, push, wait for a minute - then talk to your bot on slack and see the change. In addition to unit-testing your library, you can run the bot framework on your computer, using the Bot Framework emulator if you want to do some manual testing.

Next

There you go. A simple and solid base for interrupting serious discussions with triviality, talking down to people and more importantly, making you look less terrible.

Now that it’s ready, all that is left for you is to add it to channels and see the magic operate.

Ideas for improvement:

  • add more reactions
  • make it respond only 50% of the time, unpredictability is key to ass-ness.
  • make it respond by picking a random quote in a pre-established series
  • make it even smarter through integration with Luis

You’ll find the full project ready for deployment here, on GitHub.