Class: Direct7::SLACK

Inherits:
Object
  • Object
show all
Defined in:
lib/direct7/slack.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SLACK

Returns a new instance of SLACK.



8
9
10
11
# File 'lib/direct7/slack.rb', line 8

def initialize(client)
  @client = client
  @log = Logger.new(STDOUT) # You can customize the log destination as needed
end

Instance Method Details

#get_status(request_id) ⇒ Object



32
33
34
35
36
# File 'lib/direct7/slack.rb', line 32

def get_status(request_id)
  response = @client.get(@client.host, "/report/v1/message-log/#{request_id}")
  @log.info('Message status retrieved successfully.')
  response
end

#send_slack_message(content, work_space_name, channel_name, report_url = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/direct7/slack.rb', line 13

def send_slack_message(content, work_space_name, channel_name, report_url = nil)
  message = {
    'channel' => 'slack',
    'content' => content,
    'work_space_name' => work_space_name,
    'channel_name' => channel_name
  }
  message_globals = {
    'report_url' => report_url
  }
  response = @client.post(@client.host, '/messages/v1/send', true, params= {
    'messages' => [message],
    'message_globals' => message_globals
  })

  @log.info('Message sent successfully.')
  response
end