Class: BundleUp::Unify::Chat
- Defined in:
- lib/bundleup/unify/chat.rb,
sig/bundleup/unify/chat.rbs
Overview
Client for chat-related Unify endpoints.
Constant Summary
Constants inherited from Base
Base::API_VERSION, Base::BASE_URL
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#channels(params = {}) ⇒ { data: Array[chat_channel], metadata: metadata }
Fetches channels from the connected chat provider.
-
#message(channel_id, text) ⇒ { data: Hash[String, untyped] }
Sends a message to a channel on the connected chat provider.
-
#users(params = {}) ⇒ { data: Array[chat_user], metadata: metadata }
Fetches users from the connected chat provider.
Methods inherited from Base
Constructor Details
This class inherits a constructor from BundleUp::Unify::Base
Instance Method Details
#channels(params = {}) ⇒ { data: Array[chat_channel], metadata: metadata }
Fetches channels from the connected chat provider.
19 20 21 22 23 24 25 26 27 |
# File 'lib/bundleup/unify/chat.rb', line 19 def channels(params = {}) response = connection.get('chat/channels') do |req| req.params = params end raise "Failed to fetch chat/channels: #{response.status}" unless response.success? response.body end |
#message(channel_id, text) ⇒ { data: Hash[String, untyped] }
Sends a message to a channel on the connected chat provider.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bundleup/unify/chat.rb', line 30 def (channel_id, text) raise ArgumentError, 'channel_id is required to send a message.' if channel_id.nil? encoded_channel_id = URI.encode_www_form_component(channel_id) response = connection.post("chat/channels/#{encoded_channel_id}/message", { text: text }.to_json) raise "Failed to post chat/channels/#{encoded_channel_id}/message: #{response.status}" unless response.success? response.body end |
#users(params = {}) ⇒ { data: Array[chat_user], metadata: metadata }
Fetches users from the connected chat provider.
8 9 10 11 12 13 14 15 16 |
# File 'lib/bundleup/unify/chat.rb', line 8 def users(params = {}) response = connection.get('chat/users') do |req| req.params = params end raise "Failed to fetch chat/users: #{response.status}" unless response.success? response.body end |