Add a date variable in a Slack Workflow

Curious software engineer
Search for a command to run...

Curious software engineer
No comments yet. Be the first to comment.
In this series, I will treat subjects related to software development, software engineering, and related career.
This is a long title, but it is on the point. I am going to show you how to set up AWS Cloudfront, the CDN solution of Amazon, in front of your AWS website. The solution works if your website is hosted on a single server or if you have multiple i...
It’s the summer holidays, after all. So I wanted to spent some time with my 7 years old daughter to teach her programming. ⌨️ I spent some time before discussing with her some of the basics concept verbally: the different parts of a computer, and bas...

This article is a follow up on my previous one introducing the concept of SE Spectrum: https://sonny.alvesdi.as/a-better-way-to-discuss Existing solutions For long, the easiest way to run a spectrum was to use visual drawing or diagram tools like ...

Introduction to SE Spectrum

One of the greatest tool available on GitHub is Dependabot. For those not familiar with it, in short it's a bot reviewing your list of dependencies and proposing PRs to update them. https://docs.github.com/en/code-security/getting-started/dependabot-...

Photo by Harli Marten on Unsplash As long as I remember I have always been interested by skepticism. And I think one element that really resonated with me has been that conference talk by Phil Plait: https://www.youtube.com/watch?v=FrFRbGjUtJk 15 ...

One annoying thing that is not supported in Workflows yet is date. What a pity, to not have a date picker available in your workflow.
And even a variable that be the date time of when a form has been submitted. Fortunately, it is not hopeless.
By coding a workflow step ourselves, we can add a date!
First, I would invite you to read that official tutorial from Slack: https://api.slack.com/tutorials/workflow-builder-steps
In the tutorial, you can find a link to remix (fork) the glitch repo. So go ahead and remix it.
Then follow the README.md to prepare your Slack app and the .env of the glitch.
One thing was not clear from the README is how to get the bot token. You actually need to go to
OAuth & Permissions. Then install in workspace. Finally, you should copy that token which starts byxoxb-.
Here is the code I use for my case, which is, I need the date of the submission of a form in a variable.
const { App, WorkflowStep } = require("@slack/bolt");
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
});
const ws = new WorkflowStep("copy_review", {
edit: async ({ ack, step, configure }) => {
await ack();
const blocks = [
{
type: "section",
block_id: "intro-section",
text: {
type: "plain_text",
text:
"Get the current date in a variable.",
emoji: true
}
}
];
await configure({ blocks, submit_disabled: false });
},
save: async ({ ack, step, update, view }) => {
await ack();
const inputs = {};
// NOTE: We define a new output variable called date
const outputs = [
{
type: "text",
name: "date",
label: "Date"
}
];
await update({ inputs, outputs });
},
execute: async ({ step, complete, fail, client }) => {
const today = new Date().toDateString();
// NOTE: We assign a value to the variable date
const outputs = {
date: today
};
await complete({ outputs });
}
});
app.step(ws);
(async () => {
// Start your app
const port = process.env.PORT || 3000;
await app.start(port);
console.log(`⚡️ Get Date Bolt app is running on port ${port}!`);
})();
Copy and paste that code in the file index.js of your Glitch.
That's it.
Open the Slack Workflow Builder, add your step and use your date variable!
Note that Glitch apps goes to sleep after 5 minutes of inactivity. You can either purchase a pro account to remove that limitation or google to find alternative. Maybe the best option is to just to host the app yourself, but don't forget to update your Slack app configuration.
Photo by Estée Janssens on Unsplash