Skip to content

Commit 29a38e7

Browse files
committed
Add an example of narrowcast
1 parent 7eca519 commit 29a38e7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

examples/v2/kitchensink/app.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,57 @@ def handle_message_event(event)
910910

911911
reply_text(event, "[STATS]\n#{stats}")
912912

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

0 commit comments

Comments
 (0)