How to Build a Role-Playing Game with Vonage AI Studio and Notion
Published on January 24, 2024

From Playing RPGs to to Building Vonage's Gate

When I was younger, some of my playtime was filled with hand-me-down video games – absolute gems in their own right, but ones that I admittedly spent a little too much time with, often earning a scolding or two. I enjoyed a variety of games, from social simulations and platform games to first-person shooters to my personal favorite, role-playing games (RPG). Unbeknownst to my younger self, each hour spent in these fantasy worlds was subtly honing my problem-solving skills and creativity. Fast forward, and those very gaming adventures laid the groundwork for this blog.

Last year, Larian Studios published Baldur's Gate 3, an RPG based on the tabletop game Dungeon & Dragons. Think of an RPG as diving into a book where, instead of just reading the story, you get to be the main character. You'll navigate through adventures, make decisions, interact with other characters, and shape the story's outcome based on your choices. It's a chance to experience a narrative in a hands-on way, where the world reacts to what you decide.

I played the game myself and was thoroughly impressed by how unique yet engaging each player's experience was since it followed a "choose your own adventure" style. I then felt compelled to recreate a simpler version of an RPG using Vonage AI Studio and Messages API - Vonage's Gate!

Creating an RPG with Messages

Here is how we will create a storytelling experience where players decide their character's fate. Now, channel your main character energy, and let's get building!

Prerequisites

Database and Game Setup

As best practice, we will store all the values used in the gameplay in a database - for this sample, we'll be using Notion!

How to Use Notion as a Database

It is a user-friendly choice, doesn't require advanced database knowledge, and is super handy because changes show up instantly - perfect for keeping our content fresh and responsive. Although it's less scalable than traditional databases, it can handle everything we need for this app. The best part is that it easily integrates with Vonage AI Studio and other low-code platforms, making our lives a whole lot easier!

Create your spreadsheet

Go to Notion. Click the (+) button to add a page. On the new page under DATABASE, click 'Table'. Create the following columns:

  • ID (type: number) - the ID of the message is sent over MMS

  • Message (type: title) - the actual text sent

  • Option1 (type: number) - the response a player sends when choosing option 1

  • Option2 (type: number) - the response a player sends when choosing option 2

  • Option3 (type: number) - the response a player sends when choosing option 3

  • NextID1 (type: number) - the ID of the next message the player receives after choosing option 1

  • NextID2 (type: number) - the ID of the next message the player receives after choosing option 2

  • NextID3 (type: number) - the ID of the next message the player receives after choosing option 3

How to Structure Your Game

You can customize the storyline however you would like. In my story, the player ends up with the artifact. Texts sent to the player are triggered by their responses to the previous message. You can even use this sample game's data from my GitHub repo.

Character Creation

  • Initial message: Send a brief introduction and a simple choice for character creation.

In my database, you can see that ID 1 shows the initial message: "Welcome to Vonage's Gate! Choose a class: (1) Warrior, (2) Mage, or (3) Rogue."

  • Character confirmation: Once they reply with a choice, send a confirmation with a brief character description.

Game progression

Immediately after character confirmation, present the first simple scenario that requires a decision. When the player makes a choice, respond with a brief outcome and another decision point. Continue with a series of simple decision points that keep the story moving without requiring complex interactions. For this demo, we will have players respond with single-character messages. After a few rounds of decisions, we can conclude the demo with a simple ending.

The image shows a screenshot of a database table titled "Vonage's Gate Database - Script." The table has several columns: "ID," "Message," "Option1," "Option2," "Option3," "NextID1," "NextID2," and "NextID3." Each row corresponds to a part of a script for a messaging game, with the "Message" column containing a snippet of the text sent to players, and the "Option" columns indicating the numeric response a player can send. The "NextID" columns point to the ID of the next message in the sequence based on the player's choice. The first row, for example, reads "Welcome to V..." with options 1, 2, and 3 leading to different "NextID" outcomes.Database Setup

Enabling the Notion API for Data Access and Integration with Vonage AI Studio

Now comes the fun part! With Vonage AI Studio's easy-to-use interface, you can design your chatbot's conversational flow. It's a drag-and-drop setup, meaning you don't need coding skills to get going. You can add different dialog nodes and define responses.

