GPT-trainer Slack Bot is an intelligent Slack bot that connects your team's conversations with the powerful GPT-trainer AI capabilities. It serves as a bridge between your Slack workspace and GPT-trainer, allowing seamless access to AI assistance without leaving your communication platform.
The bot integrates directly with the GPT-trainer API, enabling your team to interact with your custom-trained AI models directly from Slack. It maintains conversation context through sessions, allowing for natural, multi-turn interactions.
- Seamless Slack Integration: Fully integrated with Slack's messaging platform
- Custom AI Responses: Leverages your GPT-trainer chatbots for domain-specific knowledge
- Persistent Sessions: Maintains conversation context for coherent multi-turn interactions
- Thread Support: Works in threads for organized conversations
- Direct Message Support: Available in DMs for private assistance
- Mention Support: Can be mentioned in channels to provide assistance
- Error Handling: Robust error handling and recovery
- Logging: Comprehensive logging for monitoring and debugging
- Streaming Support: Uses GPT-trainer's streaming API for faster responses
- Fallback Mechanisms: Gracefully handles API errors with informative messages
GPT-trainer Slack Bot is built with a modular architecture that separates concerns and allows for easy extension:
- Slack Integration Layer: Handles all communication with the Slack API
- GPT-trainer API Client: Manages connections to the GPT-trainer service
- Supports both streaming and non-streaming endpoints
- Implements fallback mechanisms for API errors
- Handles session creation and message sending
- Session Management: Maintains user sessions for conversation continuity
- Maps Slack user IDs to GPT-trainer session UUIDs
- Handles session cleanup for inactive conversations
- Configuration Layer: Provides flexible configuration options
- Environment-based configuration
- Constants for application-wide settings
- Node.js 16+ installed
- npm 7+ installed
- Slack workspace with admin access
- GPT-trainer API key and chatbot UUID
-
Clone the repository:
git clone https://github.com/v4lheru/GPT-Trainer-Slack-Bot.git cd GPT-Trainer-Slack-Bot -
Install dependencies:
npm install
-
Create a
.envfile with the required environment variables (see.env.examplefor reference):# Node environment NODE_ENV=development PORT=3000 # Slack configuration SLACK_BOT_TOKEN=xoxb-your-bot-token SLACK_SIGNING_SECRET=your-signing-secret SLACK_APP_TOKEN=xapp-your-app-token # GPT-trainer configuration GPT_TRAINER_API_KEY=your-gpt-trainer-api-key GPT_TRAINER_CHATBOT_UUID=your-chatbot-uuid GPT_TRAINER_API_URL=https://app.gpt-trainer.com # Application configuration LOG_LEVEL=info SESSION_CLEANUP_INTERVAL=3600000
npm run devThis will start the bot in development mode with hot reloading.
npm run build
npm startThis will build the TypeScript code and start the bot in production mode.
This project includes configuration files for deploying on Railway:
railway.json- Configuration for Railway deploymentProcfile- Process file for Railway
To deploy on Railway:
- Push your code to a GitHub repository
- Create a new project on Railway from the GitHub repository
- Set up the environment variables in the Railway dashboard
- Deploy the project
/
├── src/
│ ├── config/ # Configuration management
│ │ ├── constants.ts # Application constants
│ │ └── environment.ts # Environment variables
│ ├── api/ # API client definitions
│ │ ├── slack.ts # Slack API client
│ │ └── gpt-trainer.ts # GPT-trainer API client
│ ├── services/ # Business logic
│ │ └── session.ts # Session management service
│ ├── types/ # TypeScript interfaces and types
│ │ ├── slack.ts # Slack types
│ │ └── gpt-trainer.ts # GPT-trainer types
│ ├── utils/ # Utility functions
│ │ ├── logger.ts # Logging utility
│ │ └── error-handler.ts # Error handling
│ ├── slack/ # Slack integration
│ │ ├── app.ts # Slack app configuration
│ │ └── events/ # Event handlers
│ └── index.ts # Application entry point
├── tsconfig.json # TypeScript configuration
├── package.json # Dependencies and scripts
└── .env.example # Environment variable template
Once deployed, you can interact with GPT-trainer Slack Bot in several ways:
- Direct Messages: Send a DM to the bot for private conversations
- Mentions: Mention the bot in a channel using
@GPT-trainer - Threads: The bot can participate in conversation threads
Example interactions:
@GPT-trainer What is the company policy on remote work?@GPT-trainer Can you explain how our product works?@GPT-trainer Help me draft an email to a client
The bot will maintain context throughout the conversation, allowing for natural follow-up questions and multi-turn interactions.
The bot integrates with the GPT-trainer API using the following endpoints:
-
Create Session:
https://app.gpt-trainer.com/api/v1/chatbot/{chatbot_uuid}/session/create- Creates a new session for a user
- Returns a session UUID for subsequent messages
-
Send Message (Streaming):
https://app.gpt-trainer.com/api/v1/session/{session_uuid}/message/stream- Sends a user message to the GPT-trainer API
- Returns the AI response as a string
The integration includes robust error handling and fallback mechanisms to ensure reliable operation even when API issues occur.
GPT-trainer Slack Bot is designed to be extensible. You can:
- Customize Response Formatting: Modify how responses are presented in Slack
- Add New Features: Implement additional functionality as needed
- Integrate with Other Services: Connect to other APIs or services
- Enhance Session Management: Implement database storage for persistent sessions
If you encounter issues with the GPT-trainer API integration:
- Check API Credentials: Ensure your API key and chatbot UUID are correct
- Verify API Endpoints: The bot uses the streaming endpoint by default
- Check Logs: Examine the logs for detailed error information
- Test API Directly: Use the included test script (
test-gpt-trainer.js) to test the API directly
Contributions are welcome! Please feel free to submit a Pull Request.
MIT