Twilio Challenge: SmartyCall - AI Powered Competitive Trivia
Tags: devchallenge, twiliochallenge, ai, twilio
Published: 2024-06-18 19:59:42

---
title: Twilio Challenge: SmartyCall - AI Powered Competitive Trivia
published: true
tags: devchallenge, twiliochallenge, ai, twilio
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pj2wbro9ulfbbc775obs.png
canonical_url: https://www.bengreenberg.dev/blog/blog_twilio-challenge:-smartycall---ai-powered-competitive-trivia_1718668800000
---

*This is a submission for the [Twilio Challenge ](https://dev.to/challenges/twilio)*

## 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](https://openai.com): Generates trivia questions and processes user responses to determine correctness.
* [Couchbase Capella](https://cloud.couchbase.com): 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
 {% youtube PvueyYpYCp0 %}

## 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 https://github.com/hummusonrails/trivia-game %}

## 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.