Our flow should look like this:

The image shows a flowchart for a conversational application, likely in a visual programming environment. It begins with a "Start" node, followed by a "Set Starting Parameter" node that sets a parameter to 1. Next is a "Webhook" node with outcomes for "2XX" (successful response) and "Failed" connected to a "Collect Input" node for text input. There are "Conditions" nodes with options 1, 2, 3, and a check for "Not End," which lead to corresponding "Set Parameter" nodes (1, 2, and 3) that presumably update the query parameter with new values. The flow includes "Exit Points" for when the query ID is not 0 or equals 0, leading to the "End Game" message node, which sends a thank you message, and finally to an "End Conversation" node, which likely signifies the end of the conversation flow.Conversation Flow

First, set up Vonage AI Studio.

Next, we will be make nodes and properties to connect to each other for the conversation flow. You can also download the zip file of this sample and Import Agent on Vonage AI Studio. If you would like to build this from scratch, here are the nodes we will need to create and which nodes and properties we need to connect them to:

Properties > Parameters

Property name: Set Start Parameter

Create a parameter called QUERY_PARAMETER and set it to 1 since our first ID starts at 1.

Connection(s): START (left) and $QUERY_PARAMATER = 1 to Webhook

The image shows a table with two columns labeled "# ID" and "Aa Message." The first row under "# ID" shows the number 1, and adjacent to it under "Aa Message," the text reads "Welcome to Vonage's Gate! Choose a class: (1) Warrior, (2) Mage, or (3) Rogue." This appears to be a snippet from a database used in an interactive text-based game, where the player is prompted to choose a character class at the beginning of the game.Set Start Parameter

NODES > Integrations > Webhook

Node name: Webhook

Method: POST Request URL: https://api.notion.com/v1/databases/<databaseid>/query

To find a database ID, navigate to the database URL in your Notion workspace. The ID is the string of characters in the URL that is between the slash following the workspace name (if applicable) and the question mark. The ID is a 32-character alphanumeric string.

Headers (HTTP Header : Value)

  • Authorization : Bearer $NOTION_ACCESS_TOKEN

  • Notion-Version : 2022-06-28

To find your $NOTION_ACCESS_TOKEN, go through the Authorization process for an internal integration on Notion.

Body

Put the following text in the body:

{
 "filter": {
  "property": "ID",
  "unique_id": {
   "equals": $QUERY_PARAMETER
  }
 }
}

Response Mapping

  • Response type: JSON Object path

After filling out the above information in our webhook node, make sure the webhook is working by clicking the 'Test request' button in the top right. Under Response, you'll see that it returns all the data from our Notion table. Using the response, define the object path and map it to a parameter. If you need help, check out my blog that [dives deeper into response mapping](LINK TO MY BLOG).

Connection(s): 2xx to Collect Input

The image displays a section of a user interface titled "Response Mapping" for a software application, likely related to API or database interaction. It shows a configuration setup for handling JSON responses, with mappings from object paths in the JSON structure to named parameters. For example, "results[0].properties.Message.title[0].plain_text" is mapped to the parameter "$RETURNED_MESSAGE," and similar mappings are made for "Option1," "Option2," "Option3," "NextID1," "NextID2," and "NextID3," each pointing to their respective returned parameters. This setup is used to extract specific pieces of data from a JSON response and assign them to variables within the application  The image shows a graphical user interface for mapping JSON response data to specific parameters within a software application. It lists various JSON object paths such as "results[0].properties.Message.title[0].plain_text" and corresponding parameters like "$RETURNED_MESSAGE". The mapping is designed to translate the structured JSON data into variables that the application can use in its operations.Response Mapping

NODES > Conversation > Collect Input

Node name: Collect Input

Parameter: INPUT

Text Prompt: $RETURNED_MESSAGE (you made need to type this out instead of copy & pasting this text)

Expected input: Text

Connection(s): Text to Conditions

The image displays a section of a user interface for a "Collect Input" node within a chatbot or automated messaging system. It has a field marked "Parameter" with "INPUT" entered in a text box, outlined in red, indicating the parameter that will be used to store the input collected. Below that, under "Message," there is an option for "Text" selected, and a text box labeled "Prompt" contains a placeholder variable "$RETURNED_MESSAGE" within it, also outlined in red. This setup suggests that the system is configured to prompt the user for input and store their response in the "INPUT" parameter.Collect Input

