Overview

Namespaces

  • LINE
    • LINEBot
      • Constant
      • Event
        • MessageEvent
        • Parser
      • Exception
      • HTTPClient
      • ImagemapActionBuilder
      • MessageBuilder
        • Imagemap
        • TemplateBuilder
      • TemplateActionBuilder

Classes

  • LINE\LINEBot
  • LINE\LINEBot\Constant\ActionType
  • LINE\LINEBot\Constant\EventSourceType
  • LINE\LINEBot\Constant\HTTPHeader
  • LINE\LINEBot\Constant\MessageType
  • LINE\LINEBot\Constant\Meta
  • LINE\LINEBot\Constant\TemplateType
  • LINE\LINEBot\Event\BaseEvent
  • LINE\LINEBot\Event\BeaconDetectionEvent
  • LINE\LINEBot\Event\FollowEvent
  • LINE\LINEBot\Event\JoinEvent
  • LINE\LINEBot\Event\LeaveEvent
  • LINE\LINEBot\Event\MessageEvent
  • LINE\LINEBot\Event\MessageEvent\AudioMessage
  • LINE\LINEBot\Event\MessageEvent\ImageMessage
  • LINE\LINEBot\Event\MessageEvent\LocationMessage
  • LINE\LINEBot\Event\MessageEvent\StickerMessage
  • LINE\LINEBot\Event\MessageEvent\TextMessage
  • LINE\LINEBot\Event\MessageEvent\VideoMessage
  • LINE\LINEBot\Event\Parser\EventRequestParser
  • LINE\LINEBot\Event\PostbackEvent
  • LINE\LINEBot\Event\UnfollowEvent
  • LINE\LINEBot\HTTPClient\Curl
  • LINE\LINEBot\HTTPClient\CurlHTTPClient
  • LINE\LINEBot\ImagemapActionBuilder\AreaBuilder
  • LINE\LINEBot\ImagemapActionBuilder\ImagemapMessageActionBuilder
  • LINE\LINEBot\ImagemapActionBuilder\ImagemapUriActionBuilder
  • LINE\LINEBot\MessageBuilder\AudioMessageBuilder
  • LINE\LINEBot\MessageBuilder\Imagemap\BaseSizeBuilder
  • LINE\LINEBot\MessageBuilder\ImagemapMessageBuilder
  • LINE\LINEBot\MessageBuilder\ImageMessageBuilder
  • LINE\LINEBot\MessageBuilder\LocationMessageBuilder
  • LINE\LINEBot\MessageBuilder\MultiMessageBuilder
  • LINE\LINEBot\MessageBuilder\StickerMessageBuilder
  • LINE\LINEBot\MessageBuilder\TemplateBuilder\ButtonTemplateBuilder
  • LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselColumnTemplateBuilder
  • LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselTemplateBuilder
  • LINE\LINEBot\MessageBuilder\TemplateBuilder\ConfirmTemplateBuilder
  • LINE\LINEBot\MessageBuilder\TemplateMessageBuilder
  • LINE\LINEBot\MessageBuilder\TextMessageBuilder
  • LINE\LINEBot\MessageBuilder\VideoMessageBuilder
  • LINE\LINEBot\Response
  • LINE\LINEBot\SignatureValidator
  • LINE\LINEBot\TemplateActionBuilder\MessageTemplateActionBuilder
  • LINE\LINEBot\TemplateActionBuilder\PostbackTemplateActionBuilder
  • LINE\LINEBot\TemplateActionBuilder\UriTemplateActionBuilder

Interfaces

  • LINE\LINEBot\HTTPClient
  • LINE\LINEBot\ImagemapActionBuilder
  • LINE\LINEBot\MessageBuilder
  • LINE\LINEBot\MessageBuilder\TemplateBuilder
  • LINE\LINEBot\TemplateActionBuilder

