Example use php push message to LINE OA

Example use php push message to LINE OA

Example use php push message to LINE OA

Jan 30, 2025

PHPLINEOAMessagingNotifyAPI

Example use php push message to LINE OA

Cr. Supakarn Laorattanakul

Example code php

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.line.me/v2/bot/message/push',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "to": "<UserId>",
    "messages":[
        {
            "type":"text",
            "text":"นี่เป็นข้อความจากเรา"
        },
        {
  "type": "template",
  "altText": "this is a confirm template",
  "template": {
    "type": "confirm",
    "actions": [
      {
        "type": "message",
        "label": "Yes",
        "text": "ขอบคุณที่ใช้บริการค่ะ"
      },
      {
        "type": "message",
        "label": "No",
        "text": "ไปไกลตรีนเลย"
      }
    ],
    "text": "ืยืนยันการใช้บริการครั้งนี้ใช่หรือไม่ ?"
  }
}
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer <No 2.Channel Access Token>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;