PHP code example of ratiw / line-messaging

1. Go to this page and download the library: Download ratiw/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/ */

    

ratiw / line-messaging example snippets


use Ratiw\LineMessaging\LineMessaging;
use Illuminate\Http\Client\Response;

// simple text message to a user
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('Hi, this is a test message.');

// sticker message to a group chat
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->sticker('6359', '11069851');

// text with emojis
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->text('Hey, $ LINE emoji $', [
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '009'],
        ['productId' => '5ac21d59031a6752fb806d5d', 'emojiId' => '004'],
    ]);

// send a text message to a user
LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('Hello, world!');

// send a text message to a group chat
LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->text('Hello, world!');

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('$ Happy birthday! $', [
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '007'],
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '009'],
    ]);

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->sticker('6359', '11069851');

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->image('https://example.com/image.jpg', 'https://example.com/image_preview.jpg');

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->video('https://example.com/video.mp4', 'https://example.com/video_preview.jpg', 'TRACKING_ID');

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->audio('https://example.com/video.m4a', 50000);

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->location('MOCA Bangkok', '499 Kamphaeng Phet 6 Rd, Lat Yao, Chatuchak, Bangkok 10900', 13.853197788942376, 100.56302862528158);