12
12
def client
13
13
@client ||= Line ::Bot ::V2 ::MessagingApi ::ApiClient . new (
14
14
channel_access_token : ENV . fetch ( "LINE_CHANNEL_ACCESS_TOKEN" ) ,
15
+ base_url : 'https://api.line-beta.me' ,
15
16
http_options : {
16
17
open_timeout : 5 ,
17
18
read_timeout : 5
@@ -22,6 +23,7 @@ def client
22
23
def blob_client
23
24
@blob_client ||= Line ::Bot ::V2 ::MessagingApi ::ApiBlobClient . new (
24
25
channel_access_token : ENV . fetch ( "LINE_CHANNEL_ACCESS_TOKEN" ) ,
26
+ base_url : 'https://api-data.line-beta.me' ,
25
27
http_options : {
26
28
open_timeout : 5 ,
27
29
read_timeout : 5
@@ -910,6 +912,57 @@ def handle_message_event(event)
910
912
911
913
reply_text ( event , "[STATS]\n #{ stats } " )
912
914
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
+
913
966
else
914
967
if ( event . message . quoted_message_id != nil )
915
968
reply_text ( event , "[ECHO]\n #{ event . message . text } Thanks you for quoting my message!" )
0 commit comments