This Go application listens to new user messages and poll updates in Firestore, processes them in real-time, and responds with AI-generated messages using the Gemini model from Google AI. It also periodically sends status updates to a chat platform based on the current state of polls and conversations.
- Real-time Firestore Integration: Listens for new user messages and processes them immediately.
- AI-Powered Responses: Uses Google AI's Gemini model to generate responses based on the conversation summary.
- Poll Monitoring: Fetches poll status from Firestore and updates the conversation summary.
- Concurrency: Utilizes Go's
sync.WaitGroup
andsync.Mutex
to ensure concurrent processes run safely.
- Go (1.16+)
- Firestore database with proper collections set up.
- Service account credentials with access to your Firestore project.
.env
file with the necessary configuration.- Firebase Admin SDK and Google AI Genkit SDK.
- User Messages: This collection (
gccdpune-user
) stores incoming user messages. - Poll Collection: This collection (
gccdpune-poll
) contains poll questions and options. - Ping Collection: This collection (
gccdpune-go-pings
) stores the AI-generated responses.
Create a .env
file in the root of your project:
# .env
SERVICE_ACCOUNT_PATH=".keys/serviceAccountKey.json"
id
: string (unique identifier)message
: string (user's message)timestamp
: timestamp (message creation time)processed
: boolean (whether the message has been processed)
question
: string (the poll question)options
: map (keyed by option label, containing poll options with their text and voters)
- Clone this repository:
git clone https://github.com/your-username/firestore-ai-poll.git
cd firestore-ai-poll
- Install the necessary Go modules:
go mod tidy
- Run the application:
go run main.go
-
Mark Existing Messages as Processed: The program first scans and marks all existing unprocessed messages in the
gccdpune-user
collection as processed, so that only new messages are handled. -
Listen for New Messages: The program listens for any new user messages and processes them by generating a response using the Gemini AI model.
-
Poll Monitoring: The app periodically checks the status of a poll in Firestore and generates a summary, which is then used to update the conversation summary.
-
AI-Generated Responses: When a new message arrives, the Gemini AI model generates a response, and it is stored in Firestore for display in the chat.
Feel free to fork this repository, create a new branch, and submit pull requests for any improvements or features you'd like to add.
This project is licensed under the MIT License.