SDK of the LINE BOT API Trial for PHP.
The LINE BOT API SDK can be installed with Composer.
composer require linecorp/line-bot-sdk
If you use PHP 5.5 or lower, please use this SDK with polyfill of hash_equals().
e.g.
Create a LINEBot
constructor.
$config = [
'channelId' => '<your channel ID>',
'channelSecret' => '<your channel secret>',
'channelMid' => '<your channel MID>',
];
$bot = new LINEBot($config, new GuzzleHTTPClient($config));
Send a text message to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_text
$res = $bot->sendText(['TARGET_MID'], 'Message');
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');
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');
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);
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);
Send a sticker to mid(s).
https://developers.line.me/bot-api/api-reference#sending_message_sticker
$bot->sendSticker(['TARGET_MID'], 1, 1, 100);
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);
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);
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');
Retrieve thumbnail preview of the message.
https://developers.line.me/bot-api/api-reference#getting_message_content_preview_request
$content = $bot->getMessageContentPreview('1234567890');
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']);
Validate signature.
$isValid = $bot->validateSignature($requestJSON, 'expected-signature');
composer install
./vendor/bin/phpunit ./tests
composer install
make
You can find some implementation examples here.
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.