# Gửi tin nhắn

Sau khi nhận thông tin từ webook gửi về, xem cấu hình nhận tin nhắn - thông báo trên Fanpage mục [Webhook tin nhắn](/webhook/webhook-tin-nhan.md) , Quý khách hàng sẽ có các thông tin cần thiết như id hội thoại, id fanpage, pagescopeid, text message từ Fanpage gửi về. Để tương tác và reply lại khách , Quý khách hàng - đối tác cần tạo Access Token để tương cấp quyền xác thực trên mỗi request đến API của Abitmes, Xem mục Khởi tạo [Access Token](/khoi-tao-access-token.md) để lấy quyền truy cập và tương tác.

URL API: [https://api.abitmes.vn](https://api.abitmes.vn/)

<mark style="color:green;">`POST /`</mark>`api/partner/{ma_shop}/{access_token}/send-message?page_id={id_page}`&#x20;

Trong đó:

| Name            | Value                                                                                                                                                                                           |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| {ma\_shop}      | tương ứng là Tên khách hàng khi khởi tạo Access Token, Xem [**tại đây**](/khoi-tao-access-token.md)                                                                                             |
| {access\_token} | Mã Access token được khởi tạo và cấp quyền bởi chủ tài khoản Abit, Xem hướng dẫn tạo [<mark style="color:red;">**Access Token**</mark> ](/gioi-thieu-ve-abit-open-api.md#khoi-tao-access-token) |
| {id\_page}      | Là ID Fanpage , giá trị này có thể trả về trên boby webhook của tin nhắn                                                                                                                        |

**Url example:** <https://api.abitmes.vn/api/partner/Abit/NWUxMzU5ZmZjZjc5YzAyYTY1YTcyNWE0ZTQ2OTdmM2Q=/send-message?page_id=2013792605578989>

API này Abit mô phỏng và giữ nguyên định dạng body chuẩn của Facebook theo tài liệu của Facebook\
<https://developers.facebook.com/docs/messenger-platform/send-messages>

Thử nghiệm với Postman:

<https://api.postman.com/collections/2953703-42320021-a4aa-4b8d-a9d0-1029d557ebb7?access_key=PMAT-01K5QWGH0NYSG2B7CPY3Q0WFBV>

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |

<mark style="color:orange;">**Gửi tin nhắn Text cơ bản cho khách**</mark>

**Body**

<table><thead><tr><th width="149">Name</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td></td><td>Thông tin người nhận tin nhắn phản hồi</td></tr><tr><td>id</td><td>string</td><td>ID của khách chat trên fanpage, giá trị này tương ứng là <strong>page_scopeid</strong> trong boby json của webhook bắn về</td></tr><tr><td>message</td><td></td><td>Nội dung tin nhắn phản hồi khách hàng</td></tr><tr><td>text</td><td>string</td><td>Loại tin nhắn phản hồi khách hàng, trong ví dụ là tin nhắn text phản hồi khách</td></tr></tbody></table>

{% tabs %}
{% tab title="Body" %}

```json
{
    "recipient": {
        "id": "2298104106936206"
    },
    "message": {
        "text": "hello 3"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```json
{
    "error": 0,
    "data": {
        "recipient_id": "2298104106936206",
        "message_id": "m__NF_55z0NiqkoAzzxL02eKUlmN3hacJV4y1OXCAslPGGvgnfIGU_MAzV-6qDkpZhcaqwDiaETWUW2xsyFFKPaQ"
    }
}
```

{% endtab %}
{% endtabs %}

<mark style="color:orange;">**Gửi 1 ảnh**</mark>

{% tabs %}
{% tab title="Body" %}

```json
{
   "recipient":{
      "id":"2298104106936206"
   },
   "message":{
      "attachment":{
         "type":"image",
         "payload":{
            "url":"https://blog.abitstore.vn/frontend/assets/img/trangchu/banner-abitstore.jpg",
            "is_reusable":true
         }
      }
   }
}
```

{% endtab %}

{% tab title="Response" %}

```json
{
    "error": 0,
    "data": {
        "recipient_id": "2298104106936206",
        "message_id": "m_WXfwQr2F7t4wX8K8Ji-No6UlmN3hacJV4y1OXCAslPHqAIctqob-3KyogDm8szEHqUufZLl3WnmQEIfi7zesRg",
        "attachment_id": "839896582031502"
    }
}
```

{% endtab %}
{% endtabs %}

<mark style="color:orange;">**Gửi nhiều ảnh**</mark>

{% tabs %}
{% tab title="Body" %}

```json
{
   "recipient":{
      "id":"2298104106936206"
   },
   "message":{
      "attachments": [
      {
        "type": "image",
        "payload": {
          "url": "https://blog.abitstore.vn/frontend/assets/img/trangchu/banner-abitstore.jpg"
        }
      },
      {
        "type": "image",
        "payload": {
          "url": "https://blog.abitstore.vn/photos/MrChinh.SEO/1.jpg"
        }
      }
    ]
   }
}
```

{% endtab %}

{% tab title="Response" %}

```json
{
    "error": 0,
    "data": {
        "recipient_id": "2298104106936206",
        "message_id": "m_5ZzmrZn7NnvZNcqp26yuR6UlmN3hacJV4y1OXCAslPElfD5czAvpuwDdp6loR3tzGFy22OQUeizANneF5ebmwg"
    }
}
```

{% endtab %}
{% endtabs %}


---

# 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://apidocs.abit.vn/api-abitmes/gui-tin-nhan.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.
