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\LINEBot\Event;
 20: 
 21: use LINE\LINEBot\Constant\EventSourceType;
 22: use LINE\LINEBot\Exception\InvalidEventSourceException;
 23: 
 24: /**
 25:  * Base class of each events.
 26:  *
 27:  * Don't instantiate this class individually.
 28:  *
 29:  * @package LINE\LINEBot\Event
 30:  */
 31: class BaseEvent
 32: {
 33:     /** @var array */
 34:     protected $event;
 35: 
 36:     /**
 37:      * BaseEvent constructor.
 38:      *
 39:      * @param array $event
 40:      */
 41:     public function __construct($event)
 42:     {
 43:         $this->event = $event;
 44:     }
 45: 
 46:     /**
 47:      * Returns event type.
 48:      *
 49:      * @return string
 50:      */
 51:     public function getType()
 52:     {
 53:         return $this->event['type'];
 54:     }
 55: 
 56:     /**
 57:      * Returns timestamp of the event.
 58:      *
 59:      * @return int
 60:      */
 61:     public function getTimestamp()
 62:     {
 63:         return $this->event['timestamp'];
 64:     }
 65: 
 66:     /**
 67:      * Returns reply token of the event.
 68:      *
 69:      * @return string|null
 70:      */
 71:     public function getReplyToken()
 72:     {
 73:         return array_key_exists('replyToken', $this->event) ? $this->event['replyToken'] : null;
 74:     }
 75: 
 76:     /**
 77:      * Returns the event is user's one or not.
 78:      *
 79:      * @return bool
 80:      */
 81:     public function isUserEvent()
 82:     {
 83:         return $this->event['source']['type'] === EventSourceType::USER;
 84:     }
 85: 
 86:     /**
 87:      * Returns the event is group's one or not.
 88:      *
 89:      * @return bool
 90:      */
 91:     public function isGroupEvent()
 92:     {
 93:         return $this->event['source']['type'] === EventSourceType::GROUP;
 94:     }
 95: 
 96:     /**
 97:      * Returns the event is room's one or not.
 98:      *
 99:      * @return bool
100:      */
101:     public function isRoomEvent()
102:     {
103:         return $this->event['source']['type'] === EventSourceType::ROOM;
104:     }
105: 
106:     /**
107:      * Returns user ID of the event.
108:      *
109:      * @return string|null
110:      * @throws InvalidEventSourceException Raise when called with non user type event.
111:      */
112:     public function getUserId()
113:     {
114:         if (!$this->isUserEvent()) {
115:             throw new InvalidEventSourceException('This event source is not a user type');
116:         }
117:         return array_key_exists('userId', $this->event['source'])
118:             ? $this->event['source']['userId']
119:             : null;
120:     }
121: 
122:     /**
123:      * Returns group ID of the event.
124:      *
125:      * @return string|null
126:      * @throws InvalidEventSourceException Raise when called with non group type event.
127:      */
128:     public function getGroupId()
129:     {
130:         if (!$this->isGroupEvent()) {
131:             throw new InvalidEventSourceException('This event source is not a group type');
132:         }
133:         return array_key_exists('groupId', $this->event['source'])
134:             ? $this->event['source']['groupId']
135:             : null;
136:     }
137: 
138:     /**
139:      * Returns room ID of the event.
140:      *
141:      * @return string|null
142:      * @throws InvalidEventSourceException Raise when called with non room type event.
143:      */
144:     public function getRoomId()
145:     {
146:         if (!$this->isRoomEvent()) {
147:             throw new InvalidEventSourceException('This event source is not a room type');
148:         }
149:         return array_key_exists('roomId', $this->event['source'])
150:             ? $this->event['source']['roomId']
151:             : null;
152:     }
153: 
154:     /**
155:      * Returns the identifier of the event source that associated with event source type
156:      * (i.e. userId, groupId or roomId).
157:      *
158:      * @return null|string
159:      *
160:      * @throws InvalidEventSourceException Raise when event source type is invalid
161:      */
162:     public function getEventSourceId()
163:     {
164:         if ($this->isUserEvent()) {
165:             return $this->getUserId();
166:         }
167: 
168:         if ($this->isGroupEvent()) {
169:             return $this->getGroupId();
170:         }
171: 
172:         if ($this->isRoomEvent()) {
173:             return $this->getRoomId();
174:         }
175: 
176:         throw new InvalidEventSourceException('Invalid event source type, neither `user`, `room` nor `group`');
177:     }
178: }
179: 
line-bot-sdk-php API documentation generated by ApiGen