> For the complete documentation index, see [llms.txt](https://tailieu.smax.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tailieu.smax.ai/module-cai-dat/tich-hop/nhung-form.md).

# 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')
}
```
