# LINE API

import { Badge } from '@astrojs/starlight/components';

<Aside type="caution" title="/createLineMessage เลิกใช้งานแล้ว">
การผสานรวมใหม่ควรใช้ [Messaging API v2](/th/developer/api-reference/messaging-api-v2/) — ส่ง `platforms: ["LINE"]` ไปยัง `Notify` และใช้บล็อก `line` ภายใน `payload.content.localized_content` ดู [คู่มือการย้าย](/th/developer/api-reference/messaging-api-v2/migration-from-v1/#from-createlinemessage) สำหรับข้อความรูปภาพ / คารูเซล / flex ที่มีเนื้อหาสมบูรณ์ ให้กำหนดค่าล่วงหน้าเป็นเทมเพลต LINE ใน Pushwoosh Control Panel ของคุณและอ้างอิงรหัสเทมเพลตผ่าน `line.template`
</Aside>

<Aside> ก่อนส่งข้อความ LINE ตรวจสอบให้แน่ใจว่าแพลตฟอร์ม Line ได้รับการกำหนดค่าอย่างถูกต้อง [เรียนรู้เพิ่มเติม](/th/developer/first-steps/connect-messaging-services/line-configuration/) </Aside>

## createLineMessage <Badge text="เลิกใช้งานแล้ว" variant="caution" size="small" />

ใช้สำหรับส่งข้อความ LINE ไปยังผู้ใช้

`POST` `https://api.pushwoosh.com/json/1.3/createLineMessage`

### ส่งข้อความตัวอักษร

ข้อความ LINE แบบง่ายที่ประกอบด้วยข้อความธรรมดาเท่านั้น ไม่มีรูปภาพหรือปุ่ม [เรียนรู้เพิ่มเติม](https://developers.line.biz/en/reference/messaging-api/#text-message)

> **เคล็ดลับ:** สำหรับการจัดรูปแบบขั้นสูงและสื่อสมบูรณ์ ให้ใช้เทมเพลตข้อความเช่น [Flex](#send-a-flex-message), [รูปภาพ](#send-an-image-message), หรือ [คารูเซล](#send-an-image-carousel-message)

##### เนื้อหาของคำขอ

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `application` | string | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| `auth` | string | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) สำหรับการตรวจสอบสิทธิ์คำขอ |
| `notifications` | array of objects | ใช่ | รายการของอ็อบเจกต์ข้อความ LINE ที่จะส่ง |
| `content` | string | ใช่ | ข้อความของข้อความ LINE ที่จะส่ง ขีดจำกัดตัวอักษรสูงสุด: 5000<br/><strong>หมายเหตุ:</strong> หากมีทั้ง <code>preset</code> และ <code>content</code> ค่าจากคำขอจะแทนที่ <code>preset</code> |
| `preset` | string | ไม่ | รหัสของ [LINE preset](/th/product/content/line-presets/) ที่คุณสร้างใน Pushwoosh Control Panel **หมายเหตุ:** หากมีทั้ง `preset` และ `content` ค่าจากคำขอจะแทนที่ `preset` |
| `send_date` | string | ใช่ | วันที่และเวลาที่จะส่งข้อความ ใช้รูปแบบ `YYYY-MM-DD HH:mm` หรือ `now` เพื่อส่งทันที |
| `devices` | array of strings | ใช่ | รายการรหัสอุปกรณ์ (user IDs) ที่จะส่งข้อความ LINE ไปให้ |

```
{
    "request": {
    "application": "XXXXXX-XXXXXX",
    "auth": "**************************************",
        "notifications": [
            {
                "content": "test",
                "preset": "preset_code",
                "send_date":"now",
                "devices": ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"]
            }
        ]
    }
}

```

### ส่งข้อความรูปภาพ

คุณสามารถส่ง [ข้อความรูปภาพ](https://developers.line.biz/en/reference/messaging-api/#image-message) ไปยังผู้ใช้ LINE โดยการระบุอ็อบเจกต์รูปภาพภายในฟิลด์เทมเพลตของคำขอของคุณ

ข้อความรูปภาพแต่ละข้อความต้องการ URL รูปภาพสองรายการ: หนึ่งสำหรับ **รูปภาพขนาดเต็ม (image\_url)** และอีกหนึ่งสำหรับ **ภาพตัวอย่าง (preview\_image\_url)** เมื่อผู้ใช้แตะที่ภาพตัวอย่าง รูปภาพขนาดเต็มจะเปิดขึ้น ตรวจสอบให้แน่ใจว่า URL ทั้งสองใช้ HTTPS (TLS 1.2 หรือใหม่กว่า) และเชื่อมโยงไปยังไฟล์รูปภาพที่สามารถเข้าถึงได้แบบสาธารณะ

สำหรับรายละเอียด โปรดดูส่วน [Image Message](https://developers.line.biz/en/reference/messaging-api/#image-message) ในเอกสารประกอบ LINE Messaging API

##### เนื้อหาของคำขอ

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | ----- | ----- | ----- |
| `application` | string | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| `auth` | string | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) ที่ใช้ในการตรวจสอบสิทธิ์คำขอ |
| `notifications` | array of objects | ใช่ | รายการข้อความที่จะส่ง |
| `content` | string | ใช่ | ใช้เป็นข้อความสำรองหรือข้อความตัวอย่างสำหรับข้อความ รหัสของ LINE preset ที่คุณสร้างใน Pushwoosh Control Panel<br/><strong>หมายเหตุ:</strong> หากมีทั้ง <code>preset</code> และ <code>template</code> จะใช้ <code>template</code> จากคำขอ<br/>หากมีทั้ง <code>preset</code> และ <code>content</code> <code>content</code> จากคำขอจะแทนที่ preset |
| `send_date` | string | ใช่ | วันที่และเวลาที่จะส่งข้อความ ใช้รูปแบบ `YYYY-MM-DD HH:mm` หรือ `now` เพื่อส่งทันที |
| `devices` | array of strings | ใช่ | รายการรหัสอุปกรณ์ (user IDs) ที่จะส่งข้อความ LINE ไปให้ |
| `preset` | string | ไม่ | รหัสของ [LINE preset](/th/product/content/line-presets/) ที่คุณสร้างใน Pushwoosh Control Panel<br/><strong>หมายเหตุ:</strong> หากมีทั้งพารามิเตอร์ <code>preset</code> และ <code>template</code> ในคำขอ ค่าจาก <code>template</code> จะแทนที่ค่าที่กำหนดใน preset<br/>หากมีทั้ง <code>preset</code> และ <code>content</code> ในคำขอเดียวกัน <code>content</code> ที่ให้มาโดยตรงในคำขอจะแทนที่เนื้อหาจาก <code>preset</code> |
| `template` | object | ใช่ | เทมเพลตเค้าโครงข้อความ รองรับข้อความหลายประเภท ดูรายละเอียดด้านล่าง |

##### พารามิเตอร์เทมเพลต

**ประเภท:** image

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `image_url` | string | ใช่ | URL ของรูปภาพขนาดเต็ม (ต้องใช้ HTTPS) **ความยาวสูงสุด:** 2000 ตัวอักษร **รูปแบบ:** JPEG, PNG **ขนาดสูงสุด:** 10 MB |
| `preview_image_url` | string | ใช่ | URL ของภาพตัวอย่างที่แสดงในแชท (ต้องใช้ HTTPS) **ความยาวสูงสุด:** 2000 ตัวอักษร **รูปแบบ:** JPEG, PNG **ขนาดสูงสุด:** 1 MB |

##### ตัวอย่างคำขอ

```json
{
  "request": {
    "application": "XXXXXX-XXXXXX",
    "auth": "**************************************",
    "notifications": [
      {
        "content": "test",
        "send_date": "now",
        "devices": [
          "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        ],
        "preset": "preset_code",
        "template": {
          "en": {
            "image": {
              "alt_text": "some text",
              "image_url": "https://images.com/1.jpg",
              "preview_image_url": "https://images.com/1.png"
            }
          }
        }
      }
    ]
  }
}


```

### ส่งข้อความคารูเซลรูปภาพ

ข้อความคารูเซลรูปภาพช่วยให้คุณสามารถแสดงรูปภาพหลายรูปในรูปแบบที่เลื่อนได้ในแนวนอน รูปภาพแต่ละรูปจะปรากฏเป็นคอลัมน์แยกต่างหากที่ไม่สามารถคลิกได้ ซึ่งผู้ใช้สามารถปัดผ่านในอินเทอร์เฟซแชทของ LINE

รูปแบบนี้เหมาะสำหรับการนำเสนอสินค้า โปรโมชั่น หรือการเลือกชมภาพในรูปแบบที่น่าสนใจ

สำหรับรายละเอียด โปรดอ้างอิงส่วน [Image Carousel Template](https://developers.line.biz/en/reference/messaging-api/#carousel) ในเอกสารประกอบ LINE Messaging API

##### เนื้อหาของคำขอ

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `application` | string | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| `auth` | string | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) ที่ใช้ในการตรวจสอบสิทธิ์คำขอ |
| `notifications` | array of objects | ใช่ | รายการข้อความที่จะส่ง |
| `content` | string | ใช่ | ใช้เป็นข้อความสำรองหรือข้อความตัวอย่างสำหรับข้อความ<br/><strong>หมายเหตุ:</strong> หากตั้งค่าทั้ง <code>content</code> และ <code>template</code> จะใช้ <code>template</code><br/>หากมีทั้ง <code>preset</code> และ <code>content</code> ในคำขอเดียวกัน <code>content</code> ที่ให้มาโดยตรงในคำขอจะแทนที่เนื้อหาจาก <code>preset</code> |
| `send_date` | string | ใช่ | วันที่และเวลาที่จะส่งข้อความ ใช้รูปแบบ `YYYY-MM-DD HH:mm` หรือ `"now"` |
| `devices` | array of strings | ใช่ | รายการรหัสอุปกรณ์ (user IDs) ที่จะส่งข้อความ LINE ไปให้ |
| `preset` | string | ไม่ | รหัสของ [LINE preset](/th/product/content/line-presets/) ที่คุณสร้างใน Pushwoosh Control Panel<br/><strong>หมายเหตุ:</strong> หากมีทั้งพารามิเตอร์ <code>preset</code> และ <code>template</code> ในคำขอ ค่าจาก <code>template</code> จะแทนที่ค่าที่กำหนดใน <code>preset</code><br/>หากมีทั้ง <code>preset</code> และ <code>content</code> ในคำขอเดียวกัน <code>content</code> ที่ให้มาโดยตรงในคำขอจะแทนที่เนื้อหาจาก <code>preset</code> |
| `template` | object | ใช่  | เทมเพลตเค้าโครงข้อความ รองรับข้อความหลายประเภท ดูรายละเอียดด้านล่าง |



##### พารามิเตอร์เทมเพลต

**ประเภท:** image\_carousel

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `alt_text` | string | ใช่ | ข้อความสำรองที่แสดงในตัวอย่าง push และบนอุปกรณ์ที่ไม่รองรับ ความยาวสูงสุด 400 ตัวอักษร |
| `columns` | array of objects | ใช่ | อาร์เรย์ของคอลัมน์รูปภาพ (รองรับ 1–10 คอลัมน์) แต่ละคอลัมน์ประกอบด้วยรูปภาพ |
| `image_url` | string  | ใช่ | URL ของรูปภาพที่แสดงในแต่ละคอลัมน์ของคารูเซล ซึ่งชี้ไปยังไฟล์ JPEG หรือ PNG ที่สามารถเข้าถึงได้แบบสาธารณะ ต้องใช้ HTTPS |

##### ตัวอย่างคำขอ

```json
{
  "request": {
    "application": "XXXXXX-XXXXXX",
    "auth": "**************************************",
    "notifications": [
      {
        "content": "test",
        "send_date": "now",
        "devices": [
          "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        ],
        "preset": "preset_code",
        "template": {
          "en": {
            "image_carousel": {
              "alt_text": "some text",
              "columns": [
                { "image_url": "https://images.com/1.jpg" },
                { "image_url": "https://images.com/2.jpg" },
                { "image_url": "https://images.com/3.jpg" }
              ]
            }
          }
        }
      }
    ]
  }
}
```

### ส่งข้อความ Flex

Flex Messages เป็นประเภทข้อความที่มีประสิทธิภาพและปรับแต่งได้ ซึ่งช่วยให้คุณสร้างเค้าโครงที่มีโครงสร้างโดยใช้ข้อความ รูปภาพ ปุ่ม และส่วนประกอบอื่นๆ เหมาะสำหรับกรณีการใช้งานเช่น ใบเสร็จ การ์ดผลิตภัณฑ์ เมนู หรือเนื้อหาใดๆ ที่ต้องการการจัดโครงสร้างทางสายตา

ในการส่ง Flex Message ให้รวมอ็อบเจกต์ `template` ที่มี `raw` payload ภายในคำขอของคุณ เค้าโครงข้อความต้องเป็นไปตาม [ข้อกำหนดของ LINE Flex Message](https://developers.line.biz/en/docs/messaging-api/using-flex-messages/)

**เคล็ดลับ:** คุณสามารถออกแบบและดูตัวอย่าง Flex Messages ได้โดยใช้ [LINE Flex Message Simulator](https://developers.line.biz/flex-simulator/)

##### เนื้อหาของคำขอ

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `application` | string | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| `auth` | string | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) ที่ใช้ในการตรวจสอบสิทธิ์คำขอ |
| `notifications` | array of objects | ใช่ | รายการข้อความที่จะส่ง |
| `content` | string | ใช่ | ใช้เป็นข้อความสำรองหรือข้อความตัวอย่างสำหรับข้อความ<br/><strong>หมายเหตุ:</strong> หากตั้งค่าทั้ง <code>content</code> และ <code>template</code> จะใช้เทมเพลต<br/>หากมีทั้ง <code>preset</code> และ <code>content</code> เนื้อหาจากคำขอจะแทนที่ preset |
| `send_date` | string | ใช่ | เวลาที่จะส่งข้อความ ใช้รูปแบบ `"now"` หรือ `YYYY-MM-DD HH:mm` |
| `devices` | array of strings | ใช่ | รายการโทเค็นอุปกรณ์ LINE (user IDs) ที่จะรับข้อความ |
| `preset` | string | ไม่ | รหัสของ [LINE preset](/th/product/content/line-presets/) ที่คุณสร้างใน Pushwoosh Control Panel<br/><strong>หมายเหตุ:</strong> หากมีทั้ง <code>preset</code> และ <code>template</code> เทมเพลตจะแทนที่ preset<br/>หากมีทั้ง <code>preset</code> และ <code>content</code> เนื้อหาจากคำขอจะแทนที่ preset |
| `template` | object | ใช่ | เทมเพลตเค้าโครงข้อความ รองรับข้อความหลายประเภท ดูรายละเอียดด้านล่าง |

##### พารามิเตอร์เทมเพลต

สำหรับ Flex Message ให้ใช้โครงสร้าง raw
ประเภท: raw (Flex)

| พารามิเตอร์ <div style="width:180px"></div>| ประเภท  <div style="width: 80px"></div>| จำเป็น | คำอธิบาย <div style="width:180px"></div> |
| :---- | :---- | :---- | :---- |
| `alt_text` | string | ใช่ | ข้อความสำรองที่แสดงในการแจ้งเตือน ตัวอย่างแชท และการอ้างอิง ความยาวสูงสุด 400 ตัวอักษร |
| `content`  | object  | ใช่ | เค้าโครง Flex Message ซึ่งมีโครงสร้างโดยใช้ `bubble`, `box`, `text` และส่วนประกอบอื่นๆ ตามข้อกำหนด Flex ของ LINE |

##### ตัวอย่างคำขอ

```json
{
  "request": {
    "application": "XXXXXX-XXXXXX",
    "auth": "**************************************",
    "notifications": [
      {
        "content": "test",
        "send_date": "now",
        "devices": ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"],
        "preset": "preset_code", 
        "template": {
          "en": {
            "raw": {
              "alt_text": "My raw template",
              "content": {
                "type": "bubble",
                "body": {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "RECEIPT",
                      "weight": "bold",
                      "color": "#1DB446",
                      "size": "sm"
                    }
                    // Additional components...
                  ]
                }
              }
            }
          }
        }
      }
    ]
  }
}
```