Inspiration
The rules of the social deduction game Mafia are simple: people are secretly assigned a role (villager, mafia, doctor, detective, etc.). The mafia chooses someone to eliminate each round, the doctor can save the person, and the detective can inspect a person. Everyone talks together to try and eliminate the real Mafia! Mafia is a classic and beloved game where the core of the game is about people whispering, shouting, defending, and accusing each other.
Many online versions of Mafia simply put it in an app, which we believe loses some aspect of the human connection and FUN in the game! We decided to create Mafia, fully integrated into messages! Friends can play Mafia together simply in their message group chat, having lots of fun. messageMAFIA uses AI story narration, roles and actions managed through the DMS, polls for voting, immersive message effects, and more!
What it does
A host can start the game in a group chat, adding their friends and the messageMAFIA's number. Everyone else who wants to play will text in the chat. The, the host sends a message to start the game. Each player's role shows up as a private DM with iMessage's invisible ink effect on it, where you swipe to reveal it. The roles we included were a normal villager, the mafia, doctor, and detective.
At night, anyone with a job gets a DM from the bot. Mafia, doctor, detective, where they will reply with a name. The players don't have to be precise ("kill sam i guess" works) because we pass the reply to Claude Haiku to work out who the player meant. It also tells the difference between an answer and a question, so if they text back "wait who's still alive?", they get an answer instead of accidentally banishing someone.
At dawn, the bot posts what happened in the group chat. It's written fresh each time by an AI narrator that remembers this particular game, so a death in round three can reference something from round one. The stories are all very creative and interesting!
Then everyone talks, discussing who they think the mafia is, chatting in the group.
Voting is a real iMessage poll with every living player as an option. Players tap the name who they think is the Mafia. The tally resolves once everyone's voted. Then the person voted out is revealed to either be the Mafia or not. This repeats until the mafia are gone or they've taken over.
How we built it
Node and Express on the server side, Supabase for state, Linq's iMessage API for anything that touches a phone, and Claude doing two separate jobs.
The core is a state machine. Every player is dead or alive, has a role, and either has or hasn't acted this round. The server holds nothing in memory between requests. A webhook comes in, we pull the current game state out of Supabase, work out what that message or vote means, write the result back, and send whatever needs sending. That makes the whole thing effectively serverless. Any instance can handle any event, and a crash or a restart doesn't lose a game.
Voting is a real iMessage poll rather than something we drew ourselves. When we create the poll we store which option ID belongs to which player, then listen for poll.vote.added and poll.vote.removed to keep the tally live.
The narrator is Claude Opus. What makes it feel continuous isn't a summary we generate between rounds. We pass it the actual prior messages from that game as conversation history, so it's continuing its own story rather than being briefed on it each round. Claude Haiku does the other job, turning a casual DM like "kill sam i guess" into a specific target.
None of this is Mafia-specific. Roles, phases, private actions, public votes is the shape of most text-based social games. Swapping in Spyfall or a whodunnit means new role definitions and new prompts, not a whole new architecture, so it is very versatile.
Accomplishments that we're proud of
Making full game running start to finish entirely over text, on real phones, with real people. Lobby, secret roles, night actions, an AI-written dawn, a live poll, a tied vote, a resolved vote, a win. The murder mystery also remembers itself! The AI narrator gets the actual history of that specific game, so it can call back to something that happened rounds earlier. Two games with the same five people read completely differently, because no two sets of roles and deaths are the same.
What's next for messageMAFIA
More roles. Jester, vigilante, traitors, bodyguards, and so much more!
More of what iMessage can do using Linq: voice-note narration, images for deaths and action, screen effects, backgrounds, stickers, and more!
Bigger games and longer stories, with roles that unlock as the player count grows.
Also, other games entirely. The message-based architecture is not Mafia-specific, roles, phases, private actions and public votes describe many other games. Other games could be Dungeons and Dragons, Spyfall, or even games that implement location spending in text like Class Assasin or something like PokemonGo with friends.
Built With
- express.js
- linq
- supabase
- typescript
Log in or sign up for Devpost to join the conversation.