{"id":22369693,"url":"https://github.com/mesak/laravel-linebot","last_synced_at":"2025-12-31T14:20:37.655Z","repository":{"id":65557592,"uuid":"594672267","full_name":"mesak/laravel-linebot","owner":"mesak","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-15T18:45:47.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T16:24:45.761Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mesak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-29T09:27:02.000Z","updated_at":"2023-02-14T09:03:18.000Z","dependencies_parsed_at":"2023-02-28T10:32:05.137Z","dependency_job_id":null,"html_url":"https://github.com/mesak/laravel-linebot","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"fcaf602f4cd72dfaebe367c4def9a9c8a325c4e1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mesak/laravel-linebot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesak%2Flaravel-linebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesak%2Flaravel-linebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesak%2Flaravel-linebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesak%2Flaravel-linebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesak","download_url":"https://codeload.github.com/mesak/laravel-linebot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesak%2Flaravel-linebot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265849023,"owners_count":23838198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T19:27:31.798Z","updated_at":"2025-12-31T14:20:37.611Z","avatar_url":"https://github.com/mesak.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel LINEBOT\n\n採用 laravel response 的方式來回應 LINEBOT 的訊息\n\n## 安裝\n\n```bash\ncomposer require mesak/laravel-linebot\n```\n\n## 設定檔替換\n\n將設定檔複製到專案中\n\n```bash\nphp artisan vendor:publish --tag=mesak-linebot.config --force\n```\n\n修改 `config/linebot.php` 中的設定\n\n```php\n    'listener' =\u003e 'App\\Listeners\\LineBotListener',\n```\n\n\n## 使用\n\n利用標準檔案 `App\\Listeners\\LineBotListener` 來建立 LINEBOT 的 Listener\n\n```bash\nphp artisan vendor:publish --tag=mesak-linebot.listener\n```\n\n`LineBotListener.php`\n\nLINEBOT 預設的事件：\n\n- onMessage\n- onUnsend\n- onFollow\n- onUnfollow\n- onJoin\n- onLeave\n- onPostback\n- onVideoPlayComplete\n- onBeacon\n- onAccountLink\n- onMemberJoined\n- onMemberLeft\n- onThings\n\n\n## 設定\n\n在 `.env` 中加入\n\n```env\nLINE_CLIENT_ID=xxxxxxxx\nLINE_CLIENT_SECRET=xxxxxxxx\n```\n\n在 route 中加入，對應 line webhook 的 post 事件\n\n```php\nuse Illuminate\\Http\\Request;\n\nRoute::post('/line', function (Request $request) {\n    return \\Facades\\Mesak\\LineBot\\Contracts\\Bot::handle($request);\n});\n```\n\n\n### Event 事件\n\n套件利用處理 Request 把內容塞入 `Mesak\\LineBot\\Events\\MessageEvent` 中，利用 BotEventSubscribe 發起對話事件，最後回傳 `Mesak\\LineBot\\Actions\\BaseAction` 的事件來處理需要的回應\n\n\n### 擴充\n\n如果需要擴充 LINEBOT 的功能，可以在 `App\\Providers\\AppServiceProvider` 中的 register 加入 `\\Mesak\\LineBot\\Contracts\\Bot::class` 合約綁定\n\n```php\n\n    $this-\u003eapp-\u003esingleton(\\Mesak\\LineBot\\Contracts\\Bot::class, function ($app) {\n        return tap(new \\App\\Services\\EntityBot(config('linebot') , $app['events']) ,function($bot){\n            $bot-\u003eboot();\n        });\n    });\n\n```\n\n自訂 `EntityBot` 類別\n\n```php\n\u003c?php\n\nnamespace App\\Services\\LineBot;\n\nuse Mesak\\LineBot\\EntityBot as BaseEntityBot;\nuse Mesak\\LineBot\\Contracts\\Bot as BotContract;\n\nclass EntityBot extends BaseEntityBot implements BotContract\n{\n  //do something...\n}\n\n```\n\n如果要從外部呼叫 Bot，可以使用 Facades 靜態介面\n\n舉例：\n```\n$response = \\Facades\\Mesak\\LineBot\\Contracts\\Bot::getProfile($userId);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesak%2Flaravel-linebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesak%2Flaravel-linebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesak%2Flaravel-linebot/lists"}