Class: Whop_sdk::Messages::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Messages::Client
- Defined in:
- lib/whop_sdk/messages/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Send a new message in an experience chat, DM, or group chat channel.
-
#delete(request_options: {}, **params) ⇒ Boolean
Permanently delete a message from an experience chat, DM, or group chat channel.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Messages::Types::ListMessagesResponse
Returns a paginated list of messages within a specific experience chat, DM, or group chat channel, sorted by creation time.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Retrieves the details of an existing message.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Edit the content, attachments, or pinned status of an existing message in an experience chat, DM, or group chat channel.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/messages/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Send a new message in an experience chat, DM, or group chat channel. Supports text content, attachments, polls, and replies.
Required permissions (one of):
chat:message:createdms:message:managelivestream:chat:writesupport_chat:message:create
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/whop_sdk/messages/client.rb', line 106 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "messages", body: Whop_sdk::Messages::Types::CreateMessagesRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Message.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Boolean
Permanently delete a message from an experience chat, DM, or group chat channel. Only the message author or a channel admin can delete a message.
Required permissions (one of):
chat:message:createandchat:readdms:message:manageanddms:readlivestream:chat:writeandlivestream:chat:readsupport_chat:message:createandsupport_chat:read
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/whop_sdk/messages/client.rb', line 194 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "messages/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#list(request_options: {}, **params) ⇒ Whop_sdk::Messages::Types::ListMessagesResponse
Returns a paginated list of messages within a specific experience chat, DM, or group chat channel, sorted by creation time.
Required permissions (one of):
chat:readdms:readsupport_chat:read
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/whop_sdk/messages/client.rb', line 43 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["after"] = params[:after] if params.key?(:after) query_params["before"] = params[:before] if params.key?(:before) query_params["first"] = params[:first] if params.key?(:first) query_params["last"] = params[:last] if params.key?(:last) query_params["channel_id"] = params[:channel_id] if params.key?(:channel_id) query_params["direction"] = params[:direction] if params.key?(:direction) Whop_sdk::Internal::CursorItemIterator.new( cursor_field: :end_cursor, item_field: :data, initial_cursor: query_params["after"] ) do |next_cursor| query_params["after"] = next_cursor request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "messages", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) parsed_response = Whop_sdk::Messages::Types::ListMessagesResponse.load(response.body) [parsed_response, response] else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Retrieves the details of an existing message.
Required permissions (one of):
chat:readdms:readlivestream:chat:readsupport_chat:read
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/whop_sdk/messages/client.rb', line 150 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "messages/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Message.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Message
Edit the content, attachments, or pinned status of an existing message in an experience chat, DM, or group chat channel.
Required permissions (one of):
chat:message:createdms:message:managelivestream:chat:writesupport_chat:message:create
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/whop_sdk/messages/client.rb', line 236 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Messages::Types::UpdateMessagesRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "messages/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Message.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |