
greenur backend
Backend for greenur
Repository Info
About This Server
Backend for greenur
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Greenur Botanist AI Voice Service
This backend provides a microservice (MCP) for the Greenur app's Botanist AI assistant, enabling real-time communication through WebSockets. It handles audio processing, speech-to-text, language model processing, and text-to-speech capabilities.
Architecture
The service functions as follows:
- Acts as a WebSocket server for real-time bidirectional communication
- Provides REST API endpoints for non-WebSocket clients
- Processes audio data from clients using Google Speech-to-Text
- Sends transcribed text to language models (OpenAI or Gemini)
- Converts AI text responses to speech using Google Text-to-Speech
- Streams all responses back to the client in real-time via WebSockets
Prerequisites
- OpenAI API key (or Gemini API key)
- Google Cloud service account with Speech-to-Text and Text-to-Speech API access
- Render account for deployment
Security
All API endpoints and WebSocket connections are protected with API key authentication. You must include the secret API key with every request:
- For REST API calls: Include the API key in the
X-API-Keyheader or as anapi_keyquery parameter - For WebSocket connections: Include the API key as an
api_keyquery parameter in the WebSocket URL
Deploying to Render
Option 1: Deploying via Render Dashboard
- Login to the Render dashboard
- Create a new Web Service
- Connect your GitHub repository
- Configure the service:
- Name:
greenur-botanist - Build Command:
npm install - Start Command:
./start.sh
- Name:
- Add the following environment variables:
OPENAI_API_KEY: Your OpenAI API key- (Optional)
GEMINI_API_KEY: Your Gemini API key if using Gemini instead of OpenAI GOOGLE_CREDENTIALS_JSON: The entire JSON content of your Google Cloud service account key fileLOG_LEVEL: Set toinfo(ordebugfor troubleshooting)API_SECRET_KEY: A strong secret key for API authentication
- Deploy the service
Option 2: Using Render CLI
If using the Render CLI:
render create
Follow the interactive prompts to set up your service, making sure to include all the necessary environment variables.
API Documentation
Authentication
All API endpoints and WebSocket connections require authentication. Include your API key in one of the following ways:
-
REST API:
- Header:
X-API-Key: your_api_key_here - Query parameter:
?api_key=your_api_key_here
- Header:
-
WebSocket:
- Connect to:
wss://your-render-app.onrender.com?api_key=your_api_key_here
- Connect to:
WebSocket API
Connect to the WebSocket endpoint at wss://your-render-app.onrender.com?api_key=your_api_key_here
Messages from Client to Server:
-
Configuration Message
{ "type": "config", "modelId": "gpt-4o", "audioSession": true } -
Text Message
{ "type": "chat_message", "message": "How do I care for a peace lily?" } -
Audio Message
{ "type": "audio_data", "audio": "base64EncodedAudioData", "format": "base64" }
Messages from Server to Client:
-
Connection Confirmation
{ "type": "connected", "connectionId": "uuid" } -
Text Response
{ "type": "bot_message", "id": "uuid", "text": "Peace lilies prefer indirect light and moist soil..." } -
Audio Response
{ "type": "audio_message", "id": "uuid", "audio": "base64EncodedAudioData", "format": "mp3" } -
Transcription
{ "type": "transcript", "text": "How do I care for a peace lily?" } -
Error
{ "type": "error", "error": "Error message" }
REST API
The following REST endpoints are available:
-
Health Check
GET /api/health- Returns server health status
- No authentication required
-
Chat
POST /api/chat- Authentication required
- Request body:
{ "message": "How do I care for a peace lily?", "sessionId": "optional-session-id", "modelId": "optional-model-id" } - Response:
{ "sessionId": "uuid", "message": "Peace lilies prefer indirect light and moist soil..." }
Updating the Frontend Configuration
Update your frontend configuration to use the WebSocket URL provided by Render:
// In src/services/botanistService.ts
const apiKey = "your_api_key_here";
const wsUrl = `${import.meta.env.VITE_BOTANIST_WS_URL || 'wss://your-render-app.onrender.com'}?api_key=${apiKey}`;
const apiUrl = import.meta.env.VITE_BOTANIST_API_URL || 'https://your-render-app.onrender.com/api';
// For API calls
const headers = {
'Content-Type': 'application/json',
'X-API-Key': apiKey
};
Monitoring and Logs
- Access the Render dashboard
- Select your deployed application
- Navigate to the "Logs" tab to view real-time logs
- Check the "Metrics" tab to monitor performance
Troubleshooting
If you encounter issues with the deployment:
- Verify that all environment variables are set correctly
- Check the logs for any error messages
- Ensure your Google Cloud service account has the necessary permissions
- Verify that your OpenAI API key is valid
- Make sure you're including the correct API key in all requests
Quick Start
Clone the repository
git clone https://github.com/lucyfuur94/greenur-backendInstall dependencies
cd greenur-backend
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.