Skip to content

Commit 31e70d9

Browse files
authored
Merge pull request #284 from Sean0628/feature/audience_match_api
feat: support the Audience Match API
2 parents 4c47cdb + 056a97e commit 31e70d9

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

lib/line/bot/client.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,39 @@ def get_narrowcast_message_status(request_id)
11741174
get(endpoint, endpoint_path, credentials)
11751175
end
11761176

1177+
# Send messages to multiple users using phone numbers.
1178+
#
1179+
# @param to [Array, String] Array of hashed phone numbers.
1180+
# @param messages [Hash, Array] Message Objects.
1181+
# @param headers [Hash] HTTP Headers.
1182+
# @param payload [Hash] Additional request body.
1183+
#
1184+
# @return [Net::HTTPResponse]
1185+
1186+
def multicast_by_phone_numbers(to, messages, headers: {}, payload: {})
1187+
channel_token_required
1188+
1189+
to = [to] if to.is_a?(String)
1190+
messages = [messages] if messages.is_a?(Hash)
1191+
1192+
endpoint_path = 'bot/ad/multicast/phone'
1193+
payload = payload.merge({ to: to, messages: messages }).to_json
1194+
post(oauth_endpoint, endpoint_path, payload, credentials.merge(headers))
1195+
end
1196+
1197+
# Get the delivery result of the message delivered in Send message using phone number. (`#multicast_by_phone_numbers`)
1198+
#
1199+
# @param date [String] Date the message was sent in UTC+9 with `yyyyMMdd` format.
1200+
#
1201+
# @return [Net::HTTPResponse]
1202+
1203+
def get_delivery_result_sent_by_phone_numbers(date)
1204+
channel_token_required
1205+
1206+
endpoint_path = "/bot/message/delivery/ad_phone?date=#{date}"
1207+
get(endpoint, endpoint_path, credentials)
1208+
end
1209+
11771210
# Fetch data, get content of specified URL.
11781211
#
11791212
# @param endpoint_base [String]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require 'spec_helper'
2+
require 'webmock/rspec'
3+
4+
DELIVERY_RESULT_CONTENT = <<~"EOS"
5+
{
6+
"status": "ready",
7+
"success": 10000
8+
}
9+
EOS
10+
11+
describe Line::Bot::Client do
12+
describe '#multicast_by_phone_numbers' do
13+
before do
14+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + 'bot/ad/multicast/phone'
15+
stub_request(:post, uri_template).to_return { |request| { body: '{}', status: 200 } }
16+
end
17+
18+
let(:client) do
19+
Line::Bot::Client.new do |config|
20+
config.channel_token = 'channel_token'
21+
end
22+
end
23+
let(:phone_numbers) { ['818000000000', '817000000000'].map { Digest::SHA256.hexdigest(_1) } }
24+
let(:message) do
25+
{
26+
type: 'text',
27+
text: 'Hello, world'
28+
}
29+
end
30+
31+
context 'normal scenario' do
32+
it 'pushes the message' do
33+
response = client.multicast_by_phone_numbers(phone_numbers, message)
34+
35+
expect(response).to be_a(Net::HTTPOK)
36+
expect(response.body).to eq('{}')
37+
end
38+
end
39+
40+
context 'with additional payload' do
41+
it 'pushes the message' do
42+
response = client.multicast_by_phone_numbers(phone_numbers, message, payload: { notificationDisabled: true })
43+
44+
expect(response).to be_a(Net::HTTPOK)
45+
expect(response.body).to eq('{}')
46+
end
47+
end
48+
end
49+
50+
describe '#get_delivery_result_sent_by_phone_numbers' do
51+
before do
52+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/ad_phone?date={date}'
53+
stub_request(:get, uri_template).to_return { |request| { body: DELIVERY_RESULT_CONTENT, status: 200 } }
54+
end
55+
56+
let(:client) do
57+
Line::Bot::Client.new do |config|
58+
config.channel_token = 'channel_token'
59+
end
60+
end
61+
62+
it 'gets the delivery result' do
63+
response = client.get_delivery_result_sent_by_phone_numbers('20230101')
64+
65+
expect(response).to be_a(Net::HTTPOK)
66+
expect(response.body).to eq(DELIVERY_RESULT_CONTENT)
67+
end
68+
end
69+
end

0 commit comments

Comments
 (0)