Class: BundleUp::Unify::Chat

Inherits:
Base
  • Object
show all
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

#api_key, #connection_id

Instance Method Summary collapse

Methods inherited from Base

#connection, #initialize

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.

Parameters:

  • params (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • ({ data: Array[chat_channel], metadata: metadata })


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.

Parameters:

  • channel_id (String)
  • text (String)

Returns:

  • ({ data: Hash[String, untyped] })

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bundleup/unify/chat.rb', line 30

def message(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.

Parameters:

  • params (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • ({ data: Array[chat_user], metadata: metadata })


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