> For the complete documentation index, see [llms.txt](https://docs.nlx.ai/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nlx.ai/platform/developers/conversation-sdk/examples/advanced/modalities.md).

# Modalities

Modalities allow richer interactions to be embedded inside chat or voice applications with task specific UI being presented at the appropriate moment in a conversation. The exact workflow depends on your setup:

{% tabs %}
{% tab title="Typescript + NPM (Recommended)" %}
Create a new file in your project (conventionally we call it `modalities-types.d.ts`). Then find the modality you are trying to implement and copy the typescript definition:

<figure><img src="/files/SUx6O0MRShBFyJlqIlGx" alt=""><figcaption></figcaption></figure>

This will ensure that the custom modality you are working with will match the schema builders are working with.

{% hint style="info" %}
We are working on tooling that will automate this step in the future.
{% endhint %}

Then make a file for the modality you are trying to implement:

{% code overflow="wrap" %}

```typescript
import { html, type CustomModalityComponent } from "@nlxai/touchpoint-ui";
import type * as Modalities from "../modalities-types.d.ts";

export const Flights = (CustomModalityComponent<Modalities.Flights> = ({
  data,
}) => {
  return html`
    <Carousel>
      ${data.flights.map(
        (flight) => html`
          <CustomCard>
            <div><strong>Flight:</strong> ${flight.flightNumber}</div>
            <div>
              <strong>From:</strong> ${flight.departure.city}
              (${flight.departure.code}) at
              ${new Date(flight.departure.time).toLocaleString()}
            </div>
            <div>
              <strong>To:</strong> ${flight.arrival.city}
              (${flight.arrival.code}) at
              ${new Date(flight.arrival.time).toLocaleString()}
            </div>
            <div><strong>Airline:</strong> ${flight.airline}</div>
            <div><strong>Duration:</strong> ${flight.duration}</div>
            <div><strong>Price:</strong> ${flight.price}</div>
          </CustomCard>
        `,
      )}
    </Carousel>
  `;
});
```

{% endcode %}

These are standard React components, so can be unit tested, type-checked and so on. Also if you prefer JSX syntax, then `react` can be imported instead of `html`.

Finally in your Touchpoint configuration you can register these components:

```typescript
import { create } from "@nlxai/touchpoint-ui";
import { Flights } from "./custom-modalities/flights.tsx";
      
const touchpoint = await create({
  config: {
    applicationUrl: "REPLACE_WITH_APPLICATION_URL",
    headers: {
      "nlx-api-key": "REPLACE_WITH_API_KEY"
    },
    languageCode: "en-US",
  },
  modalityComponents: {
    Flights
  }
});
```

{% endtab %}

{% tab title="HTML" %}

```html
<html lang="en">
  <head>
    <title>Touchpoint Sample HTML</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <script type="module">
      import { create, html } from "https://unpkg.com/@nlxai/touchpoint-ui/lib/index.js?module";
      
      const touchpoint = await create({
        config: {
          applicationUrl: "REPLACE_WITH_APPLICATION_URL",
          headers: {
            "nlx-api-key": "REPLACE_WITH_API_KEY"
          },
          languageCode: "en-US",
        },
        modalityComponents: {
          Flights(data) {
            return html`
            <Carousel>
              ${data.flights.map(
                (flight) => html`
                  <CustomCard>
                    <div><strong>Flight:</strong> ${flight.flightNumber}</div>
                    <div>
                      <strong>From:</strong> ${flight.departure.city}
                      (${flight.departure.code}) at
                      ${new Date(flight.departure.time).toLocaleString()}
                    </div>
                    <div>
                      <strong>To:</strong> ${flight.arrival.city}
                      (${flight.arrival.code}) at
                      ${new Date(flight.arrival.time).toLocaleString()}
                    </div>
                    <div><strong>Airline:</strong> ${flight.airline}</div>
                    <div><strong>Duration:</strong> ${flight.duration}</div>
                    <div><strong>Price:</strong> ${flight.price}</div>
                  </CustomCard>
                `,
              )}
            </Carousel>
          `;
          }
        }
      });
    </script>
  </body>
</html>
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nlx.ai/platform/developers/conversation-sdk/examples/advanced/modalities.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
