Class: Dispatcher::Slack::Implementation

Inherits:
Base
  • Object
show all
Defined in:
lib/bas/dispatcher/slack/implementation.rb

Overview

This class is an implementation of the Dispatcher::Base interface, specifically designed for dispatching messages to Slack.

Instance Attribute Summary

Attributes inherited from Base

#name, #webhook

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dispatcher::Base

Instance Method Details

#dispatch(payload) ⇒ Object

Implements the dispatching logic for the Slack use case. It sends a POST request to the Slack webhook with the specified payload.


Params:

  • String payload: Payload to be dispatched to slack.


raises Exceptions::Slack::InvalidWebookToken if the provided webhook token is invalid.


returns Dispatcher::Slack::Types::Response



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bas/dispatcher/slack/implementation.rb', line 26

def dispatch(payload)
  body = {
    username: name,
    text: payload
  }.to_json

  response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })

  slack_response = Dispatcher::Discord::Types::Response.new(response)

  validate_response(slack_response)
end