Download the PHP package deawx/linebot without Composer

On this page you can find all versions of the php package deawx/linebot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package linebot

deawx/linebot

ไลบรารี PHP สำหรับเรียก LINE Messaging API

การเรียก HTTP ทั้งหมดใช้ guzzlehttp/guzzle ^7 หรือ ^8 Composer ของแอปจะเลือกสายที่เข้ากับแพ็กเกจอื่นได้ เมื่อ LINE ตอบ 4xx/5xx Guzzle จะโยน GuzzleHttp\Exception\ClientException หรือ ServerException

ยังไม่ได้ยิง API จริงทุกเมธอดในเครื่องนี้ ให้ทดสอบกับ Channel ของคุณเองก่อนขึ้นโปรดักชัน

ความต้องการ

ติดตั้ง

Composer จะดึงแพ็กเกจจาก Packagist และลง guzzlehttp/guzzle (^7 หรือ ^8) ให้เอง

ตัวอย่างโค้ดอยู่ที่โฟลเดอร์ examples/ บน GitHub (ไม่ติดตอน composer require)

ค่าคอนฟิกและ .env

ไลบรารีไม่ได้ติดตั้ง vlucas/phpdotenv เพราะการอ่านไฟล์ .env เป็นหน้าที่ของแอป

getenv() เป็นฟังก์ชันของ PHP ใช้ได้เลยถ้าเซ็ต environment ที่เว็บเซิร์ฟเวอร์ / Docker / ระบบปฏิบัติการแล้ว

ถ้าต้องการไฟล์ .env ให้ติดตั้ง dotenv ในแอป:

ตัวอย่าง .env (อย่า commit ไฟล์นี้):

ใส่ค่าตรงๆ ก็ได้ ใช้ clientId แทน channelId ได้เช่นกัน ถ้าค่าใดว่างตอนสร้าง จะโยน Cyberthai\Linebot\Exceptions\LineInitializeException

เริ่มต้นใช้งาน

ในตัวอย่างด้านล่างใช้ข้อความแบบนี้:


สารบัญหมวด API

หมวด จุดเข้า
บัญชีทางการ $line->info()
Webhook $line->webhook()
เนื้อหาจากผู้ใช้ $line->content()
ส่งข้อความ $line->message()
ผู้ใช้งาน $line->users()
กลุ่ม $line->group()
ห้องแชทหลายคน $line->room()
ริชเมนู $line->richmenu()
Audience $line->audience()
สถิติ Insight $line->insight()
แผนสมาชิก $line->membership()
คูปอง $line->coupon()
ผูกบัญชี $line->accountLink()
Channel Access Token $line->oauth() / $line->oauth2()

หมวดบัญชีทางการ

$line->info()

ดึงข้อมูลบัญชีทางการ เช่น ชื่อ รูป และโหมดแชท


หมวด Webhook

$line->webhook()

ตั้งค่า ดู และทดสอบ webhook ของช่อง

เมธอดในหมวดนี้:

$line->webhook()->set($url)

ตั้ง URL webhook ต้องเป็น HTTPS

$line->webhook()->get()

ดู URL และสถานะที่ตั้งไว้

$line->webhook()->test($url = '')

ทดสอบว่า LINE ยิง webhook ถึงเซิร์ฟเวอร์ได้หรือไม่ ไม่ส่ง URL จะทดสอบค่าที่ตั้งไว้แล้ว


หมวดเนื้อหาจากผู้ใช้

$line->content()

ดาวน์โหลดไฟล์ที่ผู้ใช้ส่งมา ยิงไป https://api-data.line.me

เมธอดในหมวดนี้:

$line->content()->get($messageId)

ดาวน์โหลดรูป วิดีโอ หรือเสียง คืนอาร์เรย์ที่มี content (ไบนารี) และ contentType

$line->content()->transcoding($messageId)

ตรวจว่าวิดีโอหรือเสียงพร้อมดาวน์โหลดหรือยัง

$line->content()->preview($messageId)

ดาวน์โหลดรูปตัวอย่างของรูปหรือวิดีโอ


หมวดส่งข้อความ

$line->message()

ส่งข้อความ ดูโควตา ตรวจโครงสร้างข้อความ และจัดการแชท

เมธอดในหมวดนี้:

$line->message()->reply($replyToken, $messages, $notificationDisabled = false)

ตอบกลับด้วย replyToken จาก webhook ใช้ได้ครั้งเดียวภายในเวลาที่ LINE กำหนด

$line->message()->push($to, $messages, $notificationDisabled = false, $retryKey = '')

ส่งหา user / group / room ได้ทุกเมื่อ $retryKey เป็น UUID สำหรับส่งซ้ำ

$line->message()->multicast($userIds, $messages, $notificationDisabled = false, $retryKey = '')

