Skip to content

Commit 82e4af0

Browse files
authored
Merge branch 'master' into fix_template_message/47
2 parents 2f6caa8 + 6987d93 commit 82e4af0

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/LINEBot.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ public function pushMessage($to, MessageBuilder $messageBuilder)
126126
]);
127127
}
128128

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+
129144
/**
130145
* Leaves from group.
131146
*

tests/LINEBot/MulticastTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2017 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\Tests\LINEBot;
20+
21+
use LINE\LINEBot;
22+
use LINE\LINEBot\Constant\MessageType;
23+
use LINE\LINEBot\MessageBuilder\TextMessageBuilder;
24+
use LINE\Tests\LINEBot\Util\DummyHttpClient;
25+
26+
class MulticastTest extends \PHPUnit_Framework_TestCase
27+
{
28+
public function testMulticast()
29+
{
30+
$mock = function ($testRunner, $httpMethod, $url, $data) {
31+
/** @var \PHPUnit_Framework_TestCase $testRunner */
32+
$testRunner->assertEquals('POST', $httpMethod);
33+
$testRunner->assertEquals('https://api.line.me/v2/bot/message/multicast', $url);
34+
35+
$testRunner->assertEquals(['DESTINATION1', 'DESTINATION2'], $data['to']);
36+
$testRunner->assertEquals(1, count($data['messages']));
37+
$testRunner->assertEquals(MessageType::TEXT, $data['messages'][0]['type']);
38+
$testRunner->assertEquals('test text', $data['messages'][0]['text']);
39+
40+
return ['status' => 200];
41+
};
42+
$bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']);
43+
$res = $bot->multicast(
44+
['DESTINATION1', 'DESTINATION2'],
45+
new TextMessageBuilder("test text")
46+
);
47+
48+
$this->assertEquals(200, $res->getHTTPStatus());
49+
$this->assertTrue($res->isSucceeded());
50+
$this->assertEquals(200, $res->getJSONDecodedBody()['status']);
51+
}
52+
}

0 commit comments

Comments
 (0)