OpenAI Slackbot with Node.js
This template provides an AI-powered Slackbot that leverages OpenAI's GPT model to answer questions directly within your Slack workspace. Built with Node.js and deployed using Vercel Functions, this bot offers a seamless way to integrate advanced conversational AI into your team's communication.
Key Features:
- AI-Powered Responses: Utilizes OpenAI's GPT model to provide intelligent and contextually relevant answers to user queries.
- Slack Integration: Designed specifically for Slack, responding to mentions (
app_mention) and monitoring channel creation (channel_created). - Serverless Architecture: Deployed on Vercel Functions, ensuring scalability, cost-efficiency, and ease of management without traditional server overhead.
- Node.js Backend: Built with Node.js, offering a robust and familiar environment for development.
Use Cases:
- Internal Knowledge Base: Quickly answer common questions for team members by querying an AI model.
- Automated Support: Provide instant responses to routine inquiries, freeing up human agents.
- Team Productivity: Enhance collaboration by making information readily accessible through a conversational interface.
- Developer Tooling: A practical example for integrating AI services and building serverless applications.
Setup and Deployment:
To get started, you'll need to configure several environment variables:
Environment Variables:
OPENAI_API_KEY: Obtain this from your OpenAI API Keys page.SLACK_BOT_TOKEN: Acquired from the Slack API Apps Page after creating an app, installing it to your workspace, and copying the Bot User OAuth Token from the OAuth & Permissions section.SLACK_SIGNING_SECRET: Found under Basic Information -> App Credentials on your Slack API Apps Page.SLACK_ADMIN_MEMBER_ID: Your Slack member ID, which can be copied from your Slack profile.
These variables should be added to your Vercel project settings for deployment and to a local .env file for local testing.
Enable Slack Events:
After deploying your application to Vercel, you must configure Slack to send events to your bot:
- Go to the Slack API Apps Page and select your bot.
- Navigate to Event Subscriptions and enable events.
- Set the Request URL to
https://<your-vercel-app>.vercel.app/api/events. Ensure this URL is verified by Slack. - Subscribe to the
app_mentionandchannel_createdbot events. - Save changes and reinstall the app to your workspace.
Local Development:
For local testing, you can use the Vercel CLI and localtunnel:
pnpm i -g vercel
pnpm vercel dev --listen 3000 --yesIn a separate terminal:
npx localtunnel --port 3000Remember to update the Slack Event Subscription URL to your localtunnel URL during local development.





