Module: MixinBot::API::Message
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/message.rb
Overview
Instance Method Summary collapse
- #acknowledge_message_receipt(message_id) ⇒ Object
- #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_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_contact_message(options) ⇒ Object
- #send_file_message(options) ⇒ Object
- #send_image_message(options) ⇒ Object
-
#send_message(payload) ⇒ Object
http post request.
- #send_plain_messages(messages) ⇒ Object
- #send_post_message(options) ⇒ Object
-
#send_text_message(options) ⇒ Object
use HTTP to send message.
-
#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_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 |
#app_button_group(options) ⇒ Object
64 65 66 67 |
# File 'lib/mixin_bot/api/message.rb', line 64 def () .merge!(category: 'APP_BUTTON_GROUP') () end |
#app_card(options) ⇒ Object
59 60 61 62 |
# File 'lib/mixin_bot/api/message.rb', line 59 def app_card() .merge!(category: 'APP_CARD') () end |
#base_message_params(options) ⇒ Object
base format of message params
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mixin_bot/api/message.rb', line 82 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
49 50 51 52 |
# File 'lib/mixin_bot/api/message.rb', line 49 def plain_audio() .merge!(category: 'PLAIN_AUDIO') () end |
#plain_contact(options) ⇒ Object
44 45 46 47 |
# File 'lib/mixin_bot/api/message.rb', line 44 def plain_contact() .merge!(category: 'PLAIN_CONTACT') () end |
#plain_data(options) ⇒ Object
34 35 36 37 |
# File 'lib/mixin_bot/api/message.rb', line 34 def plain_data() .merge!(category: 'PLAIN_DATA') () end |
#plain_image(options) ⇒ Object
29 30 31 32 |
# File 'lib/mixin_bot/api/message.rb', line 29 def plain_image() .merge!(category: 'PLAIN_IMAGE') () end |
#plain_post(options) ⇒ Object
24 25 26 27 |
# File 'lib/mixin_bot/api/message.rb', line 24 def plain_post() .merge!(category: 'PLAIN_POST') () end |
#plain_sticker(options) ⇒ Object
39 40 41 42 |
# File 'lib/mixin_bot/api/message.rb', line 39 def plain_sticker() .merge!(category: 'PLAIN_STICKER') () end |
#plain_text(options) ⇒ Object
19 20 21 22 |
# File 'lib/mixin_bot/api/message.rb', line 19 def plain_text() .merge!(category: 'PLAIN_TEXT') () end |
#plain_video(options) ⇒ Object
54 55 56 57 |
# File 'lib/mixin_bot/api/message.rb', line 54 def plain_video() .merge!(category: 'PLAIN_VIDEO') () end |
#recall_message(message_id, options) ⇒ Object
153 154 155 |
# File 'lib/mixin_bot/api/message.rb', line 153 def (, ) [(, )] end |
#recall_message_params(message_id, options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mixin_bot/api/message.rb', line 69 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
149 150 151 |
# File 'lib/mixin_bot/api/message.rb', line 149 def () () end |
#send_app_card_message(options) ⇒ Object
145 146 147 |
# File 'lib/mixin_bot/api/message.rb', line 145 def () app_card() end |
#send_contact_message(options) ⇒ Object
141 142 143 |
# File 'lib/mixin_bot/api/message.rb', line 141 def () plain_contact() end |
#send_file_message(options) ⇒ Object
133 134 135 |
# File 'lib/mixin_bot/api/message.rb', line 133 def () plain_data() end |
#send_image_message(options) ⇒ Object
129 130 131 |
# File 'lib/mixin_bot/api/message.rb', line 129 def () plain_image() end |
#send_message(payload) ⇒ Object
http post request
162 163 164 165 166 167 168 169 170 |
# File 'lib/mixin_bot/api/message.rb', line 162 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
157 158 159 |
# File 'lib/mixin_bot/api/message.rb', line 157 def () end |
#send_post_message(options) ⇒ Object
137 138 139 |
# File 'lib/mixin_bot/api/message.rb', line 137 def () plain_post() end |
#send_text_message(options) ⇒ Object
use HTTP to send message
125 126 127 |
# File 'lib/mixin_bot/api/message.rb', line 125 def () plain_text() end |
#write_ws_message(params:, action: 'CREATE_MESSAGE') ⇒ Object
gzip the message for websocket
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mixin_bot/api/message.rb', line 110 def (params:, action: 'CREATE_MESSAGE') msg = { id: SecureRandom.uuid, action:, params: }.to_json io = StringIO.new 'wb' 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
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mixin_bot/api/message.rb', line 97 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 |