Skip to content

Commit eb006f6

Browse files
authored
Merge pull request #267 from moririnson/feature/add-mode-at-event
mode property added to webhook event
2 parents 189c4ad + db5214a commit eb006f6

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/LINEBot/Event/BaseEvent.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ public function getType()
5353
return $this->event['type'];
5454
}
5555

56+
/**
57+
* Returns mode.
58+
*
59+
* active: The channel is active.
60+
* standby: The channel is waiting.
61+
*
62+
* @return string
63+
*/
64+
public function getMode()
65+
{
66+
return $this->event['mode'];
67+
}
68+
5669
/**
5770
* Returns timestamp of the event.
5871
*

tests/LINEBot/EventRequestParserTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class EventRequestParserTest extends TestCase
5151
"events":[
5252
{
5353
"type":"message",
54+
"mode":"active",
5455
"timestamp":12345678901234,
5556
"source":{
5657
"type":"user",
@@ -65,6 +66,7 @@ class EventRequestParserTest extends TestCase
6566
},
6667
{
6768
"type":"message",
69+
"mode":"active",
6870
"timestamp":12345678901234,
6971
"source":{
7072
"type":"group",
@@ -83,6 +85,7 @@ class EventRequestParserTest extends TestCase
8385
},
8486
{
8587
"type":"message",
88+
"mode":"active",
8689
"timestamp":12345678901234,
8790
"source":{
8891
"type":"group",
@@ -102,6 +105,7 @@ class EventRequestParserTest extends TestCase
102105
},
103106
{
104107
"type":"message",
108+
"mode":"active",
105109
"timestamp":12345678901234,
106110
"source":{
107111
"type":"room",
@@ -121,6 +125,7 @@ class EventRequestParserTest extends TestCase
121125
},
122126
{
123127
"type":"message",
128+
"mode":"active",
124129
"timestamp":12345678901234,
125130
"source":{
126131
"type":"room",
@@ -140,6 +145,7 @@ class EventRequestParserTest extends TestCase
140145
},
141146
{
142147
"type":"message",
148+
"mode":"active",
143149
"timestamp":12345678901234,
144150
"source":{
145151
"type":"user",
@@ -157,6 +163,7 @@ class EventRequestParserTest extends TestCase
157163
},
158164
{
159165
"type":"message",
166+
"mode":"active",
160167
"timestamp":12345678901234,
161168
"source":{
162169
"type":"user",
@@ -173,6 +180,7 @@ class EventRequestParserTest extends TestCase
173180
},
174181
{
175182
"type":"message",
183+
"mode":"active",
176184
"timestamp":12345678901234,
177185
"source":{
178186
"type":"user",
@@ -189,6 +197,7 @@ class EventRequestParserTest extends TestCase
189197
},
190198
{
191199
"type":"message",
200+
"mode":"active",
192201
"timestamp":12345678901234,
193202
"source":{
194203
"type":"user",
@@ -205,6 +214,7 @@ class EventRequestParserTest extends TestCase
205214
},
206215
{
207216
"type":"follow",
217+
"mode":"active",
208218
"timestamp":12345678901234,
209219
"source":{
210220
"type":"user",
@@ -214,6 +224,7 @@ class EventRequestParserTest extends TestCase
214224
},
215225
{
216226
"type":"unfollow",
227+
"mode":"active",
217228
"timestamp":12345678901234,
218229
"source":{
219230
"type":"user",
@@ -222,6 +233,7 @@ class EventRequestParserTest extends TestCase
222233
},
223234
{
224235
"type":"join",
236+
"mode":"active",
225237
"timestamp":12345678901234,
226238
"source":{
227239
"type":"user",
@@ -231,6 +243,7 @@ class EventRequestParserTest extends TestCase
231243
},
232244
{
233245
"type":"leave",
246+
"mode":"active",
234247
"timestamp":12345678901234,
235248
"source":{
236249
"type":"user",
@@ -239,6 +252,7 @@ class EventRequestParserTest extends TestCase
239252
},
240253
{
241254
"type":"postback",
255+
"mode":"active",
242256
"timestamp":12345678901234,
243257
"source":{
244258
"type":"user",
@@ -251,6 +265,7 @@ class EventRequestParserTest extends TestCase
251265
},
252266
{
253267
"type":"beacon",
268+
"mode":"active",
254269
"timestamp":12345678901234,
255270
"source":{
256271
"type":"user",
@@ -265,6 +280,7 @@ class EventRequestParserTest extends TestCase
265280
},
266281
{
267282
"type":"__unknown__",
283+
"mode":"active",
268284
"timestamp":12345678901234,
269285
"source":{
270286
"type":"user",
@@ -273,13 +289,15 @@ class EventRequestParserTest extends TestCase
273289
},
274290
{
275291
"type":"__unknown__",
292+
"mode":"active",
276293
"timestamp":12345678901234,
277294
"source":{
278295
"type":"__unknown__"
279296
}
280297
},
281298
{
282299
"type":"message",
300+
"mode":"active",
283301
"timestamp":12345678901234,
284302
"source":{
285303
"type":"user",
@@ -294,6 +312,7 @@ class EventRequestParserTest extends TestCase
294312
{
295313
"replyToken": "replytoken",
296314
"type": "message",
315+
"mode":"active",
297316
"timestamp": 1462629479859,
298317
"source": {
299318
"type": "user",
@@ -309,6 +328,7 @@ class EventRequestParserTest extends TestCase
309328
{
310329
"replyToken": "replytoken",
311330
"type": "postback",
331+
"mode":"active",
312332
"timestamp": 1501234567890,
313333
"source": {
314334
"type": "user",
@@ -324,6 +344,7 @@ class EventRequestParserTest extends TestCase
324344
{
325345
"replyToken": "replytoken",
326346
"type": "postback",
347+
"mode":"active",
327348
"timestamp": 1501234567890,
328349
"source": {
329350
"type": "user",
@@ -339,6 +360,7 @@ class EventRequestParserTest extends TestCase
339360
{
340361
"replyToken": "replytoken",
341362
"type": "postback",
363+
"mode":"active",
342364
"timestamp": 1501234567890,
343365
"source": {
344366
"type": "user",
@@ -354,6 +376,7 @@ class EventRequestParserTest extends TestCase
354376
{
355377
"replyToken": "replytoken",
356378
"type": "accountLink",
379+
"mode":"standby",
357380
"timestamp": 1501234567890,
358381
"source": {
359382
"type": "user",
@@ -367,6 +390,7 @@ class EventRequestParserTest extends TestCase
367390
{
368391
"replyToken": "replytoken",
369392
"type": "accountLink",
393+
"mode":"active",
370394
"timestamp": 1501234567890,
371395
"source": {
372396
"type": "user",
@@ -379,6 +403,7 @@ class EventRequestParserTest extends TestCase
379403
},
380404
{
381405
"type":"memberJoined",
406+
"mode":"active",
382407
"timestamp":12345678901234,
383408
"source":{
384409
"type":"group",
@@ -400,6 +425,7 @@ class EventRequestParserTest extends TestCase
400425
},
401426
{
402427
"type":"memberLeft",
428+
"mode":"active",
403429
"timestamp":12345678901234,
404430
"source":{
405431
"type":"group",
@@ -420,6 +446,7 @@ class EventRequestParserTest extends TestCase
420446
},
421447
{
422448
"type":"things",
449+
"mode":"active",
423450
"timestamp":12345678901234,
424451
"source":{
425452
"type":"user",
@@ -433,6 +460,7 @@ class EventRequestParserTest extends TestCase
433460
},
434461
{
435462
"type":"things",
463+
"mode":"active",
436464
"timestamp":12345678901234,
437465
"source":{
438466
"type":"user",
@@ -446,6 +474,7 @@ class EventRequestParserTest extends TestCase
446474
},
447475
{
448476
"type": "things",
477+
"mode":"active",
449478
"timestamp":12345678901234,
450479
"source":{
451480
"type":"user",
@@ -486,7 +515,7 @@ public function testParseEventRequest()
486515
}), ['channelSecret' => 'testsecret']);
487516
list($destination, $events) = $bot->parseEventRequest(
488517
$this::$json,
489-
'E4RwvnMZKLeGdtg+WLmGeA4DgW7e9f1Xugxl7X1KLGw=',
518+
'qsC+32XO0KUio+ScsxnvUk4t/sYfCyseYaNwi2AA7cw=',
490519
false
491520
);
492521

@@ -498,6 +527,7 @@ public function testParseEventRequest()
498527
// text
499528
$event = $events[0];
500529
$this->assertEquals(12345678901234, $event->getTimestamp());
530+
$this->assertEquals('active', $event->getMode());
501531
$this->assertTrue($event->isUserEvent());
502532
$this->assertEquals('userid', $event->getUserId());
503533
$this->assertEquals('userid', $event->getEventSourceId());
@@ -700,6 +730,7 @@ public function testParseEventRequest()
700730
$this->assertEquals('__unknown__', $event->getEventBody()['type']); // with unprocessed event body
701731
$this->assertEquals(null, $event->getReplyToken());
702732
$this->assertEquals(12345678901234, $event->getTimestamp());
733+
$this->assertEquals('active', $event->getMode());
703734
$this->assertEquals('userid', $event->getEventSourceId());
704735
$this->assertEquals('userid', $event->getUserId());
705736
$this->assertEquals(true, $event->isUserEvent());
@@ -714,6 +745,7 @@ public function testParseEventRequest()
714745
$this->assertEquals('__unknown__', $event->getEventBody()['type']); // with unprocessed event body
715746
$this->assertEquals(null, $event->getReplyToken());
716747
$this->assertEquals(12345678901234, $event->getTimestamp());
748+
$this->assertEquals('active', $event->getMode());
717749
$this->assertEquals(null, $event->getEventSourceId());
718750
$this->assertEquals(true, $event->isUnknownEvent());
719751
}
@@ -776,6 +808,7 @@ public function testParseEventRequest()
776808
/** @var AccountLinkEvent $event */
777809
$this->assertEquals('replytoken', $event->getReplyToken());
778810
$this->assertEquals(1501234567890, $event->getTimestamp());
811+
$this->assertEquals('standby', $event->getMode());
779812
$this->assertEquals("ok", $event->getResult());
780813
$this->assertEquals(true, $event->isSuccess());
781814
$this->assertEquals(false, $event->isFailed());
@@ -789,6 +822,7 @@ public function testParseEventRequest()
789822
/** @var AccountLinkEvent $event */
790823
$this->assertEquals('replytoken', $event->getReplyToken());
791824
$this->assertEquals(1501234567890, $event->getTimestamp());
825+
$this->assertEquals('active', $event->getMode());
792826
$this->assertEquals("failed", $event->getResult());
793827
$this->assertEquals(false, $event->isSuccess());
794828
$this->assertEquals(true, $event->isFailed());
@@ -802,6 +836,7 @@ public function testParseEventRequest()
802836
/** @var MemberJoinEvent $event */
803837
$this->assertEquals('replytoken', $event->getReplyToken());
804838
$this->assertEquals(12345678901234, $event->getTimestamp());
839+
$this->assertEquals('active', $event->getMode());
805840
$members = $event->getMembers();
806841
$this->assertEquals(["type" => "user", "userId" => "U4af4980629..."], $members[0]);
807842
$this->assertEquals(["type" => "user", "userId" => "U91eeaf62d9..."], $members[1]);
@@ -814,6 +849,7 @@ public function testParseEventRequest()
814849
/** @var MemberLeaveEvent $event */
815850
$this->assertTrue($event->getReplyToken() === null);
816851
$this->assertEquals(12345678901234, $event->getTimestamp());
852+
$this->assertEquals('active', $event->getMode());
817853
$members = $event->getMembers();
818854
$this->assertEquals(["type" => "user", "userId" => "U4af4980629..."], $members[0]);
819855
$this->assertEquals(["type" => "user", "userId" => "U91eeaf62d9..."], $members[1]);

0 commit comments

Comments
 (0)