Skip to content
Instant

Developers

Example: a standup bot

A whole bot you can run in five minutes on your laptop, with no public URL: it answers a mention with a button, opens a form, checks what people type and posts the result.

Set Up the Bot

  1. In Settings › Bots & Apps, choose New Bot, call it Standup Bot and copy its token.
  2. On its page, turn on Socket Mode and tick the app_mention event.
  3. Under Slash Commands, add /daily. Its URL isn’t used in Socket Mode; any https address will do.
  4. Add it to a channel: /invite @Standup Bot.

Run It

Save these two files in a new folder, then:

npm install
INSTANT_BOT_TOKEN=ib_… npm start

package.json

{
  "name": "standup-bot",
  "private": true,
  "type": "module",
  "scripts": { "start": "node app.js" },
  "dependencies": { "@slack/bolt": "^4.7.0" }
}

app.js

// An Instant bot with Slack's Bolt for JavaScript, in Socket Mode, so it runs anywhere with no public URL.
import bolt from '@slack/bolt';

const { App } = bolt;
const token = process.env.INSTANT_BOT_TOKEN;
const api = { slackApiUrl: process.env.INSTANT_API_URL ?? 'https://api.instant.im/api/' };

const app = new App({
  token,
  socketMode: true,
  appToken: token, // Instant's bot token opens the socket too: there is no separate app-level token.
  clientOptions: api,
  installerOptions: { clientOptions: api }, // the socket's own client calls apps.connections.open here
});

// Someone @mentions the bot: answer in a thread, with a button.
app.event('app_mention', async ({ event, say }) => {
  await say({
    thread_ts: event.ts,
    text: `Hi <@${event.user}>!`,
    blocks: [
      { type: 'section', text: { type: 'mrkdwn', text: `Hi <@${event.user}>! Want to log a standup?` } },
      { type: 'actions', elements: [{ type: 'button', action_id: 'standup', text: { type: 'plain_text', text: 'Log Standup' }, style: 'primary' }] },
    ],
  });
});

// The button opens a form. /daily does the same.
const standupForm = {
  type: 'modal',
  callback_id: 'standup',
  title: { type: 'plain_text', text: 'Standup' },
  submit: { type: 'plain_text', text: 'Post' },
  blocks: [
    { type: 'input', block_id: 'done', label: { type: 'plain_text', text: 'Yesterday' }, element: { type: 'plain_text_input', action_id: 'text', multiline: true } },
    { type: 'input', block_id: 'next', label: { type: 'plain_text', text: 'Today' }, element: { type: 'plain_text_input', action_id: 'text', multiline: true } },
    { type: 'input', block_id: 'where', label: { type: 'plain_text', text: 'Post In' }, element: { type: 'conversations_select', action_id: 'channel' } },
  ],
};

app.action('standup', async ({ ack, body, client }) => {
  await ack();
  await client.views.open({ trigger_id: body.trigger_id, view: standupForm });
});

app.command('/daily', async ({ ack, body, client }) => {
  await ack();
  await client.views.open({ trigger_id: body.trigger_id, view: standupForm });
});

// The form comes back: check it, then post the summary as the bot.
app.view('standup', async ({ ack, view, body, client }) => {
  const v = view.state.values;
  const today = v.next.text.value?.trim() ?? '';
  if (today.length < 3) {
    await ack({ response_action: 'errors', errors: { next: 'Say a little more about today.' } });
    return;
  }
  await ack();
  await client.chat.postMessage({
    channel: v.where.channel.selected_conversation,
    text: `*Standup from <@${body.user.id}>*\n*Yesterday:* ${v.done.text.value}\n*Today:* ${today}`,
  });
});

await app.start();
console.log('Standup Bot is running');

Try It

  1. Write @Standup Bot hello in the channel. It answers in a thread with a Log Standup button.
  2. Click it, or type /daily. A form opens.
  3. Write one word under Today and submit: the form stays open and says what’s wrong, the bot’s response_action: "errors".
  4. Fix it, pick a channel and submit. The bot posts your standup there.

Where to Go Next

  • Give each person a Home tab with their recent standups: App Home.
  • Add a message shortcut that turns any message into a standup line: Shortcuts.
  • Moving a bot you already have? Porting from Slack.

Build Your First Bot

Make a bot in Settings › Bots & Apps and post your first message in a minute.

Join NowSee Pricing