Create Microsoft To-Do todos from Slack with Microsoft Flow

I live in Slack but I'd love to be able to easily create Microsoft To-Do todos. It turns out, that there is a Flow for that.

About me

Everybody has their own way of managing tasks: sticky notes, paper notebook, OneNote, Outlook tasks or anyone out of the 20 million task management apps available out there. Personally, I'm an avid user of Wunderlist. I use it for everything from recurring tasks I need to do weekly or monthly to groceries. At work, however, I'm spending a lot of time in Slack. And so recently, I found myself writing down my todos in Slack and marking them as done with reactions. On one hand, it was very convenient because I was in Slack already so all my todos were right in front of me without having to switch the context. But with writing tasks as messages to yourself, it's all too easy to lose track of them over time as they move away from your timeline. So when recently, my colleague Mike introduced me to Microsoft To-Do I was all ears.

Microsoft To-Do, for all your tasks

I have tried Microsoft To-Do in the past, with little luck. When Wunderlist was acquired by Microsoft and Microsoft To-Do proposed as its replacement, I gave it a try. Unfortunately, migrating my Wunderlist tasks to To-Do failed and back then To-Do was missing some things that I was using in Wunderlist, so eventually, I stayed with Wunderlist.

Using To-Do for work today is a different story. Yes, it allows you to create tasks, set their due dates and arrange them in lists, but it also aggregates tasks from Outlook and Planner which is very helpful if you want to keep track of all your work in a single place.

I spend a lot of time in Slack. So for Microsoft To-Do to work for me, I need to be able to quickly create a task from Slack without having to leave my work and open To-Do. At the moment of writing this article, there is no Microsoft To-Do app for Slack. I'm fully aware of Slack's extensibility capabilities and I know I could create an app for it. But I was looking for something simpler. Something that wouldn't require me to learn Slack's APIs, app registrations or deployment processes. It turns out, there is an easy way of creating To-Do todos from Slack.

Create Microsoft To-Do todos from Slack with Flow

There are a number of ways in which you can extend Slack. One of them is to create a custom command. When you enter the command in Slack, it will call the specified URL passing whatever text you typed with the command along with the request. This makes a perfect use case for a Flow with an HTTP request trigger.

Create the Flow

Start, by creating a new Flow with an HTTP request trigger. Because you can't save a Flow with just a trigger, add an Initialize variable action setting its name to text, type to String and leaving the initial value empty. You'll use it later. Right now, all you need to do is to save the Flow, to get the HTTP request-trigger URL. You need the URL to define the custom Slack command which you will use to create todos from Slack. Once the command is in place, you will have all information, such as the payload structure and the security information, necessary to complete the Flow.

Flow with an HTTP request trigger

Create the Slack command

Typically, a custom Slack command requires building and registering a custom Slack application. There is however an alternative way, which isn't maybe as powerful, but which definitely is good enough for what we need.

Slack's Slash Commands app

Using the Slash Commands app created by Slack, you can easily set up custom commands that will allow you to integrate third-party services in Slack.

After installing the app in your workspace, add a new configuration.

Adding new configuration in the Slash Commands app

What you should keep in mind, that whatever command you define, it will be available to everyone in your workspace. There is little harm in others creating a todo for you. On the contrary, it could introduce interesting collaboration scenarios. In the end, whatever name you choose, make it something unique and easy to memorize (you'll be using it to create todos).

After adding the configuration, paste the URL of your Flow's HTTP request trigger and set the method to POST.

Setting the configuration's URL and method

Next, take note of the Token. You will need it to protect your Flow from being abused.

Configuration's token highlighted on the page

To finish the configuration, specify its display name and icon.

Configuration's display name and icon

Because this command is meant for your personal use, you should consider removing it from the autocomplete list so that not everyone in your organization will see the command to add a todo for you, unless it's exactly what you want!

Before confirming the configuration, take note of the outgoing data of the payload.

Custom command's outgoing data payload

This is the information that will be sent by Slack to your Flow every time you (or someone else) will use the command. As you can see, a part of the request is the user information which you could use to ensure that only you can add todos for yourself.

Finishing up the Flow

Now that you have the Slack command in place, the last piece left is to build the Flow that will receive the requests from Slack and create Microsoft To-Do todos on your behalf.

Start, by updating the HTTP request trigger and using the following JSON schema for the request body:

{
  "type": "object",
  "properties": {
    "$content-type": {
      "type": "string"
    },
    "$content": {
      "type": "string"
    },
    "$formdata": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "required": [
          "key",
          "value"
        ]
      }
    }
  }
}

This structure corresponds to the payload sent by Slack to the Flow.

Next, add a parallel branch and add to it a Response action with Status code 200 and a Body set to Creating todo... (or any other text you'd like to show in Slack directly after receiving the request).

Adding a parallel branch with an immediate response

This is necessary because executing the Flow could take longer than the 3000ms maximum set by Slack. If Slack doesn't receive a reply in that timeframe, it will assume that the requested failed. So for the setup to work correctly, you need to send an immediate response, while you're processing the request, validating its payload, creating a To-Do todo and sending a response back. For all this, Slack gives you 30 seconds, but the first response must be sent back within 3 seconds.

Go back to the main branch and initialize two more variables: response_url, which you will use to store the response URL to which to send the final result of adding a todo and token which will contain the security token sent by Slack to verify the origin of the request.

Initializing the response URL and token variables

Next, you need to get the values of the three variables from the request data. Unfortunately, the data is set in an array rather than an object, so to get the value of the different variables, you have to iterate through the $formdata array.

For each of the three variables (text, response_url and token) add a condition block. Inside, compare the value of the key property with the variable name and if it matches is, set the value of the corresponding variable to the value of the current object.

Setting the value of the text variable

With the three variables set, you're ready for the next step.

Three variables set

First, you should check if the token provided in the request, matches the secret from the Slack command.

Verifying security token

If it doesn't, you should send an error message to the reply URL.

Error reply when the token doesn't match the command's secret

If it does, then you should obviously create the todo. Notice, how the Subject of the todo has been set to the text variable, which contains the text sent from Slack.

Creating to do using the text received from Slack

Finally, acknowledge the correct creation of a todo, by sending a message back to Slack:

Sending acknowledgment message to Slack

If you've configured all elements correctly, after typing in Slack /mytodo Write a blog post about creating To-Do todos from Slack, you should see a response similar to the following:

Creating To-Do todo from Slack

Summary

Microsoft Flow offers great capabilities for automating tedious and repetitive tasks but also combining cloud services together to build powerful productivity solutions. Even if you live in Slack, like me, and want to connect it to other services in the Microsoft cloud, you can easily do it using Microsoft Flow, without overly complex development work.

You might enjoy:

Next post No more posts

Comments

comments powered by Disqus