Class: Lita::Handlers::DmNotifier

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/dm_notifier.rb

Overview

DirectMessage Notification

Instance Method Summary collapse

Instance Method Details

#send_notification(request, _response) ⇒ Object

FORMAT:

"user": "required username (mention) to send the message to",
"author_name": "Optional author name"
"author_link": "Optional link for the author"
"author_icon": "Optional image for the author"
"title": "Required title for the attachment",
"title_link": "The link for the title on this attachment",
"image_url": "Optional image to include",
"thumb_url": "Optional Thumbnail to include",
"footer_icon": "Optional icon to include in the footer",
"footer": "Optional text for the footer",
"pretext": "Optional text above the attachment",
"text": "The message to send within the attachment, also fallback if not provided"
"fallback": "Optional fallback text if client doesn't support the attachment"
"fields": Array of json objects defining fields for slack



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lita/handlers/dm_notifier.rb', line 26

def send_notification(request, _response)
  data = MultiJson.load(request.body, symbolize_keys: true)
  type = data.delete(:type)
  text = data.delete(:text)
  data[:fields] += [{ title: 'Type', value: type, short: true }]
  data.merge(color: get_color(type))
  log.debug("Received alert request for #{data[:user]}\n")
  payload = Lita::Adapters::Slack::Attachment.new(text, data)
  user = User.find_by_mention_name(data[:user])
  robot.chat_service.send_attachment(user, payload)
end