Exceptions

  • LINE\LINEBot\Exception\CurlExecutionException
  • LINE\LINEBot\Exception\InvalidEventRequestException
  • LINE\LINEBot\Exception\InvalidEventSourceException
  • LINE\LINEBot\Exception\InvalidSignatureException
  • LINE\LINEBot\Exception\UnknownEventTypeException
  • LINE\LINEBot\Exception\UnknownMessageTypeException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * Copyright 2016 LINE Corporation
  5:  *
  6:  * LINE Corporation licenses this file to you under the Apache License,
  7:  * version 2.0 (the "License"); you may not use this file except in compliance
  8:  * with the License. You may obtain a copy of the License at:
  9:  *
 10:  *   https://www.apache.org/licenses/LICENSE-2.0
 11:  *
 12:  * Unless required by applicable law or agreed to in writing, software
 13:  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14:  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 15:  * License for the specific language governing permissions and limitations
 16:  * under the License.
 17:  */
 18: 
 19: namespace LINE;
 20: 
 21: use LINE\LINEBot\Event\Parser\EventRequestParser;
 22: use LINE\LINEBot\HTTPClient;
 23: use LINE\LINEBot\MessageBuilder;
 24: use LINE\LINEBot\MessageBuilder\TextMessageBuilder;
 25: use LINE\LINEBot\Response;
 26: use LINE\LINEBot\SignatureValidator;
 27: 
 28: /**
 29:  * A client class of LINE Messaging API.
 30:  *
 31:  * @package LINE
 32:  */
 33: class LINEBot
 34: {
 35:     const DEFAULT_ENDPOINT_BASE = 'https://api.line.me';
 36: 
 37:     /** @var string */
 38:     private $channelSecret;
 39:     /** @var string */
 40:     private $endpointBase;
 41:     /** @var HTTPClient */
 42:     private $httpClient;
 43: 
 44:     /**
 45:      * LINEBot constructor.
 46:      *
 47:      * @param HTTPClient $httpClient HTTP client instance to use API calling.
 48:      * @param array $args Configurations.
 49:      */
 50:     public function __construct(HTTPClient $httpClient, array $args)
 51:     {
 52:         $this->httpClient = $httpClient;
 53:         $this->channelSecret = $args['channelSecret'];
 54: 
 55:         $this->endpointBase = LINEBot::DEFAULT_ENDPOINT_BASE;
 56:         if (array_key_exists('endpointBase', $args) && !empty($args['endpointBase'])) {
 57:             $this->endpointBase = $args['endpointBase'];
 58:         }
 59:     }
 60: 
 61:     /**
 62:      * Gets specified user's profile through API calling.
 63:      *
 64:      * @param string $userId The user ID to retrieve profile.
 65:      * @return Response
 66:      */
 67:     public function getProfile($userId)
 68:     {
 69:         return $this->httpClient->get($this->endpointBase . '/v2/bot/profile/' . urlencode($userId));
 70:     }
 71: 
 72:     /**
 73:      * Gets message content which is associated with specified message ID.
 74:      *
 75:      * @param string $messageId The message ID to retrieve content.
 76:      * @return Response
 77:      */
 78:     public function getMessageContent($messageId)
 79:     {
 80:         return $this->httpClient->get($this->endpointBase . '/v2/bot/message/' . urlencode($messageId) . '/content');
 81:     }
 82: 
 83:     /**
 84:      * Replies arbitrary message to destination which is associated with reply token.
 85:      *
 86:      * @param string $replyToken Identifier of destination.
 87:      * @param MessageBuilder $messageBuilder Message builder to send.
 88:      * @return Response
 89:      */
 90:     public function replyMessage($replyToken, MessageBuilder $messageBuilder)
 91:     {
 92:         return $this->httpClient->post($this->endpointBase . '/v2/bot/message/reply', [
 93:             'replyToken' => $replyToken,
 94:             'messages' => $messageBuilder->buildMessage(),
 95:         ]);
 96:     }
 97: 
 98:     /**
 99:      * Replies text message(s) to destination which is associated with reply token.
100:      *
101:      * This method receives variable texts. It can send text(s) message as bulk.
102:      *
103:      * @param string $replyToken Identifier of destination.
104:      * @param string $text Text of message.
105:      * @param string[] $extraTexts Extra text of message.
106:      * @return Response
107:      */
108:     public function replyText($replyToken, $text, ...$extraTexts)
109:     {
110:         $textMessageBuilder = new TextMessageBuilder($text, ...$extraTexts);
111:         return $this->replyMessage($replyToken, $textMessageBuilder);
112:     }
113: 
114:     /**
115:      * Sends arbitrary message to destination.
116:      *
117:      * @param string $to Identifier of destination.
118:      * @param MessageBuilder $messageBuilder Message builder to send.
119:      * @return Response
120:      */
121:     public function pushMessage($to, MessageBuilder $messageBuilder)
122:     {
123:         return $this->httpClient->post($this->endpointBase . '/v2/bot/message/push', [
124:             'to' => $to,
125:             'messages' => $messageBuilder->buildMessage(),
126:         ]);
127:     }
128: 
129:     /**
130:      * Sends arbitrary message to multi destinations.
131:      *
132:      * @param array $tos Identifiers of destination.
133:      * @param MessageBuilder $messageBuilder Message builder to send.
134:      * @return Response
135:      */
136:     public function multicast(array $tos, MessageBuilder $messageBuilder)
137:     {
138:         return $this->httpClient->post($this->endpointBase . '/v2/bot/message/multicast', [
139:             'to' => $tos,
140:             'messages' => $messageBuilder->buildMessage(),
141:         ]);
142:     }
143: 
144:     /**
145:      * Leaves from group.
146:      *
147:      * @param string $groupId Identifier of group to leave.
148:      * @return Response
149:      */
150:     public function leaveGroup($groupId)
151:     {
152:         return $this->httpClient->post($this->endpointBase . '/v2/bot/group/' . urlencode($groupId) . '/leave', []);
153:     }
154: 
155:     /**
156:      * Leaves from room.
157:      *
158:      * @param string $roomId Identifier of room to leave.
159:      * @return Response
160:      */
161:     public function leaveRoom($roomId)
162:     {
163:         return $this->httpClient->post($this->endpointBase . '/v2/bot/room/' . urlencode($roomId) . '/leave', []);
164:     }
165: 
166:     /**
167:      * Parse event request to Event objects.
168:      *
169:      * @param string $body Request body.
170:      * @param string $signature Signature of request.
171:      * @return LINEBot\Event\BaseEvent[]
172:      */
173:     public function parseEventRequest($body, $signature)
174:     {
175:         return EventRequestParser::parseEventRequest($body, $this->channelSecret, $signature);
176:     }
177: 
178:     /**
179:      * Validate request with signature.
180:      *
181:      * @param string $body Request body.
182:      * @param string $signature Signature of request.
183:      * @return bool Request is valid or not.
184:      */
185:     public function validateSignature($body, $signature)
186:     {
187:         return SignatureValidator::validateSignature($body, $this->channelSecret, $signature);
188:     }
189: }
190: 
line-bot-sdk-php API documentation generated by ApiGen