Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Build an AI-powered Slackbot with Node.js and Vercel Functions that answers questions using OpenAI's GPT model.
This template creates an AI-powered Slackbot built with Node.js and deployed as a serverless function on Vercel, letting users ask questions to OpenAI's GPT model directly from Slack.
This is a boilerplate project that connects Slack to the OpenAI API. It listens for Slack Events API events (app_mention and channel_created) via a serverless endpoint at /api/events, sends the message text to OpenAI, and posts the model's answer back to the Slack channel. It comes from a curated examples repository of robust and scalable application patterns, and requires four environment variables (OPENAI_API_KEY, SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, SLACK_ADMIN_MEMBER_ID) to run locally or on Vercel.
/api/events handles Slack Event Subscriptions and is verified against the SLACK_SIGNING_SECRET.app_mentions:read, channels:history, chat:write, and commands so the bot can read mentions, see channel history, and write messages.https://your-vercel-app.vercel.app/api/events.vercel dev --listen 3000 and exposing a public URL through localtunnel for Slack event delivery.channel_created events to trigger actions when new channels are created.commands scope is already configured)./api/events endpoint.app_mention and channel_created bot events, then reinstall the app.The template needs four variables: OPENAI_API_KEY for the OpenAI API, SLACK_BOT_TOKEN for Slack authentication, SLACK_SIGNING_SECRET to verify incoming requests, and SLACK_ADMIN_MEMBER_ID to identify a specific admin user. All are added in Vercel's environment settings.
In Slack's app configuration, go to OAuth & Permissions, add the bot scopes app_mentions:read, channels:history, chat:write, and commands, then click "Install to Workplace". The OAuth flow returns a Bot User OAuth Token that starts with xoxb-.
After deploying, open your Slack app's Event Subscriptions page, turn on events, and set the Request URL to https://your-vercel-app.vercel.app/api/events. Subscribe to the bot events app_mention and channel_created, save changes, and reinstall the app.
Yes. Install the Vercel CLI, run vercel dev --listen 3000, then use localtunnel to expose that port as a public URL. Update the Slack Request URL to the localtunnel address. Be aware that Slack will verify the URL, so the tunnel must be active while testing.