Loading...
Complete Slack bot with slash commands. Copy, configure, and deploy in minutes.
Go to api.slack.com/apps → Create New App → From scratch
Settings → Socket Mode → Enable (generates App Token)
Features → Slash Commands → Create: /enhance, /removebg, /cartoon, /upscale
OAuth → Scopes: chat:write, commands, files:read, app_mentions:read
Install to workspace, copy tokens, run the bot
// Slack Bot - Complete Implementation
// Save as: index.js and run with Node.js
const { App } = require('@slack/bolt');
const app = new App({
token: 'YOUR_SLACK_BOT_TOKEN',
signingSecret: 'YOUR_SLACK_SIGNING_SECRET',
socketMode: true,
appToken: 'YOUR_SLACK_APP_TOKEN',
});
const BUTTERFLY_API_KEY = 'YOUR_BUTTERFLY_API_KEY';
// Helper function to call ButterflyAPI
async function processImage(api, imageUrl, options = {}) {
const response = await fetch('https://butterflyapi.com/api/v1/run', {
method: 'POST',
headers: {
'Authorization': `Bearer ${BUTTERFLY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ api, imageUrl, ...options }),
});
return response.json();
}
// /enhance command - Enhance image quality
app.command('/enhance', async ({ command, ack, respond }) => {
await ack();
const imageUrl = command.text.trim();
if (!imageUrl) {
await respond('Please provide an image URL: `/enhance https://example.com/image.jpg`');
return;
}
await respond('Processing your image...');
try {
const result = await processImage('image-enhance', imageUrl);
await respond({
blocks: [
{
type: 'section',
text: { type: 'mrkdwn', text: '*Enhanced Image*' },
},
{
type: 'image',
image_url: result.outputUrl,
alt_text: 'Enhanced image',
},
{
type: 'context',
elements: [{ type: 'mrkdwn', text: `Credits used: ${result.creditsUsed}` }],
},
],
});
} catch (error) {
await respond(`Error: ${error.message}`);
}
});
// /removebg command - Remove background
app.command('/removebg', async ({ command, ack, respond }) => {
await ack();
const imageUrl = command.text.trim();
if (!imageUrl) {
await respond('Please provide an image URL: `/removebg https://example.com/image.jpg`');
return;
}
await respond('Removing background...');
try {
const result = await processImage('background-remove', imageUrl);
await respond({
blocks: [
{
type: 'section',
text: { type: 'mrkdwn', text: '*Background Removed*' },
},
{
type: 'image',
image_url: result.outputUrl,
alt_text: 'Image with background removed',
},
],
});
} catch (error) {
await respond(`Error: ${error.message}`);
}
});
// /cartoon command - Cartoon transformation
app.command('/cartoon', async ({ command, ack, respond }) => {
await ack();
const parts = command.text.trim().split(' ');
const imageUrl = parts[0];
const style = parts[1] || 'pixar';
if (!imageUrl) {
await respond('Usage: `/cartoon https://example.com/image.jpg [style]`\nStyles: pixar, anime, disney, ghibli, comic');
return;
}
await respond(`Converting to ${style} style...`);
try {
const result = await processImage('cartoon', imageUrl, { style });
await respond({
blocks: [
{
type: 'section',
text: { type: 'mrkdwn', text: `*Cartoon (${style})*` },
},
{
type: 'image',
image_url: result.outputUrl,
alt_text: 'Cartoon image',
},
],
});
} catch (error) {
await respond(`Error: ${error.message}`);
}
});
// /upscale command - Upscale image
app.command('/upscale', async ({ command, ack, respond }) => {
await ack();
const parts = command.text.trim().split(' ');
const imageUrl = parts[0];
const scale = parseInt(parts[1]) || 2;
if (!imageUrl) {
await respond('Usage: `/upscale https://example.com/image.jpg [2|4]`');
return;
}
await respond(`Upscaling ${scale}x...`);
try {
const result = await processImage('upscale', imageUrl, { scale });
await respond({
blocks: [
{
type: 'section',
text: { type: 'mrkdwn', text: `*Upscaled ${scale}x*` },
},
{
type: 'image',
image_url: result.outputUrl,
alt_text: 'Upscaled image',
},
],
});
} catch (error) {
await respond(`Error: ${error.message}`);
}
});
// Handle file uploads
app.event('message', async ({ event, client }) => {
if (event.files && event.files.length > 0 && event.text?.includes('@butterflybot')) {
const file = event.files[0];
if (!file.mimetype?.startsWith('image/')) return;
// Determine action from message
let api = 'image-enhance';
if (event.text.includes('cartoon')) api = 'cartoon';
if (event.text.includes('background') || event.text.includes('removebg')) api = 'background-remove';
if (event.text.includes('upscale')) api = 'upscale';
try {
const result = await processImage(api, file.url_private_download);
await client.chat.postMessage({
channel: event.channel,
thread_ts: event.ts,
text: 'Here\'s your processed image!',
blocks: [
{
type: 'image',
image_url: result.outputUrl,
alt_text: 'Processed image',
},
],
});
} catch (error) {
await client.chat.postMessage({
channel: event.channel,
thread_ts: event.ts,
text: `Error processing image: ${error.message}`,
});
}
}
});
(async () => {
await app.start(3000);
console.log('Slack bot is running!');
})();Need help with your Slack bot?