ส่งข้อความชุดเดียวกันหาหลาย user ID (ส่งกลุ่มหรือห้องไม่ได้)

$line->message()->narrowcast($messages, $recipient = [], $demographic = [], $limit = 0, $notificationDisabled = false, $retryKey = '')

ส่งตาม audience หรือตัวกรองประชากร

$line->message()->progressNarrowcast($requestId)

ดูสถานะการส่ง narrowcast ใช้ requestId จาก header X-Line-Request-Id

$line->message()->broadcast($messages, $notificationDisabled = false, $retryKey = '')

ส่งหาเพื่อนทั้งหมดของบัญชีทางการ

$line->message()->loading($chatId, $loadingSeconds = 0)

แสดงแอนิเมชันกำลังพิมพ์ในแชท 1 ต่อ 1 วินาทีต้องเป็นพหุคูณของ 5 ช่วง 5–60

$line->message()->markAsRead($markAsReadToken)

ทำเครื่องหมายว่าอ่านข้อความผู้ใช้แล้ว ใช้ token จาก webhook

$line->message()->quota()

ดูเพดานส่งข้อความเดือนนี้

$line->message()->quotaConsumption()

ดูจำนวนข้อความที่ส่งไปแล้วเดือนนี้

$line->message()->deliveryReply($date)

จำนวน reply ที่ส่งสำเร็จในวันนั้น date เป็น yyyyMMdd

$line->message()->deliveryPush($date)

$line->message()->deliveryMulticast($date)

$line->message()->deliveryBroadcast($date)

$line->message()->validateReply($messages)

ตรวจโครงสร้างข้อความสำหรับ reply ก่อนส่งจริง

$line->message()->validatePush($messages)

$line->message()->validateMulticast($messages)

$line->message()->validateNarrowcast($messages)

$line->message()->validateBroadcast($messages)

$line->message()->aggregationInfo()

ดูจำนวนหน่วย aggregation ที่ใช้เดือนนี้

$line->message()->aggregationList($limit = 0, $start = '')

ดึงรายชื่อหน่วย aggregation เดือนนี้ ใช้ $start จาก next เพื่อดึงหน้าถัดไป


หมวดผู้ใช้งาน

$line->users()

ดึงโปรไฟล์ผู้ใช้ที่เพิ่มเพื่อนแล้ว และรายการ user ID ของเพื่อน

เมธอดในหมวดนี้:

$line->users()->profile($userId)

ดึงชื่อ รูป และสถานะของผู้ใช้ที่เพิ่มเพื่อนแล้ว ใช้กับคนที่บล็อกไม่ได้

$line->users()->followers($start = '', $limit = 0)

ดึงรายการ user ID ของเพื่อน ไม่ส่งพารามิเตอร์ LINE จะใช้ค่าเริ่มต้น (limit 300) ถ้ามีหน้าถัดไปให้ส่งค่า next จากรอบก่อนเป็น $start limit สูงสุด 1000


หมวดกลุ่ม

$line->group()

ข้อมูลกลุ่มที่บอทเป็นสมาชิกอยู่

เมธอดในหมวดนี้:

$line->group()->summary($groupId)

ดูชื่อและรูปกลุ่ม

$line->group()->membersCount($groupId)

นับจำนวนสมาชิกในกลุ่ม

$line->group()->membersIds($groupId, $start = '')

ดึง user ID ของสมาชิก ถ้าเกิน 100 คนใช้ $start จาก next

$line->group()->member($groupId, $userId)

ดึงโปรไฟล์สมาชิกในกลุ่ม

$line->group()->leave($groupId)

ให้บอทออกจากกลุ่ม


หมวดห้องแชทหลายคน

$line->room()

ห้องแชทหลายคนที่บอทอยู่ ไม่มี API สรุปห้องแบบกลุ่ม

เมธอดในหมวดนี้:

$line->room()->memberCount($roomId)

นับจำนวนสมาชิกในห้อง

$line->room()->memberIds($roomId, $start = '')

ดึง user ID ของสมาชิก ถ้าเกิน 100 คนใช้ $start จาก next

$line->room()->member($roomId, $userId)

ดึงโปรไฟล์สมาชิกในห้อง

$line->room()->leave($roomId)

ให้บอทออกจากห้อง


หมวดริชเมนู

$line->richmenu()

สร้าง ผูก และจัดการริชเมนู อัปโหลด/ดาวน์โหลดรูปใช้ api-data.line.me

เมธอดในหมวดนี้:

$line->richmenu()->create($content)

สร้างริชเมนูจากอ็อบเจ็กต์ตามเอกสาร LINE คืน richMenuId

$line->richmenu()->validate($content)

ตรวจอ็อบเจ็กต์ก่อนสร้าง

