PHP code example of syllistudio / line-messaging

1. Go to this page and download the library: Download syllistudio/line-messaging library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

syllistudio / line-messaging example snippets


return [
	/*
     * You need to define your channel secret and access token in your environment variables
     */
    'channel_secret' => env('LINEBOT_CHANNEL_SECRET'),
    'channel_access_token' => env('LINEBOT_CHANNEL_ACCESS_TOKEN'),
];




namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Syllistudio\LineMessaging\LineWebhookReceiver;

class YourControllerName extends Controller
{
	use LineWebhookReceiver;

	public function onMessageEvent($replyToken, $source, $message, $timestamp) {
		// do your work here
	}

	public function onFollowEvent($replyToken, $source, $timestamp) {
		// do your work here
	}

	public function onUnfollowEvent($source, $timestamp) {
		// do your work here
	}

	public function onJoinEvent($replyToken, $source, $timestamp) {
		// do your work here
	}

	public function onLeaveEvent($source, $timestamp) {
		// do your work here
	}



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Syllistudio\LineMessaging\LineWebhookReceiver;
use Syllistudio\LineMessaging\LineMessaging;
use Syllistudio\LineMessaging\MessageBuilder\TextMessageBuilder;

class LineBotController extends Controller
{
	use LineWebhookReceiver, LineMessaging;

	public function onJoinEvent($replyToken, $source, $timestamp) {
		$messages = new TextMessageBuilder("You're welcome");
		$response = $this->replyMessage($replyToken, $messages);
	}



namespace App;

use Illuminate\Database\Eloquent\Model;
use Syllistudio\LineMessaging\LineMessaging;
use Syllistudio\LineMessaging\MessageBuilder\TextMessageBuilder;

class ChatBot extends Model
{
	use LineMessaging;

	public sendMessage() {
		$messages = new TextMessageBuilder("You're so sexy Lady");
		$response = $this->pushMessage($userId, $messages);
	}

php artisan vendor:publish --provider="Syllistudio\LineMessaging\LineMessagingProvider" --tag="config"