> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/narrative-design-guide/narrative-design-keys.md).

# Narrative Design Keys

This guide shows how to dynamically pass variables to Narrative Design section and triggers

We will create a simple scenario where the character welcomes the player and asks them about their evening or morning based on the player's time of day.

1. In the playground, enable Narrative Design on your character and change the starting section name to `Welcome`.<br>
2. Add the following to the Objective field of the Welcome section:\
   `The time of day currently is {TimeOfDay}. Welcome the player and ask him how his {TimeOfDay} is going.`\
   \
   Notice that by adding any string between curly brackets it becomes a variable, and what we did here is adding the time of day as a variable, then from Unreal we can pass either the word "Morning" or "Evening" and the character will respond accordingly.<br>

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FjIXZMLIToi7k1RfftC3n%2Fimage.png?alt=media&amp;token=df966094-b478-4f71-b108-c83438ca9ac2" alt=""><figcaption><p>Narrative Design Keys</p></figcaption></figure>
3. Setting Narrative Template Keys in JavaScript

   To initialize your narrative design framework with custom template keys, you can pass the `narrativeTemplateKeys` argument when instantiating the `convaiClient`. This allows you to define and structure your narrative flow programmatically.

```javascript
//example
function getNarrativeTemplateKeys(): Map<string, string> {
  const narrativeKeys = new Map<string, string>();
  // Populate the map with narrative keys and values
  // This could be from a database, configuration file, or other source
  narrativeKeys.set('TimeOfDay', 'Replace it with time');
  narrativeKeys.set('chapter1', 'The journey begins in a small village.');
  // Add more narrative keys as needed
  return narrativeKeys;
}


const client = new convaiClient({
  apiKey: 'your-api-key',
  characterId: 'your-character-id',
  narrativeTemplateKeys: getNarrativeTemplateKeys()
});
```

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/narrative-design-guide/narrative-design-keys.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
