> For the complete documentation index, see [llms.txt](https://docs.launchboard.app/cxd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.launchboard.app/cxd/code-chatbot-1/code-mods/storing-data-for-a-user.md).

# Storing Data for a User

## The Rivescript Way

Rivescript offers a way to store data in your chatbot. For example, you could use the following script.

```javascript
+ my name is *
- <set name=<star>>It's nice to meet you, <get name>.

+ what is my name
- Your name is <get name>, silly!
```

&#x20;For a more detailed explanation go [here](https://www.rivescript.com/docs/tutorial#learning-things).The only limitation is that it only stores the name for the duration of the browser session. In other words if the user leaves your chatbot and comes back another time, his or her name will not be *remembered* (or stored) by the chatbot. The next way uses Javascript localStorage to store the data for longer periods.

## The Javascript `localStorage` Way

Using this method we can store information that will remain in the browser, even after a browser refresh. (Unless the user clears the browser cache, which is not typical.) First let's create some Javascript functions in our Rivescipt file to store, get, or clear a user's name.

```javascript
> object storeName javascript
  localStorage.setItem("name", args[0]);
< object

> object getName javascript
  var name = localStorage.getItem("name");
  if (name) return name;
  else return "what is your name?"
< object

> object clearName javascript
    localStorage.removeItem("name");
    return "Name removed.";
< object
```

Learn more about localStorage in Javascript [here](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).

Next, create the script needed to use these functions, like below.

```javascript
+ start // "start" autostarts the bot conversation 
- Hello, <call>getName</call>

+ *
% hello what is your name
- <call>storeName <formal></call>Nice to meet you <call>getName</call>

+ clear
- <call>clearName</call>
```

{% hint style="info" %}
You may have noticed that we used `<formal>` instead of `<star>` in line 6 to represent the user's input. The only difference between the two is that `<formal>` maintains any capitalization the user would use. This is useful in this case since we expect that most names begin with a capital letter.
{% endhint %}

You can modify the examples above to store and retrieve different information. &#x20;


---

# 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.launchboard.app/cxd/code-chatbot-1/code-mods/storing-data-for-a-user.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.
