Systems Library / Platform Integrations / How to Build a Slack Bot for Business Automation
Platform Integrations communication platforms

How to Build a Slack Bot for Business Automation

Create a custom Slack bot that automates business workflows.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

A slack bot business automation custom system automates approvals, pulls reports, and triggers workflows from slash commands. I build these for teams that need their communication tools to do more than just send messages.

What You Need

Step 1: Set Up the Project

npm init -y && npm install dotenv
import 'dotenv/config';

const API_TOKEN = process.env.BOT_TOKEN;
console.log('Bot starting...');

Step 2: Build the Message Handler

async function handleMessage(message, sender) {
  const text = message.toLowerCase().trim();

  if (text === 'report') {
    const metrics = await fetchMetrics();
    return formatReport(metrics);
  }

  if (text === 'status') {
    return 'All systems operational.';
  }

  if (text === 'help') {
    return 'Commands: report, status, help';
  }

  return null; // No auto-response
}

async function fetchMetrics() {
  return { leads: 23, spend: 800, cpl: 34.78 };
}

function formatReport(metrics) {
  return `Daily Report\nLeads: ${metrics.leads}\nSpend: $${metrics.spend}\nCPL: $${metrics.cpl}`;
}

Step 3: Add Automated Notifications

async function sendNotification(channel, message) {
  // Platform-specific send logic
  console.log(`Sending to ${channel}: ${message}`);
}

async function dailyReport() {
  const metrics = await fetchMetrics();
  const report = formatReport(metrics);
  await sendNotification(process.env.REPORT_CHANNEL, report);
}

Step 4: Schedule Regular Messages

import cron from 'node-cron';

// Daily report at 9am weekdays
cron.schedule('0 9 * * 1-5', dailyReport);

// Hourly health check
cron.schedule('0 * * * *', async () => {
  const healthy = await checkHealth();
  if (!healthy) {
    await sendNotification(process.env.ALERT_CHANNEL, 'System health check failed');
  }
});

async function checkHealth() {
  // Your health check logic
  return true;
}

Step 5: Add Interactive Actions

async function handleAction(actionId, userId, data) {
  switch (actionId) {
    case 'approve':
      await processApproval(data.requestId);
      return `Approved by user ${userId}`;
    case 'reject':
      return `Rejected by user ${userId}`;
    default:
      return 'Unknown action';
  }
}

async function processApproval(requestId) {
  console.log(`Processing approval: ${requestId}`);
  // Trigger downstream workflow
}

What to Build Next

Add an AI layer that answers questions about your business data in natural language. Team members ask the bot "what was our CPL last week?" and it queries the database and responds with the answer.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems