Skip to content

Commit 67e181e

Browse files
committed
Add an example of narrowcast
1 parent 7eca519 commit 67e181e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/v2/kitchensink/app.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def client
1313
@client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
1414
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
15+
base_url: 'https://api.line-beta.me',
1516
http_options: {
1617
open_timeout: 5,
1718
read_timeout: 5
@@ -22,6 +23,7 @@ def client
2223
def blob_client
2324
@blob_client ||= Line::Bot::V2::MessagingApi::ApiBlobClient.new(
2425
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
26+
base_url: 'https://api-data.line-beta.me',
2527
http_options: {
2628
open_timeout: 5,
2729
read_timeout: 5
@@ -910,6 +912,57 @@ def handle_message_event(event)
910912

911913
reply_text(event, "[STATS]\n#{stats}")
912914

915+
when 'narrowcast'
916+
request = Line::Bot::V2::MessagingApi::NarrowcastRequest.new(
917+
messages: [
918+
Line::Bot::V2::MessagingApi::TextMessage.new(text: 'Hello, this is a narrowcast message')
919+
],
920+
filter: Line::Bot::V2::MessagingApi::Filter.new(
921+
demographic: Line::Bot::V2::MessagingApi::OperatorDemographicFilter.new(
922+
_or: [
923+
Line::Bot::V2::MessagingApi::OperatorDemographicFilter.new(
924+
_and: [
925+
Line::Bot::V2::MessagingApi::AgeDemographicFilter.new(
926+
gte: 'age_20',
927+
lte: 'age_60'
928+
),
929+
Line::Bot::V2::MessagingApi::AppTypeDemographicFilter.new(
930+
one_of: ['ios']
931+
)
932+
]
933+
),
934+
Line::Bot::V2::MessagingApi::OperatorDemographicFilter.new(
935+
_and: [
936+
Line::Bot::V2::MessagingApi::GenderDemographicFilter.new(
937+
one_of: ['female']
938+
),
939+
Line::Bot::V2::MessagingApi::AreaDemographicFilter.new(
940+
one_of: %w(jp_08 jp_09 jp_10 jp_11 jp_12 jp_13 jp_14)
941+
),
942+
]
943+
)
944+
]
945+
)
946+
)
947+
)
948+
_body, _status_code, headers = client.narrowcast_with_http_info(narrowcast_request: request)
949+
request_id = headers['x-line-request-id']
950+
951+
reply_text(event, "Narrowcast requested, requestId: #{request_id}")
952+
953+
client.show_loading_animation(show_loading_animation_request: Line::Bot::V2::MessagingApi::ShowLoadingAnimationRequest.new(
954+
chat_id: event.source.user_id
955+
))
956+
sleep 5
957+
958+
response = client.get_narrowcast_progress(request_id: request_id)
959+
client.push_message(push_message_request: Line::Bot::V2::MessagingApi::PushMessageRequest.new(
960+
to: event.source.user_id,
961+
messages: [
962+
Line::Bot::V2::MessagingApi::TextMessage.new(text: "Narrowcast status: #{response}")
963+
]
964+
))
965+
913966
else
914967
if (event.message.quoted_message_id != nil)
915968
reply_text(event, "[ECHO]\n#{event.message.text} Thanks you for quoting my message!")

0 commit comments

Comments
 (0)