metamaps--metamaps/app/models/webhooks/slack/base.rb

77 lines
1.9 KiB
Ruby
Raw Permalink Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
2016-11-05 16:34:50 +00:00
Webhooks::Slack::Base = Struct.new(:webhook, :event) do
include Routing
def username
'Metamaps Bot'
end
def icon_url
'https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg'
end
def text
'something'
end
2016-11-05 16:34:50 +00:00
def channel
webhook.channel
end
def attachments
[{
title: attachment_title,
text: attachment_text,
fields: attachment_fields,
fallback: attachment_fallback
}]
end
alias_method :read_attribute_for_serialization, :send
private
# def motion_vote_field
# {
# title: "Vote on this proposal",
# value: "#{proposal_link(eventable, "yes")} · " +
# "#{proposal_link(eventable, "abstain")} · " +
# "#{proposal_link(eventable, "no")} · " +
# "#{proposal_link(eventable, "block")}"
# }
# end
def view_map_on_metamaps(text = nil)
"<#{map_url(event.map)}|#{text || event.map.name}>"
end
# def view_discussion_on_loomio(params = {})
# { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) }
# end
# def proposal_link(proposal, position = nil)
# discussion_link position || proposal.name, { proposal: proposal.key, position: position }
# end
# def discussion_link(text = nil, params = {})
# "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>"
# end
def eventable
@eventable ||= event.eventable
end
def author
@author ||= eventable.author
end
end
# webhooks:
# slack:
# motion_closed: "*%{name}* has closed"
# motion_closing_soon: "*%{name}* has a proposal closing in 24 hours"
# motion_outcome_created: "*%{author}* published an outcome in *%{name}*"
# motion_outcome_updated: "*%{author}* updated the outcome for *%{name}*"
# new_motion: "*%{author}* started a new proposal in *%{name}*"
# view_it_on_loomio: "View it on Loomio"