Thanksgiving is a good reminder to take a moment to appreciate the people we work with. It’s also a fun opportunity to build something small that brings a team together.
For this year’s Thanksgiving, I put together a simple Gratitude app for Slack. Teammates can run /gratitude, select someone they’re thankful for, add a few words about why, and share their message in a channel.
It’s a small app, but it brings together three useful Slack platform capabilities: slash commands, modals, and message publishing. More importantly, these are building blocks you can reuse for all kinds of internal workflows.
Let’s take a look at how it works.
A simple idea, powered by three Slack building blocks
The experience follows a straightforward pattern:
Trigger → Collect → Publish
A slash command starts the interaction, a modal collects the information, and a message shares the result with the team.
Here’s what the experience looks like from a user’s perspective:
- Run /gratitude in a channel.
- Select the teammate you’re thankful for.
- Add a reason or a specific moment you’d like to recognize.
- Submit the modal and share the message with the team.
Behind the scenes, Bolt for JavaScript handles the incoming interactions, while Slack’s APIs open the modal and publish the resulting message.
Getting started with the Slack CLI
I’ll use the Slack CLI and the Bolt for JavaScript starter template to create the app. If you haven’t installed and authenticated the Slack CLI yet, start with the Slack CLI documentation.
Create a new project:
slack create slacksgiving-gratitude-app -t slack-samples/bolt-js-starter-template
cd slacksgiving-gratitude-app
npm install
The starter template gives us the project structure and Bolt setup, so we can focus on the app’s functionality. You can also explore the available starter templates with the Slack CLI and choose one that fits your project.
Giving the app a slash command
First, let’s tell Slack how users will interact with the app.
In manifest.json, we’ll declare the /gratitude slash command, the permissions the app needs, and enable interactivity so Slack can send interactive payloads back to our app:
{
"display_information": {
"name": "Slacksgiving Gratitude App"
},
"features": {
"bot_user": {
"display_name": "Slacksgiving Gratitude App",
"always_online": false
},
"slash_commands": [
{
"command": "/gratitude",
"description": "Share gratitude with your team",
"should_escape": false
}
]
},
"oauth_config": {
"scopes": {
"bot": ["commands", "chat:write"]
}
},
"settings": {
"interactivity": {
"is_enabled": true
},
"socket_mode_enabled": true,
"org_deploy_enabled": false,
"token_rotation_enabled": false
}
}
The commands scope allows the app to receive slash commands, while chat:write lets it publish messages in conversations where the bot is a member.
Interactivity is enabled because our app needs to receive the modal submission when someone selects Share Thanks. The slash command itself is declared separately under features.slash_commands.
If you want the app to post in public channels without first being invited, you can also add chat:write.public. The bot must still be a member of private channels where it wants to post.
You can validate the manifest with:
slack manifest validate --source local
Connecting Bolt to Slack
For this example, we’ll use Socket Mode to connect our local app to Slack. Socket Mode lets your app receive slash commands and interactive payloads over a WebSocket connection, so you can develop and test without exposing a public HTTP endpoint.
The starter template already provides the basic Bolt structure. Our app.js uses the bot token and app-level token to establish that connection:
require("dotenv").config();
const { App } = require("@slack/bolt");
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
});
(async () => {
await app.start(process.env.PORT || 3000);
console.log("Slacksgiving Gratitude app is running!");
})();
When you run the app with slack run, the Slack CLI supplies the tokens for your development environment. If you run it another way, you’ll need to provide your bot token and app-level token through your environment variables.
Collecting gratitude with a modal
Now for the first part of the interaction: opening a modal when someone runs /gratitude.
Bolt lets us listen for the slash command using app.command(). Once the command arrives, we acknowledge it and use its trigger_id to open a modal with views.open.
const GRATITUDE_MODAL_CALLBACK_ID = "gratitude_modal_submit";
app.command("/gratitude", async ({ ack, body, client, logger }) => {
await ack();
try {
await client.views.open({
trigger_id: body.trigger_id,
view: {
type: "modal",
callback_id: GRATITUDE_MODAL_CALLBACK_ID,
private_metadata: body.channel_id || "",
title: { type: "plain_text", text: "Send Gratitude" },
submit: { type: "plain_text", text: "Share Thanks" },
close: { type: "plain_text", text: "Cancel" },
blocks: [
{
type: "input",
block_id: "person_block",
label: { type: "plain_text", text: "Who are you thankful for?" },
element: {
type: "users_select",
action_id: "person_action",
placeholder: { type: "plain_text", text: "Select a teammate" },
},
},
{
type: "input",
block_id: "reason_block",
label: { type: "plain_text", text: "Why are you thankful?" },
element: {
type: "plain_text_input",
action_id: "reason_action",
multiline: true,
placeholder: {
type: "plain_text",
text: "Share a specific moment or contribution...",
},
},
},
],
},
});
} catch (error) {
logger.error(error);
}
});
There are a few details worth calling out here.
First, acknowledge the slash command promptly. Slack expects an acknowledgement within three seconds, and the trigger_id used to open the modal is short-lived. Calling ack() first and opening the modal immediately afterward keeps the interaction moving.
Second, notice the block_id and action_id values on each input. These identifiers make it possible to retrieve the submitted values later. The block_id identifies the input block, while the action_id identifies the element inside it.
Finally, we’re using private_metadata to preserve the channel ID from the original slash command. This gives the submission handler the context it needs to publish the message back to the same channel.
Sharing the message with the team
Once someone submits the modal, Bolt can handle the submission using app.view(). The handler retrieves the selected user and the reason from the modal’s state, then publishes a formatted message with chat.postMessage.
Here’s the submission handler:
const GRATITUDE_CHANNEL_ID = process.env.GRATITUDE_CHANNEL_ID;
app.view(GRATITUDE_MODAL_CALLBACK_ID, async ({ ack, body, view, client, logger }) => {
await ack();
try {
const selectedUser = view.state.values.person_block.person_action.selected_user;
const reason = view.state.values.reason_block.reason_action.value.trim();
// Prefer an explicit channel, otherwise post where /gratitude was run
const targetChannel = GRATITUDE_CHANNEL_ID || view.private_metadata;
if (!targetChannel) return;
const message = [
":pie: _Thanksgiving Gratitude Moment_",
`<@${body.user.id}> is thankful for <@${selectedUser}>`,
`> ${reason}`,
"_Use `/gratitude` to add yours._",
].join("\n");
await client.chat.postMessage({
channel: targetChannel,
text: `<@${body.user.id}> shared gratitude for <@${selectedUser}>`,
blocks: [
{
type: "section",
text: { type: "mrkdwn", text: message },
},
],
});
} catch (error) {
logger.error(error);
}
});
The destination is configurable. If GRATITUDE_CHANNEL_ID is set, every submission goes to that channel. Otherwise, the app uses the channel ID saved in the modal’s private_metadata, so the message appears where the command was originally run.
You’ll also notice that we’re providing both text and blocks in the message payload. The top-level text acts as a notification and accessibility fallback, while the Block Kit section gives us control over the message’s formatting.
For this example, we’re acknowledging the modal submission before publishing the message. That keeps the interaction responsive, but it also means a later posting error won’t be displayed in the modal. In a production app, you may want to add more specific error handling so users know when an action hasn’t completed successfully.
Bringing it all together
With the command handler and view submission handler in place, start the app:
slack run
Install it in your development environment when prompted, then run /gratitude in a channel to try it out.
You can also experiment with the experience. For example, you could add a category to describe the kind of contribution someone appreciates, let people post anonymously, or include a team or project selector. The Block Kit Builder is a handy place to prototype modal layouts before updating the code.
Beyond Thanksgiving: reuse the pattern
The Gratitude app is intentionally small, but the underlying pattern is useful well beyond the holiday.
Trigger → Collect → Publish can be the foundation for many everyday team workflows:
- /win: Collect a teammate’s weekly accomplishment and share it in a wins channel.
- /insight: Capture customer feedback, including context and a follow-up action.
- /handoff: Gather on-call notes and publish a structured shift handoff.
- /retro-note: Collect sprint retrospective feedback for the team to review.
You don’t have to use a slash command every time, either. You could start an interaction with a message shortcut or a button, collect additional information in a modal, and publish the result somewhere useful.
The important part isn’t the Thanksgiving theme or even the specific app. It’s understanding how these Slack platform capabilities fit together. Once you know how to combine them, you can start building workflows that solve all kinds of problems for your team.
Happy Thanksgiving, and happy building! 🥧
