# Nhúng Form

{% hint style="info" %}
Tích hợp Nhúng Form giúp bạn thêm các form lên đơn để tự đồng bộ về CRM hoặc phần mềm quản lý bán hàng của mình trong module <mark style="color:orange;">**Nhắn tin**</mark>
{% endhint %}

## Hướng dẫn nhúng Form vào SmaxAi

Để nhúng Form vào SmaxAi, bạn cần truy cập module Cài đặt, sau đó chọn phần Tích hợp

Trong cửa sổ tích hợp bạn cần đặt tên của Form (1), phần nền tảng (2) chọn Nhúng form, sau đó nhập URL của form (3) và chọn Lưu (4) để lưu lại

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

## 2\_ Hướng dẫn giao tiếp giữa SmaxAi LiveChat với Form

### 2.1\_ Nhận event từ SmaxAI

<pre class="language-javascript"><code class="lang-javascript">// Nhận event từ SmaxAi Livechat
<strong>window.addEventListener('message', function (event) {
</strong>    if (typeof event.data == 'object' &#x26;&#x26; event.data.name === '__SM_FORM_CUSTOMER') {
        console.log(event.data?.data?.customer);
    }
}, false);

</code></pre>

<pre class="language-javascript"><code class="lang-javascript">
<strong>// event.data?.data?.customer có dạng:
</strong>{
    "id": "6340818229362746",
    "name": "Hoàng Đức",
    "address": "",
    "phone": "",
    "email": "",
    "gender": "",
    "gid": "",
    "picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/?psid=6340818229362746&#x26;width=300&#x26;ext=1691194252&#x26;hash=AeQudyCWzA0X3MZDGrk"
}
</code></pre>

### 2.2\_ Yêu cầu SmaxAi

```javascript
const getIntegrationId = () => {
  return window.location.href.split('=')[1]
}

// yêu cầu SmaxAi trả dữ liệu customer
if (window.parent) {
    window.parent.postMessage({
        name: '__SM_FORM_CUSTOMER',
        data: {
            integration_id: getIntegrationId(),
        }
    }, '*')
} else {
    console.error('window.parent is undefined')
}

// yêu cầu SmaxAi bật popup
if (window.parent) {
    window.parent.postMessage({
        name: '__SM_FORM_POPUP',
        action: 'SHOW',  // 'HIDE'
        data: {
            integration_id: getIntegrationId(),
            url: 'https://crm.com/orders?id=xxx',
            title: 'Title Demo',
            height: '80vh'
        }
    }, '*')
} else {
    console.error('window.parent is undefined')
}
```


---

# 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://tailieu.smax.ai/module-cai-dat/tich-hop/nhung-form.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.
