Class: Howlr::Controllers::DeliveryNotifications

Inherits:
REST
  • Object
show all
Defined in:
lib/howlr/controllers.rb

Overview

Can be used as a callback target for messages. This makes it possible to receive a notification when a message is sent out.

For example, set up your outgoing message’s callback values as follows:

callback_url: http://howlr.example.com/delivery_notifications
callback_method: post

Now when the message is sent, a delivery notice will be sent back to the sender, informing them of whether the message was successfully sent out, or if some sort of delivery error occurred.

The real-world usefulness of this is probably questionable. It’s just meant to illustrate how a message callback receiver can be implemented.

Instance Method Summary collapse

Instance Method Details

#createObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/howlr/controllers.rb', line 97

def create
  $LOG.debug "Creating delivery notification from: #{input.inspect}"
  
  auth = {
    :username => $CONF[:auth_username], 
    :password => $CONF[:auth_password]
  }
  
  begin
    m = Restr.get("http://localhost:#{$CONF[:port]}#{$CONF[:uri_path]}messages", 
      {:id => input[:message_id], :format => 'XML'}, 
      auth)
    
    to = m['from']
    subject = "Howlr Message Delivery Notification"
    
    body = "Your message regarding #{m['subject'].inspect} was " +
      (input[:send_success] == 'true' ? '' : 'NOT') +
      " sent successfully to #{input[:recipient_address]}."
    
    data = {
      :recipients => to, 
      :body => body, 
      :subject => subject,
      :from => input[:recipient_address]
    }
    
    Restr.post("http://localhost:#{$CONF.port}#{$CONF.uri_path}messages",
      data, auth)
      
  rescue Net::HTTPServerException, Net::HTTPError => e
    return _error($LAST_ERROR_BODY, e.response.code, e)
  rescue => e
    return _error(e.inspect, 500, e)
  end
end