Skip to main content

Introduction

This guide covers creating and deploying Slack bots on Shard Cloud.

Creating a Slack App

1

Create App

Go to Slack API - Your Apps and click “Create New App”.
2

Choose Creation Method

Select “From scratch”, name your app, and select your workspace.
3

Get Credentials

In “Basic Information”, note your Signing Secret. In “OAuth & Permissions”, add scopes like chat:write, app_mentions:read, commands.
4

Install to Workspace

Click “Install to Workspace” and copy the Bot Token (starts with xoxb-).
Security: Never expose your Signing Secret or Bot Token publicly.

Creating Your Bot

Setup

npm init -y
npm install @slack/bolt

Basic Bot Code

index.js
const { App } = require('@slack/bolt');

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
});

// Respond to mentions
app.event('app_mention', async ({ event, say }) => {
  await say(`<@${event.user}> Thanks for mentioning me!`);
});

// Slash command
app.command('/ping', async ({ ack, respond }) => {
  await ack();
  await respond('Pong!');
});

(async () => {
  await app.start(process.env.PORT || 80);
  console.log('⚡️ Slack bot is running!');
})();

Package.json

package.json
{
  "name": "slack-bot",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "@slack/bolt": "^3.0.0"
  }
}

Environment Variables

Set these in the Shard Cloud dashboard:
  • SLACK_SIGNING_SECRET: Your app’s signing secret
  • SLACK_BOT_TOKEN: Your bot’s OAuth token

Shard Cloud Configuration

.shardcloud
DISPLAY_NAME=Slack Bot
DESCRIPTION=My Slack Bot
MAIN=index.js
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-slack-bot
The SUBDOMAIN is required for Slack to send events to your bot via webhooks.

Configuring Slack Events

After deployment, configure your Request URLs in Slack:
  1. Event Subscriptions: Enable and set URL to https://my-slack-bot.shardweb.app/slack/events
  2. Slash Commands: Set URL to https://my-slack-bot.shardweb.app/slack/events

Deploying

1

Prepare Your Files

Ensure you have: - Your bot code file - package.json or requirements.txt
  • .shardcloud
2

Set Environment Variables

Configure SLACK_SIGNING_SECRET and SLACK_BOT_TOKEN in the dashboard.
3

Create ZIP Archive

Compress your project folder (excluding node_modules/).
4

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload.
5

Configure Slack URLs

Update Event Subscriptions and Slash Command URLs in your Slack app settings.

Additional Resources

Troubleshooting

  • Verify your Request URL is correct - Ensure your app is running and accessible - Check that the signing secret matches
Make sure your bot is running before verifying the URL in Slack.