Nodes > Conversation > Conditions

Node name: Conditions

Condition Name(s):

  • Option 1

    * Parameter: INPUT
    * Operation: Is equal to
    * Value: $RETURNED_OPTION1
  • Option 2

    * Parameter: INPUT
    * Operation: Is equal to
    * Value: $RETURNED_OPTION2
  • Option 3

    * Parameter: INPUT
    * Operation: Is equal to
    * Value: $RETURNED_OPTION3
  • Not End

    * Parameter: RETURNED_ID
    * Operation: Is equal to
    * Value: 9
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 11
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 12
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 15
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 16
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 18
    
    	_or_
    
    * Parameter: RETURNED_ID
    * Operation: Is not equal to
    * Value: 19

Connection(s):

- Option 1 to Set Parameter 1

- Option 2 to Set Parameter 2

- Option 3 to Set Parameter 3

The image shows a part of a software interface under the "NODES" menu, specifically within the "Conversation" section. There are different node options listed: "Classification," "Collect Input," and "Send Message." The "Conditions" node is highlighted with a red outline, indicating it is likely selected or being emphasized for the user to interact with. These nodes represent different functions or processes that can be configured within a conversation flow in a chatbot or similar automated system.Conditions

Properties > Parameters

Property name: Set Parameter 1

Parameter: QUERY_PARAMETER

Value: $RETURNED_NEXT_ID1

Connection(s): $QUERY_PARAMETER to Exit Points

Depending on which option the player chooses, this property will point to the ID of the next message the player should receive after texting "1".

The image displays a user interface for a "Set Parameter 1" configuration. There are two fields: one labeled "Parameter," with "QUERY_PARAMETER" selected from a dropdown menu, and another labeled "Value," containing the placeholder "$RETURNED_NEXT_ID1." This setup indicates that the system is configured to assign the value from "$RETURNED_NEXT_ID1" to the "QUERY_PARAMETER." This is typically part of a workflow where the value of a parameter is dynamically set based on a previous action or input.Set Parameter 1

Properties > Parameters

Property name: Set Parameter 2

Parameter: QUERY_PARAMETER

Value: $RETURNED_NEXT_ID2

Connection(s): $QUERY_PARAMTER to Exit Points

Depending on which option the player chooses, this property will point to the ID of the next message the player should receive after texting "2".

Properties > Parameters

Property name: Set Parameter 3

Parameter: QUERY_PARAMETER

Value: $RETURNED_NEXT_ID3

Connection(s): $QUERY_PARAMTER to Exit Points

Depending on which option the player chooses, this property will point to the ID of the next message the player should receive after texting "3".

Nodes > Conversation > Conditions

Node name: Exit Points

Condition Name(s):

  • QUERY_ID NOT 0

    *Parameter: QUERY_PARAMETER*
    	 Operation: Is not equal to
    	 *Value: 0*
    	 Connection(s): $QUERY_ID NOT 0 to Webhook
  • QUERY_ID = 0

    *Parameter: QUERY_PARAMETER*
    	 Operation: Is equal to
    	 *Value: 0*
    	 Connection(s): $QUERY_ID = 0 to End Game

Nodes > Conversation > Send Message

Node name: End Game

Text: Thanks for playing Vonage’s Gate! Share your thoughts on Twitter and tag @dianasoyster and @VonageDev

Connection(s): Thanks for playing to END CONVERSATION

The image shows a section of a user interface with a menu labeled "NODES" and a subsection titled "Conversation." Within this subsection, a list of conversational nodes is presented: "Classification," "Collect Input," and "Send Message." The "Send Message" node is highlighted with a red outline, suggesting it is currently selected or being focused on. These nodes represent different stages or actions in a conversation flow within a chatbot or automated messaging system.Send Message

This node is sent after the player reaches the end of their adventure. This means all values in the table are 0 and they send "1" to continue as prompted.

