Skip to content

Magic-PHP/Line-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

line-bot-sdk-php

Build Status Latest Stable Version License

SDK of the LINE BOT API Trial for PHP.

Installation

The LINE BOT API SDK can be installed with Composer.

composer require linecorp/line-bot-sdk

Note

If you use PHP 5.5 or lower, please use this SDK with polyfill of hash_equals().

e.g.

Methods

Constructor

new LINEBot(array $args, HTTPClient $client)

Create a LINEBot constructor.

$config = [
    'channelId' => '<your channel ID>',
    'channelSecret' => '<your channel secret>',
    'channelMid' => '<your channel MID>',
];
$bot = new LINEBot($config, new GuzzleHTTPClient($config));

Sending Message

LINEBot#sendText($mid, $text)

Send a text message to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_text

$res = $bot->sendText(['TARGET_MID'], 'Message');

LINEBot#sendImage($mid, $imageURL, $previewURL)

Send an image to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_image

$bot->sendImage(['TARGET_MID'] 'http://example.com/image.jpg', 'http://example.com/preview.jpg');

LINEBot#sendVideo($mid, $videoURL, $previewImageURL)

Send a video to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_video

$bot->sendVideo(['TARGET_MID'], 'http://example.com/video.mp4', 'http://example.com/video_preview.jpg');

LINEBot#sendAudio($mid, $audioURL, $durationMillis)

Send a voice message to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_audio

$bot->sendAudio(['TARGET_MID'], 'http://example.com/audio.m4a', 5000);

LINEBot#sendLocation($mid, $text, $latitude, $longitude)

Send location information to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_location

$bot->sendLocation(['TARGET_MID'], '2 Chome-21-1 Shibuya Tokyo 150-0002, Japan', 35.658240, 139.703478);

LINEBot#sendSticker($mid, $stkid, $stkpkgid, $stkver)

Send a sticker to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_sticker

$bot->sendSticker(['TARGET_MID'], 1, 1, 100);

LINEBot#sendRichMessage($mid, $imageURL, $altText, Markup $markup)

Send a rich message to mid(s).
https://developers.line.me/bot-api/api-reference#sending_rich_content_message_request

$markup = (new Markup(1040))
    ->setAction('SOMETHING', 'something', 'https://line.me')
    ->addListener('SOMETHING', 0, 0, 1040, 1040);
$bot->sendRichMessage(['TARGET_MID'], 'https://example.com/image.jpg', "Alt text", $markup);

LINEBot#sendMultipleMessages($mid, MultipleMessages $multipleMessages)

Send multiple messages to mids(s).
https://developers.line.me/bot-api/api-reference#sending_multiple_messages_request

$multipleMessages = (new \LINE\LINEBot\Message\MultipleMessages())
    ->addText('hello!')
    ->addImage('http://example.com/image.jpg', 'http://example.com/preview.jpg')
    ->addAudio('http://example.com/audio.m4a', 6000)
    ->addVideo('http://example.com/video.mp4', 'http://example.com/video_preview.jpg')
    ->addLocation('2 Chome-21-1 Shibuya Tokyo 150-0002, Japan', 35.658240, 139.703478)
    ->addSticker(1, 1, 100);
$bot->sendMultipleMessages(['TARGET_MID'], $multipleMessages);

Getting Message Contents

LINEBot#getMessageContent($messageId, $fileHandler = null)

Retrieve the content of a user's message which is an image or video file.
https://developers.line.me/bot-api/api-reference#getting_message_content_request

$content = $bot->getMessageContent('1234567890');

LINEBot#getMessageContentPreview($messageId, $fileHandler = null)

Retrieve thumbnail preview of the message.
https://developers.line.me/bot-api/api-reference#getting_message_content_preview_request

$content = $bot->getMessageContentPreview('1234567890');

Getting User Profile

LINEBot#getUserProfile($mid)

Retrieve user profile(s) that is associated with mid(s).
https://developers.line.me/bot-api/api-reference#getting_user_profile_information_request

$profile = $bot->getUserProfile(['TARGET_MID']);

Signature Validation

LINEBot#validateSignature($json, $signature)

Validate signature.

$isValid = $bot->validateSignature($requestJSON, 'expected-signature');

Run Tests

Execute with phpunit

composer install
./vendor/bin/phpunit ./tests

Execute make test

composer install
make

Hints

You can find some implementation examples here.

License

Copyright 2016 LINE Corporation

LINE Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

See Also

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published