Class: Hermes::OutboundWebhookProvider

Inherits:
Provider
  • Object
show all
Defined in:
lib/providers/outbound_webhook/outbound_webhook_provider.rb

Instance Attribute Summary

Attributes inherited from Provider

#credentials, #defaults, #deliverer, #weight

Instance Method Summary collapse

Methods inherited from Provider

#initialize, #message_failure, #message_success, #provider_name, required_credentials

Methods included from Extractors

#complex_extract, #extract_from, #extract_html, #extract_text, #extract_to

Constructor Details

This class inherits a constructor from Hermes::Provider

Instance Method Details

#payload(rails_message) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/providers/outbound_webhook/outbound_webhook_provider.rb', line 20

def payload(rails_message)
  {
    :endpoint => extract_to(rails_message),
    :headers => {
      'Content-Type' => 'application/json'
    },
    :body => extract_text(rails_message)
  }
end

#send_message(rails_message) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/providers/outbound_webhook/outbound_webhook_provider.rb', line 4

def send_message(rails_message)
  payload = payload(rails_message)
  outbound_webhook = OutboundWebhook.create!(payload)
  rails_message[:message_id] = outbound_webhook.id

  byebug

  if self.deliverer.should_deliver?
    outbound_webhook.deliver_async
  end

  self.message_success(rails_message)
rescue Exception => e
  self.message_failure(rails_message, e)
end