The image is a screenshot of a user interface for a messaging application, showing an "End Game" messaging node. It displays various types of message options such as Text, Image, Audio, File, Location, and Video, with the Text option highlighted. Below the message options, there's a section labeled "Agent says," followed by a text box containing the message: "Thanks for playing Vonage’s Gate! Share your thoughts on Twitter and tag @dianasoyster and @VonageDev." This implies that the agent, or chatbot, will send this message at the end of the game to encourage players to share their experience on Twitter.End Game

Nodes > Actions > End Conversation

Node name: End Conversation

The image depicts a user interface from a software application with a menu titled "Actions" on the left side. One of the actions, "End Conversation," is highlighted within a red outlined box and has an icon resembling a chat bubble with a diagonal line through it, indicating the function to terminate a conversation. Other action options listed but not highlighted include "Send Email," "Send SMS," and "Live Agent Routing," each with their respective icons.End Conversation

Technically, you don't need this node, but out of good practice, we should include it.

Testing

On the top right hand corner of Vonage AI Studio, there is a black Tester button. Click that to play the game.

This is a screenshot of a text-based role-playing game being played through a chat interface. The game is presumably named "Vonage's Gate." The player is being welcomed by the game's agent and is prompted to choose a class out of Warrior, Mage, or Rogue. The player chooses the option "3" which corresponds to the Rogue class. The agent acknowledges the choice with a poetic description of the Rogue class, highlighting stealth and cunning as their attributes, and instructs the player to send the message "Text 1" to continue the game.Testing the Agent in AI Studio - Part 1

This image shows a continuation of the text-based role-playing game in a chat interface, where the game's agent presents a new scenario to the player. The player is faced with a decision: a mysterious figure has offered a quest to find a lost artifact. The agent asks whether the player wants to (1) accept the quest or (2) decline and explore the town. The player chooses option "1" to accept the quest. In response, the agent congratulates the player for bravely accepting the quest and mentions that the mysterious figure hands the player a worn map with a location marked in red, presumably indicating where the quest will lead.Testing the Agent in AI Studio - Part 2

This image shows the next part of the text-based role-playing game. The game's agent gives the player a choice after they have accepted the quest to venture into the Spiderwood Forest. The player must decide whether to (1) head to the forest right away or (2) stop by the village to gather more information about the forest. The player chooses option "1" to head to the forest right away.  Following this decision, the agent describes the journey into the Spiderwood Forest, indicating that the player has been given a map and warned of dangers ahead. After hours of travel, the player reaches a fork in the path and must choose again: go (1) left, towards the sounds of a river, or (2) right, where the path seems safer. The player's choice at this point is not shown in the image.Testing the Agent in AI Studio - Part 3

The image continues the narrative of the text-based role-playing game. It seems that the player chose to follow the river's sound, which led them to a hidden cave behind a waterfall. Inside the cave, they find the lost artifact, described as glowing with an otherworldly light. The game's agent then presents the player with a new decision: (1) take the artifact, or (2) walk back to the safer path. The player opts for choice "1" to take the artifact. The outcome of this decision is not displayed in the image.Testing the Agent in AI Studio - Part 4

This image shows the conclusion of the text-based role-playing game scenario. The player, having chosen to take the artifact, is told they feel a sense of accomplishment. The game's agent informs the player that they have successfully completed the quest and now have the option to return the artifact to the mysterious figure or keep it for themselves. The player is instructed to text "1" to continue, which they do.  Finally, the game's agent thanks the player for playing "Vonage's Gate" and suggests sharing thoughts on Twitter, providing two handles to tag in the post. The conversation in the game interface then appears to be ended by the agent.Testing the Agent in AI Studio - Part 5

Stepping into Your Own Adventure

As quoted from Baldur's Gate 3, "You can’t compromise with evil. It always profits in the end." In this tutorial, we learned how to use best practices when storing data so you won't have to deal with "evil" tech debt in case you need to make changes to your texts in the future. We also learned to integrate a database with Vonage AI Studio and Messages API. Feel free to join our "class" of developers on Slack and follow us on X, formerly known as Twitter. If you build a similar application, please share it and tag me - I'd love to hear about your adventure!

Diana PhamDeveloper Advocate

Diana is a developer advocate at Vonage. She likes eating fresh oysters.

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.

Subscribe to Our Developer Newsletter

Subscribe to our monthly newsletter to receive our latest updates on tutorials, releases, and events. No spam.