$line->richmenu()->uploadImg($richMenuId, $img, $contentType = '')

อัปโหลดรูป JPEG หรือ PNG $img เป็นพาธไฟล์หรือไบนารี ถ้าเป็น .png จะส่ง image/png ให้

$line->richmenu()->downloadImg($richMenuId)

ดาวน์โหลดรูปริชเมนู คืน content และ contentType

$line->richmenu()->getList()

ดึงรายการริชเมนูทั้งหมดของช่อง

$line->richmenu()->get($richMenuId)

ดูริชเมนูจาก ID

$line->richmenu()->delete($richMenuId)

ลบริชเมนู

$line->richmenu()->setDefault($richMenuId)

ตั้งริชเมนูเริ่มต้นของบอท

$line->richmenu()->getDefaultList()

ดู ID ริชเมนูเริ่มต้น

$line->richmenu()->cancelDefault()

ยกเลิกริชเมนูเริ่มต้น

$line->richmenu()->createAlias($richMenuAliasId, $richMenuId)

สร้าง alias สำหรับสลับแท็บริชเมนู

$line->richmenu()->updateAlias($richMenuAliasId, $richMenuId)

ให้ alias ชี้ไปริชเมนูอื่น

$line->richmenu()->getAlias($richMenuAliasId)

ดูข้อมูล alias

$line->richmenu()->getAliasList()

ดึงรายการ alias ทั้งหมด

$line->richmenu()->deleteAlias($richMenuAliasId)

ลบ alias

$line->richmenu()->userLink($userId, $richMenuId)

ผูกริชเมนูกับผู้ใช้คนเดียว

$line->richmenu()->usersLink($userIds, $richMenuId)

ผูกริชเมนูกับผู้ใช้หลายคน

$line->richmenu()->getByUserId($userId)

ดูริชเมนูที่ผูกกับผู้ใช้อยู่

$line->richmenu()->deleteByUserId($userId)

ถอดริชเมนูออกจากผู้ใช้คนเดียว

$line->richmenu()->deleteByUserIds($userIds)

ถอดริชเมนูออกจากผู้ใช้หลายคน

$line->richmenu()->validateBatch($operations, $resumeRequestKey = '')

ตรวจคำขอเปลี่ยน/ถอดริชเมนูเป็นชุดก่อนส่งจริง

$line->richmenu()->replaceBatch($operations, $resumeRequestKey = '')

เปลี่ยนหรือถอดริชเมนูเป็นชุด

$line->richmenu()->progressBatch($requestId)

ดูสถานะงาน batch จาก requestId


หมวด Audience

$line->audience()

สร้างและจัดการกลุ่มผู้รับสำหรับ narrowcast

เมธอดในหมวดนี้:

$line->audience()->upload($description, $isIfaAudience = false, $uploadDescription = '', $audiences = [])

สร้าง audience จาก JSON ของ user ID หรือ IFA

$line->audience()->uploadByFile($description, $file, $isIfaAudience = false, $uploadDescription = '')

สร้าง audience จากไฟล์ข้อความ หนึ่ง ID ต่อบรรทัด $file เป็นพาธหรือเนื้อไฟล์

$line->audience()->add($audienceGroupId, $audiences, $uploadDescription = '')

เพิ่ม user ID หรือ IFA เข้า audience ที่มีอยู่ แบบ JSON

$line->audience()->addByFile($audienceGroupId, $file, $uploadDescription = '')

เพิ่มรายชื่อจากไฟล์เข้า audience ที่มีอยู่

$line->audience()->click($description, $requestId, $clickUrl = '')

สร้าง audience จากคนที่คลิกลิงก์ในข้อความ $requestId ของข้อความที่ส่งไป

$line->audience()->imp($description, $requestId)

สร้าง audience จากคนที่เห็นข้อความ

$line->audience()->rename($audienceGroupId, $description)

เปลี่ยนชื่อ audience

$line->audience()->get($audienceGroupId)

ดูข้อมูล audience

$line->audience()->delete($audienceGroupId)

ลบ audience

$line->audience()->getList($page = 1, $size = 20, $description = '', $status = '', $includesExternalPublicGroups = true, $createRoute = '')

ดึงรายการ audience ของช่อง size สูงสุด 40

$line->audience()->getShared($audienceGroupId)

ดูข้อมูล audience ที่แชร์จาก Business Manager

$line->audience()->getSharedList($page = 1, $size = 20, $description = '', $status = '', $createRoute = '', $includesOwnedAudienceGroups = false)

ดึงรายการ audience ที่แชร์จาก Business Manager


หมวดสถิติ Insight

$line->insight()

วันที่ใช้รูปแบบ yyyyMMdd

เมธอดในหมวดนี้:

