Twilio Challenge: SmartyCall - AI Powered Competitive Trivia

Ben Greenberg - Jun 18 - - Dev Community

This is a submission for the Twilio Challenge

What I Built

SmartyCall is an interactive trivia game that utilizes Twilio's Voice and SMS APIs, OpenAI's language model, and Couchbase for data storage. This application allows users to register via SMS, receive trivia questions through voice calls, and respond either via voice or text. The game maintains a leaderboard to track scores and rankings, providing a competitive edge to the trivia challenges.

System Architecture

Key Components:

  • Twilio Voice API: Handles the voice interactions, asking trivia questions and accepting verbal responses along with feedback on whether the answer was correct or not.
  • Twilio SMS API: Manages user registrations and sends updates or notifications about scores and game status.
  • OpenAI API: Generates trivia questions and processes user responses to determine correctness.
  • Couchbase Capella: Stores user data, game scores and questions are cached for uniqueness checks.

Data Flow:

  • Users register via SMS and are stored in the Couchbase database.
  • Users initiate the game via a voice call, where they receive questions generated by OpenAI.
  • All questions are cached in Couchbase and the cache is used to check for uniqueness.
  • Answers are processed and validated through OpenAI, and scores are updated in Couchbase.

Backend Setup:

  • The Node.js application serves as the backend, handling API requests and responses.
  • Express.js is used for routing, managing different endpoints for SMS and voice interactions.

Demo

Twilio and AI

In "SmartyCall," Twilio's APIs play a crucial role. The Voice API is used to deliver trivia questions to players and collect their responses through natural voice inputs. The SMS API manages user registrations and sends text updates about scores and game progress. The integration with OpenAI’s GPT-4o allows the game to generate trivia questions dynamically and evaluate responses, adding a layer of intelligence and interaction that enhances user engagement.

Source Code

You can find the source code for the game on GitHub. Feel free to clone it and modify it according to whatever you would like to build!

GitHub logo hummusonrails / trivia-game

AI Powered Competitive Trivia

SmartyCall: An AI Trivia Game

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.

Features

  • 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

Technologies Used

Prerequisites

  • Node.js and npm installed
  • Couchbase Capella account
  • Twilio account with a phone number
  • OpenAI API key

Installation

  1. Clone the repository:

    git clone https://github.com/hummusonrails/trivia-game.git
    cd trivia-game
    Enter fullscreen mode Exit fullscreen mode
  2. Install dependencies:

    npm install
    Enter fullscreen mode Exit fullscreen mode
  3. Set up environment variables:

    Create a .env file in…

Additional Prize Categories

SmartyCall qualifies for the following additional prize categories in the Twilio Hackathon:

  • Twilio Times Two: This category is met as the project uses both Twilio's Voice and SMS APIs.
  • Entertaining Endeavors: The application provides an entertaining way for users to engage with trivia, making learning fun and interactive.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .