# Web Component

### Overview

The Memori Web Component is a standard web component that can be embedded in any HTML page with no framework dependencies. It's the ideal solution for quick, straightforward integrations.

[🔗 GitHub Repository](https://github.com/memori-ai/memori-webcomponent)

#### Key Features

* Ready to use in plain HTML;
* No framework dependencies;
* Configuration via HTML attributes;
* Supported in all modern browsers;
* Automatic component lifecycle management.

### Installation <a href="#installazione_233" id="installazione_233"></a>

#### **CDN Installation**

```html
<!-- Import Web Component -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@memori.ai/memori-webcomponent/dist/memori-webcomponent.js">
</script>
<!-- Import styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@memori.ai/memori-react/dist/styles.min.css"
/>
```

#### **NPM Installation**

```batch
# npm
npm install @memori.ai/memori-webcomponent
# yarn
yarn add @memori.ai/memori-webcomponent
```

### Basic Usage <a href="#utilizzo_base_261" id="utilizzo_base_261"></a>

#### **Simple Implementation**

```html
<memori-client
  memoriName="MyMemori"
  ownerUserName="user"
  tenantID="your-tenant.com"
  apiURL="https://backend.memori.ai"
  baseURL="https://your-base-url.com"
  height="500px"
  multilingual="true"
></memori-client>
```

### Advanced Usage <a href="#utilizzo_avanzato_277" id="utilizzo_avanzato_277"></a>

#### **With Context Variables**

```html
<memori-client
  memoriName="MyMemori"
  ownerUserName="user"
  tenantID="your-tenant.com"
  context="LOCATION:Milan,USER_TYPE:premium,CUSTOM_VAR:value"
  height="100vh"
  showShare="true"
  showSettings="true"
  multilingual="true"
></memori-client>
```

#### **Get resource URL**

```javascript
const resourceUrl = await memori.asset.getResourceUrl({
  sessionId: sessionID,
  resourceName: "image.jpg",
});
```

#### Event Handling <a href="#gestione_eventi_303" id="gestione_eventi_303"></a>

```javascript
<script>
  // Listen for state changes
  document.addEventListener("MemoriNewDialogState", (e) = >{
    const state = e.detail;
    console.log("New dialog state:", state); < span class = "hljs-comment" > // Handle specific responses</span><span class="hljs-keyword">if</span> (state.emission?.includes(<span class="hljs-string">"product"</span>)) {  showProductDetails();}
  });
  // Handle end-of-speech events
  document.addEventListener("MemoriEndSpeak", () = >{
    console.log("Memori has finished speaking");
  });
  // Send a message
  function sendCustomButton() {
    window.typeMessage("Hello from the custom button!");
  }
  // Send a hidden message
  function sendHiddenCommand() {
    window.typeMessageHidden("system:update", true);
  }
</script>
<button onclick="sendCustomButton()">
  Send Message
</button>
```


---

# Agent Instructions: 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:

```
GET https://docs.aisuru.com/en/frontend/web-component.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