$line->insight()->messageDelivery($date)

จำนวนข้อความที่ส่งสำเร็จในวันนั้น

$line->insight()->followers($date)

จำนวนเพื่อนในวันนั้น

$line->insight()->demographic()

ข้อมูลประชากรของเพื่อน

$line->insight()->messageEvent($requestId)

สถิติการโต้ตอบกับ narrowcast หรือ broadcast

$line->insight()->messageEventAggregation($customAggregationUnit, $from, $to)

สถิติต่อหน่วย aggregation ของ push / multicast

$line->insight()->richmenuSummary($richMenuId, $from, $to)

สถิติริชเมนูรวมในช่วงวันที่กำหนด

$line->insight()->richmenuDaily($richMenuId, $from, $to)

สถิติริชเมนูแยกตามวัน


หมวดแผนสมาชิก

$line->membership()

ฟีเจอร์ Membership ของบัญชีทางการ คือแผนที่ผู้ใช้สมัครจ่ายเงินกับเพจ ไม่ใช่รายชื่อสมาชิกในกลุ่มแชท

เมธอดในหมวดนี้:

$line->membership()->subscription($userId)

ดูว่าผู้ใช้อยู่แผนไหน และสถานะเป็นอย่างไร

$line->membership()->getList()

ดึงรายการแผนที่บัญชีทางการเปิดไว้

$line->membership()->userIds($membershipId, $start = '', $limit = 0)

ดึง user ID ของผู้ที่สมัครแผนนั้น limit สูงสุด 1000


หมวดคูปอง

$line->coupon()

สร้าง ดู และปิดคูปอง

เมธอดในหมวดนี้:

$line->coupon()->create($coupon)

สร้างคูปองใหม่ $coupon เป็นอ็อบเจ็กต์ตามเอกสาร LINE

$line->coupon()->getList($status = [], $start = '', $limit = 0)

ดึงรายการคูปอง $status เช่น DRAFT RUNNING CLOSED

$line->coupon()->get($couponId)

ดูรายละเอียดคูปอง

$line->coupon()->close($couponId)

ปิดคูปองไม่ให้ใช้ต่อ


หมวดผูกบัญชี

$line->accountLink()

ออก token สำหรับผูกบัญชีบริการกับบัญชี LINE

เมธอดในหมวดนี้:

$line->accountLink()->token($userId)

ออก link token


หมวด Channel Access Token

หมวดนี้ไม่ใช่การล็อกอินผู้ใช้ (LINE Login คนละระบบ)

$line->oauth() และ $line->oauth2() ใช้โปรโตคอล OAuth 2.0 เพื่อออก / ตรวจ / เพิกถอน Channel Access Token ของบอท ให้แอปเรียก Messaging API ได้ โดยไม่ต้องคัดลอก token จาก Console ทุกครั้ง

เมธอดในหมวดนี้:

$line->oauth()->accessToken()

ออก Channel Access Token อายุประมาณ 30 วัน (short-lived) ผ่าน /v2/oauth

$line->oauth()->verify($accessToken)

ตรวจว่า token อายุสั้นหรือยาวจาก Console ยังใช้ได้หรือไม่

$line->oauth()->revoke($accessToken)

เพิกถอน token อายุสั้นหรือยาวจาก Console

$line->oauth2()->token($jwt)

ออก Channel Access Token รุ่น 2.1 ด้วย JWT

$line->oauth2()->verify($accessToken)

ตรวจว่า token รุ่น 2.1 ยังใช้ได้หรือไม่

$line->oauth2()->tokens($jwt)

ดึง key ID ของ token รุ่น 2.1 ที่ยังใช้ได้ทั้งหมด

$line->oauth2()->revoke($accessToken)

เพิกถอน token รุ่น 2.1

$line->oauth2()->tokenV3($jwt = '')

ออก token แบบ stateless อายุ 15 นาที เพิกถอนไม่ได้ ไม่ส่ง JWT จะใช้ channel ID + secret จากตอนสร้าง Line


Partner API (เช่น LINE Notification Message) ไม่ได้อยู่ในแพ็กเกจนี้

ทดสอบกับช่องจริง

  1. สร้าง Messaging API Channel ที่ LINE Developers Console
  2. ใส่ค่าใน environment หรือ .env ของแอป อย่า commit token
  3. ตั้ง webhook เป็น HTTPS ที่เข้าถึงได้
  4. ส่งข้อความจาก LINE แล้วเรียก $line->message()->reply() ด้วย replyToken
  5. ลอง $line->info() และ $line->users()->profile() กับ user ID จาก webhook

เอกสารอ้างอิง

License

MIT


All versions of linebot with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
guzzlehttp/guzzle Version ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package deawx/linebot contains the following files

Loading the files please wait ...