Creating an Alexa Game: Content Management with Sanity.io

A Headless CMS for you Game Content

Overview

The best way to modify your game content is to put it into a Content Management System (CMS). That way changes to the content can happen without the need to recompile the content in code. You could put the content into a database or someplace else, but a CMS is special-built for this purpose.

There are a number of CMS solutions available. One category is called a “headless” CMS to make it clear that the content is not tied to a specific output such as a website. With a “headless” CMS, you access content through an API and the same content can be used on web, mobile, voice and others.

Finding Sanity

It had been many months since I had surveyed the CMS landscape and while I was looking around, I found the Sanity CMS and decided to give it a try. I was not disappointed.

Sanity has a free Standard plan with the following quotas:

I was confident that the game’s usage would fit into that plan.

Once you create an account and project through the website, you are ready to get started defining your content types and creating a project website where you can modify the content.

In Sanity, you do this by creating a React.js website. This was the first time that I had used React.js, but much of the heavy lifting is done for you when you use Sanity Studio. This open-source single page application defines the UI for you based on content definition files. We’ll look at an example later in the article.

Sanity Studio

Content in Sanity can be defined as a document, object, array, or other types such as boolean, text, string, date, and number. A document is a special type as the Sanity Studio UI will show a top level list for all documents.

Each document gets a generated editor based on the types configured for the document:

Content Model for Number Spies

The content in your game will determine which documents you need to define in Sanity. For Number Spies, there are secret message transmissions encoded with a One Time Pad (OTP) that are worth points when a verify code is redeemed in the voice app. There are missions to go on and trips that you can take to different cities.

Here is the content model for Number Spies:

  • announcement — a message that the player hears when starting the Number Spies Alexa Skill.
  • definition — the definition of a spy term.
  • city — a location you can visit in the game.
  • mission — a mission that you can complete.
  • post — additional information in a spy blog.
  • verifyCode — a series of 5 digits that can be redeemed during a date range.
  • oneTimePad — a list of random digits used to encode/decode a message.
  • transmission — a message that is encoded and available for transmission on a numbers station on a given date.
  • trip — a response when visiting a specified city on a given date.
  • points — the point value of XP, currency, and other values that you can earn or lose.
  • textReplacements — missions and trips have a message with placeholders. Think of Mad Libs. The key and values in this object allow for variability in responses.
  • blockContent — allows text field to add formatting such as text size, bullet lists, URL, and images.

Content Definitions

Points Object

Here is an example of an object:

The definition for a Points object is straightforward.

  • Lines 2–4: defines the points as an object with the UI title
  • Lines 5–34: This object has an array of 4 fields, each is a number
  • Lines 7–11: An example of the XP field definition including UI info and validation.

The points show in the UI as follows:

Mission Document

Here is the definition for the mission document that includes a points object.

  • Lines 4–7: defines the mission as an document with the UI title and icon
  • Lines 8–16: initial values for the fields
  • Lines 17–43: the field definitions
  • Lines 44–58: how the mission will look in Sanity Studio in the list of documents.

The fields for level and response are simple data types whereas textReplacements and points are objects I defined.

Conclusion

Being able to quickly update your game’s content is a big benefit of a Content Management System. I found Sanity to be a great tool for Number Spies.

What content does your game need?

What CMS are you using and what do you like about it?

Creating an Alexa Game — Table of Contents

  • Intro — From Idea to Code and Beyond
  • The Spark of Inspiration for Number Spies
  • Number Spies — System Components Overview
  • Content Management with Sanity.io (this post)
  • Number Spies Alexa Flash Briefing
  • Number Spies Alexa Skill — Language Model
  • Number Spies Alexa Skill — Why I Chose the Jovo Framework
  • Number Spies Alexa Skill — Text-to-Speech and Speech Markdown
  • Website Domain Name and Skill Invocation Name
  • Number Spies Alexa Skill — Code (multiple parts)
  • Number Spies Alexa Skill — Unit Testing with Bespoken
  • Number Spies Alexa Skill — Skill Store Info
  • Number Spies Alexa Skill — Analytics with Dashbot
  • Number Spies Alexa Skill — Exception Monitoring with Sentry
  • Number Spies Alexa Skill — User Acquisition with Voxalyze Then Not
  • Number Spies Website
  • Game Promotion & Social Media
  • Is the Game a Success?

Alexa Champion 🏆, Bixby Premier Developer, Software Architect, Speaker 🎙️, Author

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store