Class: Dispatcher::Discord::Implementation

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

Overview

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

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 Discord use case. It sends a POST request to the Discord webhook with the specified payload.


Params:

  • String payload: Payload to be dispatched to discord.


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


returns Dispatcher::Discord::Types::Response



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

def dispatch(payload)
  body = {
    username: name,
    avatar_url: "",
    content: payload
  }.to_json
  response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })

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

  validate_response(discord_response)
end