Download the PHP package ycs77/laravel-line-bot without Composer

On this page you can find all versions of the php package ycs77/laravel-line-bot. 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 laravel-line-bot

Laravel Line Bot

Latest Version on Packagist CI Build Status Style CI Build Status Codecov Status Total Downloads

開發中

在 Laravel 中快速開發 Line Bot

安裝前準備

安裝

使用 Composer 安裝:

發布設定檔案 (選用):

設定 Line Bot 金鑰到 .env 檔裡 (在剛才新增的 Messaging API 裡產生):

執行安裝指令,產生 Laravel LineBot 所需的檔案:

增加 webhook 路徑到 Laravel 的 VerifyCsrfToken Middleware 中的 except 陣列,以禁用 CSRF 檢查:

app/Http/Middleware/VerifyCsrfToken.php

最後,開啟 Line Developers,關閉「歡迎訊息」和「自動回應訊息」,並開啟和設定 Webhook 網址:

Lumen

如果使用 Lumen,就需要別的方式來註冊。使用 Composer 安裝完套件後,首先先把 config 檔案複製到 config/linebot.php (若 config 資料夾不存在請自行創建),然後開啟 bootstrap/app.php,新增下方程式碼來註冊。

bootstrap/app.php

最後,執行 php artisan linebot:install 和在 Line Developers 設定 webhook 網址即可。

使用

首先先開啟 routes/linebot.php,在 Laravel LineBot 中所有的監聽訊息及回傳訊息的程式,都是在這個檔案中:

routes/linebot.php

在這個範例中,如果用戶傳送 時,會自動回應 你好

監聽事件 (Event)

最基本的事件是監聽文字訊息事件,當然也可以使用 {name} 的替代文字來擷取用戶傳送的部分文字,並轉換成變數:

用法參考自 Botman

若沒有匹配成功任何訊息,將會回覆預設回應:

除了文字訊息事件,也可以監聽圖片訊息事件、跟隨事件等:

這些功能目前尚未完成

全部可以監聽的事件:

回應 (Reply)

文字訊息:

按鈕選單:

行動按鈕使用方式請參考 行動按鈕 (Action)

全部可以使用的回覆訊息類型:

全部可以使用的模板訊息類型:

快速回覆 (Quick Reply)

行動按鈕使用方式請參考 行動按鈕 (Action)

快速回覆無法使用 Url Action

行動按鈕 (Action)

行動按鈕需搭配 Quick Reply 和 Template 訊息使用。以下為使用範例:

全部可以使用的行動按鈕:

用戶資訊

取得 Line 用戶資料

使用 LineBot::profile() 即可取得當前用戶的資訊:

可以取得的用戶資訊:

整合 Eloquent

這個功能預設是關閉的,需要先把 LineBot 設置中的 user.enabled 改成 true,才可以開始使用 Eloquent:

還可以依需求調整 model (用戶模型) 及 id (辨識用戶的欄位名稱)。

config/linebot.php

在 Lumen 中需要開啟 bootstrap/app.php 取消 $app->withEloquent(); 的註釋

然後將 users 資料表修改成以下欄位,和運行 php artisan migrate

database/migrations/2014_10_12_000000_create_users_table.php

修改 User Model:

app/User.php

最後,就可以使用 LineBot::user() 來取得用戶模型了:

Rich Menu

新增 Rich Menu 和上傳圖片

詳細配置請參考 Line 官方說明:Using rich menus

準備一張 Rich Menu 的圖片

config/linebot.php 中設定 rich_menu 的設定 (建議可以使用 LINE Bot Designer 來產生)。每個 Rich Menu 都要設定對應的 key (跟 Line 官方沒有關係,只是用來辨識 Rich Menu 而已),例如範例將 key 設定為 rich_menu_1

routes/linebot.php

執行 linebot:richmenu:create 命令新增 Rich Menu 和上傳圖片,參數需要 Rich Menu 的 key (上方 config 設定) 和圖片路徑 (範例圖片路徑為 "public/image.jpg"):

查看 Rich Menu

查看全部 Rich Menu ID:

查看全部 Rich Menu 的原始資料:

刪除 Rich Menu

刪除指定 Rich Menu ID:

刪除全部 Rich Menu:

調用 LINE 官方 SDK 的 API

使用 LineBot::base() 即可調用 LINE 官方 SDK 的 API:

參考

測試

運行測試:

運行指令產生測試覆蓋率報告,報告產生在 build/coverage-report

License

Under the MIT license.


All versions of laravel-line-bot with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
facade/ignition-contracts Version ^1.0
illuminate/console Version ~5.7|~5.8|^6.0
illuminate/contracts Version ~5.7|~5.8|^6.0
illuminate/database Version ~5.7|~5.8|^6.0
illuminate/http Version ~5.7|~5.8|^6.0
illuminate/support Version ~5.7|~5.8|^6.0
linecorp/line-bot-sdk Version ^4.1
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 ycs77/laravel-line-bot contains the following files

Loading the files please wait ....