File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,27 @@ def multicast(to, messages)
131
131
request . post
132
132
end
133
133
134
+ # Broadcast messages to users
135
+ #
136
+ # @param messages [Hash or Array]
137
+ #
138
+ # @return [Net::HTTPResponse]
139
+ def broadcast ( messages )
140
+ raise Line ::Bot ::API ::InvalidCredentialsError , 'Invalidates credentials' unless credentials?
141
+
142
+ messages = [ messages ] if messages . is_a? ( Hash )
143
+
144
+ request = Request . new do |config |
145
+ config . httpclient = httpclient
146
+ config . endpoint = endpoint
147
+ config . endpoint_path = '/bot/message/broadcast'
148
+ config . credentials = credentials
149
+ config . messages = messages
150
+ end
151
+
152
+ request . post
153
+ end
154
+
134
155
def leave_group ( group_id )
135
156
raise Line ::Bot ::API ::InvalidCredentialsError , 'Invalidates credentials' unless credentials?
136
157
Original file line number Diff line number Diff line change 76
76
} . to_json
77
77
expect ( response . body ) . to eq ( expected )
78
78
end
79
+
80
+ it 'broadcasts the text message' do
81
+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/message/broadcast'
82
+ stub_request ( :post , uri_template ) . to_return { |request | { body : request . body , status : 200 } }
83
+
84
+ client = Line ::Bot ::Client . new do |config |
85
+ config . channel_token = 'channel_token'
86
+ end
87
+
88
+ message = {
89
+ type : 'text' ,
90
+ text : 'Hello, world'
91
+ }
92
+ response = client . broadcast ( message )
93
+
94
+ expected = {
95
+ messages : [
96
+ message
97
+ ]
98
+ } . to_json
99
+ expect ( response . body ) . to eq ( expected )
100
+ end
79
101
end
You can’t perform that action at this time.
0 commit comments