SmartyCall is an interactive trivia game that uses Node.js, Couchbase, Twilio Voice and SMS APIs, and the OpenAI API to deliver trivia questions to players via phone calls and SMS. Players can register via SMS, receive trivia questions through phone calls, and get their scores tracked in real-time.
This application was built for the Twilio Hackathon Challenge on devto.
- User registration via SMS
- AI-generated trivia questions using OpenAI API
- Cached trivia questions in Couchbase
- Interactive voice-based gameplay with Twilio Voice
- Score tracking and leaderboard via Couchbase
- Delivery status tracking for SMS messages
- Node.js
- Express.js
- Couchbase
- Twilio Voice and SMS APIs
- OpenAI API
- Node.js and npm installed
- Couchbase Capella account
- Twilio account with a phone number
- OpenAI API key
-
Clone the repository:
git clone https://github.com/hummusonrails/trivia-game.git cd trivia-game
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory with the following content:COUCHBASE_URL=couchbases://cb.<your-endpoint>.cloud.couchbase.com COUCHBASE_USER=your-couchbase-username COUCHBASE_PASSWORD=your-couchbase-password COUCHBASE_BUCKET=your-couchbase-bucket-name COUCHBASE_BUCKET_QUESTIONS=your-couchbase-bucket-questions-name TWILIO_ACCOUNT_SID=your-twilio-account-sid TWILIO_AUTH_TOKEN=your-twilio-auth-token TWILIO_PHONE_NUMBER=your-twilio-phone-number OPENAI_API_KEY=your-openai-api-key SESSION_SECRET=your-session-secret
-
Run the application:
npm run start
-
Expose your local server to the internet: Use ngrok to expose your local server to the internet for Twilio webhooks.
ngrok http 3000
- Send an SMS: Text "JOIN" to your Twilio phone number to register for the game.
- Receive a welcome message: You will receive a welcome message and instructions on how to start the game.
- Text "JOIN" to your Twilio phone number: You will receive a message with the phone number to call to start the game.
- Call the provided number: You will receive a welcome message followed by a trivia question. Each unique question is cached in Couchbase to avoid repeating the same question.
- Answer the trivia question: Respond via voice, and you will receive feedback on whether your answer was correct. Your score will be tracked.
- Text "LEADERBOARD" to your Twilio phone number: You will receive a message with your current score and rank on the leaderboard.
To get detailed delivery status for your messages, set the "Status Callback URL" in your Twilio settings to:
http://<your-ngrok-url>/callback/status
ai-trivia-game/
├── src/
│ ├── controllers/
│ │ ├── voiceController.js
│ │ ├── smsController.js
│ │ ├── callbackController.js
│ ├── services/
│ │ ├── openaiService.js
│ │ ├── twilioService.js
│ │ ├── couchbaseService.js
│ ├── routes/
│ │ ├── voiceRoutes.js
│ │ ├── smsRoutes.js
│ │ ├── callbackRoutes.js
│ ├── config/
│ │ ├── couchbaseConfig.js
│ │ ├── twilioConfig.js
│ │ ├── openaiConfig.js
│ ├── app.js
│ └── server.js
├── .env
├── package.json
├── package-lock.json
└── README.md
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature-name
) - Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature-name
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Please read the CODE_OF_CONDUCT for details on the standards for collaboration within this project.