Module: MixinBot::API::Message
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/message.rb
Overview
Instance Method Summary collapse
- #acknowledge_message(message_id, status: 'READ', access_token: nil) ⇒ Object (also: #send_acknowledgement)
- #acknowledge_message_receipt(message_id) ⇒ Object
- #acknowledge_messages(messages, access_token: nil) ⇒ Object (also: #send_acknowledgements)
- #app_button_group(options) ⇒ Object
- #app_card(options) ⇒ Object
-
#base_message_params(options) ⇒ Object
base format of message params.
- #list_pending_message ⇒ Object
- #plain_audio(options) ⇒ Object
- #plain_contact(options) ⇒ Object
- #plain_data(options) ⇒ Object
- #plain_image(options) ⇒ Object
- #plain_live(options) ⇒ Object
- #plain_location(options) ⇒ Object
- #plain_post(options) ⇒ Object
- #plain_sticker(options) ⇒ Object
- #plain_text(options) ⇒ Object
- #plain_video(options) ⇒ Object
- #recall_message(message_id, options) ⇒ Object
- #recall_message_params(message_id, options) ⇒ Object
- #send_app_button_group_message(options) ⇒ Object
- #send_app_card_message(options) ⇒ Object
- #send_audio_message(options) ⇒ Object
- #send_contact_message(options) ⇒ Object
- #send_file_message(options) ⇒ Object
- #send_image_message(options) ⇒ Object
- #send_live_message(options) ⇒ Object
- #send_location_message(options) ⇒ Object
-
#send_message(payload) ⇒ Object
http post request.
- #send_plain_messages(messages) ⇒ Object
- #send_post_message(options) ⇒ Object
- #send_sticker_message(options) ⇒ Object
-
#send_text_message(options) ⇒ Object
use HTTP to send message.
- #send_transfer_message(options) ⇒ Object
- #send_video_message(options) ⇒ Object
- #transfer_message(options) ⇒ Object
-
#write_ws_message(params:, action: 'CREATE_MESSAGE') ⇒ Object
gzip the message for websocket.
-
#ws_message(data) ⇒ Object
read the gzipped message form websocket.
Instance Method Details
#acknowledge_message(message_id, status: 'READ', access_token: nil) ⇒ Object Also known as: send_acknowledgement
188 189 190 191 |
# File 'lib/mixin_bot/api/message.rb', line 188 def (, status: 'READ', access_token: nil) payload = { message_id:, status: } client.post '/acknowledgements', payload, access_token: end |
#acknowledge_message_receipt(message_id) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mixin_bot/api/message.rb', line 11 def () params = { message_id:, status: 'READ' } (action: 'ACKNOWLEDGE_MESSAGE_RECEIPT', params:) end |
#acknowledge_messages(messages, access_token: nil) ⇒ Object Also known as: send_acknowledgements
194 195 196 |
# File 'lib/mixin_bot/api/message.rb', line 194 def (, access_token: nil) client.post '/acknowledgements', *, access_token: end |
#app_button_group(options) ⇒ Object
67 68 69 |
# File 'lib/mixin_bot/api/message.rb', line 67 def () (.merge(category: 'APP_BUTTON_GROUP')) end |
#app_card(options) ⇒ Object
63 64 65 |
# File 'lib/mixin_bot/api/message.rb', line 63 def app_card() (.merge(category: 'APP_CARD')) end |
#base_message_params(options) ⇒ Object
base format of message params
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mixin_bot/api/message.rb', line 85 def () data = [:data].is_a?(String) ? [:data] : [:data].to_json { conversation_id: [:conversation_id], recipient_id: [:recipient_id], representative_id: [:representative_id], category: [:category], status: 'SENT', quote_message_id: [:quote_message_id], message_id: [:message_id] || SecureRandom.uuid, data: Base64.encode64(data) }.compact end |
#list_pending_message ⇒ Object
7 8 9 |
# File 'lib/mixin_bot/api/message.rb', line 7 def (action: 'LIST_PENDING_MESSAGES', params: {}) end |
#plain_audio(options) ⇒ Object
43 44 45 |
# File 'lib/mixin_bot/api/message.rb', line 43 def plain_audio() (.merge(category: 'PLAIN_AUDIO')) end |
#plain_contact(options) ⇒ Object
39 40 41 |
# File 'lib/mixin_bot/api/message.rb', line 39 def plain_contact() (.merge(category: 'PLAIN_CONTACT')) end |
#plain_data(options) ⇒ Object
31 32 33 |
# File 'lib/mixin_bot/api/message.rb', line 31 def plain_data() (.merge(category: 'PLAIN_DATA')) end |
#plain_image(options) ⇒ Object
27 28 29 |
# File 'lib/mixin_bot/api/message.rb', line 27 def plain_image() (.merge(category: 'PLAIN_IMAGE')) end |
#plain_live(options) ⇒ Object
51 52 53 |
# File 'lib/mixin_bot/api/message.rb', line 51 def plain_live() (.merge(category: 'PLAIN_LIVE')) end |
#plain_location(options) ⇒ Object
55 56 57 |
# File 'lib/mixin_bot/api/message.rb', line 55 def plain_location() (.merge(category: 'PLAIN_LOCATION')) end |
#plain_post(options) ⇒ Object
23 24 25 |
# File 'lib/mixin_bot/api/message.rb', line 23 def plain_post() (.merge(category: 'PLAIN_POST')) end |
#plain_sticker(options) ⇒ Object
35 36 37 |
# File 'lib/mixin_bot/api/message.rb', line 35 def plain_sticker() (.merge(category: 'PLAIN_STICKER')) end |
#plain_text(options) ⇒ Object
19 20 21 |
# File 'lib/mixin_bot/api/message.rb', line 19 def plain_text() (.merge(category: 'PLAIN_TEXT')) end |
#plain_video(options) ⇒ Object
47 48 49 |
# File 'lib/mixin_bot/api/message.rb', line 47 def plain_video() (.merge(category: 'PLAIN_VIDEO')) end |
#recall_message(message_id, options) ⇒ Object
180 181 182 |
# File 'lib/mixin_bot/api/message.rb', line 180 def (, ) [(, )] end |
#recall_message_params(message_id, options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mixin_bot/api/message.rb', line 71 def (, ) raise 'recipient_id is required!' if [:recipient_id].nil? ( .merge( category: 'MESSAGE_RECALL', data: { message_id: } ) ) end |
#send_app_button_group_message(options) ⇒ Object
152 153 154 |
# File 'lib/mixin_bot/api/message.rb', line 152 def () () end |
#send_app_card_message(options) ⇒ Object
148 149 150 |
# File 'lib/mixin_bot/api/message.rb', line 148 def () app_card() end |
#send_audio_message(options) ⇒ Object
160 161 162 |
# File 'lib/mixin_bot/api/message.rb', line 160 def () plain_audio() end |
#send_contact_message(options) ⇒ Object
144 145 146 |
# File 'lib/mixin_bot/api/message.rb', line 144 def () plain_contact() end |
#send_file_message(options) ⇒ Object
136 137 138 |
# File 'lib/mixin_bot/api/message.rb', line 136 def () plain_data() end |
#send_image_message(options) ⇒ Object
132 133 134 |
# File 'lib/mixin_bot/api/message.rb', line 132 def () plain_image() end |
#send_live_message(options) ⇒ Object
168 169 170 |
# File 'lib/mixin_bot/api/message.rb', line 168 def () plain_live() end |
#send_location_message(options) ⇒ Object
172 173 174 |
# File 'lib/mixin_bot/api/message.rb', line 172 def () plain_location() end |
#send_message(payload) ⇒ Object
http post request
200 201 202 203 204 205 206 207 208 |
# File 'lib/mixin_bot/api/message.rb', line 200 def (payload) path = '/messages' if payload.is_a? Hash client.post path, **payload elsif payload.is_a? Array client.post path, *payload end end |
#send_plain_messages(messages) ⇒ Object
184 185 186 |
# File 'lib/mixin_bot/api/message.rb', line 184 def () end |
#send_post_message(options) ⇒ Object
140 141 142 |
# File 'lib/mixin_bot/api/message.rb', line 140 def () plain_post() end |
#send_sticker_message(options) ⇒ Object
156 157 158 |
# File 'lib/mixin_bot/api/message.rb', line 156 def () plain_sticker() end |
#send_text_message(options) ⇒ Object
use HTTP to send message
128 129 130 |
# File 'lib/mixin_bot/api/message.rb', line 128 def () plain_text() end |
#send_transfer_message(options) ⇒ Object
176 177 178 |
# File 'lib/mixin_bot/api/message.rb', line 176 def () () end |
#send_video_message(options) ⇒ Object
164 165 166 |
# File 'lib/mixin_bot/api/message.rb', line 164 def () plain_video() end |
#transfer_message(options) ⇒ Object
59 60 61 |
# File 'lib/mixin_bot/api/message.rb', line 59 def () (.merge(category: 'SYSTEM_ACCOUNT_SNAPSHOT')) end |
#write_ws_message(params:, action: 'CREATE_MESSAGE') ⇒ Object
gzip the message for websocket
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/mixin_bot/api/message.rb', line 113 def (params:, action: 'CREATE_MESSAGE') msg = { id: SecureRandom.uuid, action:, params: }.to_json io = StringIO.new gzip = Zlib::GzipWriter.new io gzip.write msg gzip.close io.string.unpack('c*') end |
#ws_message(data) ⇒ Object
read the gzipped message form websocket
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mixin_bot/api/message.rb', line 100 def (data) data = data.pack('c*') if data.is_a?(Array) raise MixinBot::ArgumentError, 'data should be String or Array of integer' unless data.is_a?(String) io = StringIO.new(data, 'rb') gzip = Zlib::GzipReader.new io msg = gzip.read gzip.close msg end |