|
 |
|
ท่านใดเคยทำ push message ใน LINE bot บ้างไหมครับ ผมทำ reply message ได้แล้วแต่ push message ไม่ได้ครับ |
|
 |
|
|
 |
 |
|
อันนนี้เป็น code php สำหรับ reply message ครับทำตามคำแนะนำของคุณ nuuneoi
https://nuuneoi.com/blog/blog.php?read_id=882
ผมได้ทำตามเขาเกือบทุกขั้นตอนครับ มีบางขั้นตอนอย่าง code ด้านล่างครับผมงงว่ามันเอาไว้ใส่ตรงไหน
Code
curl -X POST \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
-d '{
"replyToken":"nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}' https://api.line.me/v2/bot/message/reply
แต่ code ที่คุณเนยเขียนไว้เป็น php ทำตามขั้นตอนแล้วใช้ได้ครับ(ด้านล่าง)
Code (PHP)
<?php
$access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// Get POST body content
$content = file_get_contents('php://input');
// Parse JSON
$events = json_decode($content, true);
// Validate parsed JSON data
if (!is_null($events['events'])) {
// Loop through each event
foreach ($events['events'] as $event) {
// Reply only when message sent is in 'text' format
if ($event['type'] == 'message' && $event['message']['type'] == 'text') {
// Get text sent
$text = $event['message']['text'];
// Get replyToken
$replyToken = $event['replyToken'];
$userId = $event['source']['userId'];
$id = $event['message']['id'];
// Build message to reply back
$messages = [
'type' => 'text',
'text' => $id,
];
// Make a POST Request to Messaging API to reply to sender
$url = 'https://api.line.me/v2/bot/message/reply';
$data = [
'replyToken' => $replyToken,
'messages' => [$messages],
];
$post = json_encode($data);
$headers = array('Content-Type: application/json', 'Authorization: Bearer ' . $access_token);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result . "\r\n";
}
}
}
echo "OK";
?>
แต่ผมอยากทำ Push message ไปหาสมาชิกโดยที่สมาชิกไม่ต้องทักมาก่อนเหมือนกับ Reply message แต่ตอนนี้ยังไปไม่ถูกครับ
เลยอยากถามพี่ๆครับว่ามีใครเคยเล่น LINE bot ไหมครับอยากได้คำแนะนำครับ
(รูปล่าง)เป็น code php กับ shell ที่LINEบอกมา ของ reply message ครับ

(รูปล่าง)เป็น code php กับ shell ที่LINEบอกมา ของ push message ครับ

Tag : PHP

|
|
 |
 |
 |
 |
Date :
2017-03-03 13:39:52 |
By :
damnern007 |
View :
5144 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันมีแท็บเปลี่ยนภาษา Shell คือ พิมพ์ใน command line โดยใช้คำสั่งจาก cURL
ตัวอย่าง php ก็คลิกดูที่แท็บ php ก่อน 
|
 |
 |
 |
 |
Date :
2020-07-18 18:42:50 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|