Giter Club home page Giter Club logo

laravel-line-sdk's Introduction

LINE SDK for Laravel

packagist tests Maintainability Test Coverage Codacy Badge

Features

  • Working with Laravel Event System. Including Webhook routing and controller.
  • Extensible Bot Client.
  • Working with Laravel Notification System(LINE Notify)
  • Including Socialite drivers(LINE Login, LINE Notify)

Requirements

  • PHP >= 7.3
  • Laravel >= 6.0

Versioning

  • Basic : semver
  • Drop old PHP or Laravel version : +0.1. composer should handle it well.
  • Support only latest major version (master branch), but you can PR to old branches.

Installation

composer require revolution/laravel-line-sdk

Configuration

.env

Set up in LINE Developers console. https://developers.line.biz/

Create two channels Messaging API and LINE Login.

  • Messaging API : Get Channel access token (long-lived) and Channel secret. Set Webhook URL
  • LINE Login : Get Channel ID and Channel secret. Set Callback URL
LINE_BOT_CHANNEL_TOKEN=
LINE_BOT_CHANNEL_SECRET=

LINE_LOGIN_CLIENT_ID=
LINE_LOGIN_CLIENT_SECRET=
LINE_LOGIN_REDIRECT=

LINE_NOTIFY_CLIENT_ID=
LINE_NOTIFY_CLIENT_SECRET=
LINE_NOTIFY_REDIRECT=
LINE_NOTIFY_PERSONAL_ACCESS_TOKEN=

Publishing(Optional)

php artisan vendor:publish --tag=line-config

Short Facade(Optional)

Recent Laravel uses a full namespace.

use Revolution\Line\Facades\Bot;

Bot::replyText();

If you want to use the short Facade, you can add it manually in config/app.php.

    'aliases' => [
        'LINE' => Revolution\Line\Facades\Bot::class,
    ],
use LINE;

LINE::replyText();

Quick Start

Prepare

  • Create Messaging API channel in LINE Developers console.
  • Get Channel access token (long-lived), Channel secret and QR code.
  • A web server that can receive webhooks from LINE. Not possible on a normal local server.

Create new Laravel project

composer create-project --prefer-dist laravel/laravel line-bot "8.*"
cd ./line-bot
composer require revolution/laravel-line-sdk

Edit .env

LINE_BOT_CHANNEL_TOKEN=
LINE_BOT_CHANNEL_SECRET=

Add shouldDiscoverEvents() to app/Providers/EventServiceProvider

/**
 * Determine if events and listeners should be automatically discovered.
 *
 * @return bool
 */
public function shouldDiscoverEvents()
{
    return true;
}

Publishing default Listeners

php artisan vendor:publish --tag=line-listeners-message

Deploy to web server

  • Set Webhook URL in LINE Developers console. https://example.com/line/webhook
  • Verify Webhook URL.

Add bot as a friend.

  • Using QR code.

Send test message

Bot returns same message.

Documents

Demo

https://github.com/kawax/laravel-line-project

LICENSE

MIT

laravel-line-sdk's People

Contributors

kawax avatar codacy-badger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.