whchi/laravel-linebot-wrapper
Composer 安装命令:
composer require whchi/laravel-linebot-wrapper
包简介
A simple laravel wrapper for linecorp/line-bot-sdk
README 文档
README
A simple wrapper of linecorp/line-bot-sdk
Inspired by bottener.js
Installation
- composer install
composer require whchi/laravel-linebot-wrapper
- publish vendor
php artisan vendor:publish --provider="Whchi\LaravelLineBotWrapper\LINEBotServiceProvider"
- setup config
config/linebot.php
return [ 'channel_access_token' => 'find it in your LINE console' 'channel_secret' => 'find it in your LINE console' ];
- run migration: create a table named
line_bot_sessions - start use, see sample in app sample
remember to remove VerifyCsrfToken for line route
Usage
sdk functions
$this->context->sdk('replyText', [$event['replyToken'], 'hello']);
Initialize
In your webhook entry point
public function __construct() { $context = app('LINEBotContext'); } ... public function entryPoint(Request $request) { $lineMsg = $request->all(); $events = collect($lineMsg['events']); $events->map(function($event) { $this->context->setContext($event); ... do whatever you want... }); }
Remember bot session
Use event queue is recommended, see app samples
// after setContext event(new SaveLineBotSessionEvent($event));
State handling
Need Redis running in your enviorment
- init state
$this->context->initState([ 'status' => 1, 'isAuth' => ['departA' => true, 'departB' => false] ]); // must execute after setContext $this->context->buildState();
- set state
$this->context->setState(['status' => 2]);
- get state
$this->context->getState('isAuth.departA');
- reset state
$this->context->resetState();
Messages handling
see message samples for $template
push API
Make sure your account have PUSH_API permission
set userId before use push function
$this->context->setPushTo(string $userId|$groupId|$roomId);
- button
$this->context->pushButtonTemplate(string $altText,array $template)
- confirm
$this->context->pushConfirmTemplate(string $altText,array $template)
- carousel
$this->context->pushCarouselTemplate(string $altText,array $template)
- image carousel
$this->context->pushImageCarouselTemplate(string $altText, array $template)
- audio
$this->context->pushAudio(array $template)
- video
$this->context->pushVideo(array $template)
- image
$this->context->pushImage(array $template)
- sticker
$this->context->pushSticker(array $template)
- location
$this->context->pushLocation(array $template)
- text
$this->context->pushText(array $template)
Maximum size of $templateList is 5, so as reply
$this->context->push(string $altText,array $templateList)
// max 150 user id // @see https://developers.line.biz/en/reference/messaging-api/#send-multicast-message $this->context->pushMulticast(array $memberIdList, string $altText, array $templateList)
Maximum size of carousel flex message is 10, more detail: official doc
$this->context->pushFlex(string $altText, array $flexTemplate)
- quickReply see $quickReply example at message samples
$this->context->pushButtonTemplate(string $altText, $template + $quickReply);
reply API
Change pushXXXX to replyXXXX without setting userId, that is.
Leave API
$this->context->leave();
other usage
- detect event
more detail see official doc
$this->context->isXXXXEvent(); // example $this->context->isMessageEvent(); $this->context->isPostbackEvent(); ...
- detect message event type
$this->context->isXXXXMessage(); // example $this->context->isTextMessage(); $this->context->isImageMessage(); ...
- get message event message
$this->content->getMessagePayload();
- get postback data
$this->context->getPostbackPayload(); /** * $key = 'datetime' | 'date' | 'time' */ $this->context->getDateTimePostbackPayload(string $key);
- get user profile
more detail see official doc
$this->context->getUserProfile();
- get streaming data(audio / video / image)
$this->context->getMessageStreamData();
- accessable attributes
$this->context->rawEvent; $this->context->eventType; $this->context->messageEventType; $this->context->useId; $this->context->botSessionId;
whchi/laravel-linebot-wrapper 适用场景与选型建议
whchi/laravel-linebot-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 157 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wrapper」 「line」 「laravel」 「chatbot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 whchi/laravel-linebot-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 whchi/laravel-linebot-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 whchi/laravel-linebot-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A PHP console tool to generate Markdown documentation from your docblocks and types hints using templates.
A minimal command-line framework built from Aura v2 packages
LINE Messaging API SDK for PHP Wrapper
gv config package
统计信息
- 总下载量: 157
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-21