# Zulip Bot Service This is a Zulip bot service that provides AI-powered responses to user queries. ## Running as a Service with PM2 The application can be set up to run as a background service using PM2, which ensures it starts automatically on system boot and restarts if it crashes. ### Prerequisites 1. Node.js and npm installed on your system 2. PM2 installed globally (`npm install -g pm2`) 3. Python 3.11+ and required dependencies ### Installation 1. Make sure all required environment variables are set in your `.env` file: ``` ZULIP_BOT_EMAIL=your-bot@example.com ZULIP_BOT_API_KEY=your-api-key ZULIP_SITE=https://your-zulip-instance.com OPENAI_API_KEY=your-openai-api-key ``` 2. Make the setup script executable: ```bash chmod +x pm2_start.sh ``` 3. Run the setup script: ```bash ./pm2_start.sh ``` 4. The script will: - Install PM2 if not already installed - Start the bot as a background service - Configure PM2 to run at system startup - Provide instructions for any required sudo commands ### Managing the Service - **Check status**: `pm2 status` - **View logs**: `pm2 logs zulip-bot` - **Restart**: `pm2 restart zulip-bot` - **Stop**: `pm2 stop zulip-bot` - **Start (if stopped)**: `pm2 start zulip-bot` ### Troubleshooting If the service fails to start: 1. Check logs for errors: `pm2 logs zulip-bot` 2. Ensure all environment variables are properly set 3. Verify that the Flask app works by running it directly: `./run_app.sh` ## Manual Setup If you prefer to run the bot without PM2: 1. Activate the virtual environment: ```bash source venv/bin/activate ``` 2. Run the Flask app: ```bash ./run_app.sh ``` ## Development For development purposes, you can run the Flask app in debug mode: ```bash export FLASK_APP=app export FLASK_DEBUG=1 flask run --port=5100 ```