microsoft_teams_service.rb 1.4 KB
Newer Older
1 2 3 4 5 6
class MicrosoftTeamsService < ChatNotificationService
  def title
    'Microsoft Teams Notification'
  end

  def description
T
Tiago Botelho 已提交
7
    'Receive event notifications in Microsoft Teams'
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  end

  def self.to_param
    'microsoft_teams'
  end

  def help
    'This service sends notifications about projects events to Microsoft Teams channels.<br />
    To set up this service:
    <ol>
      <li><a href="https://msdn.microsoft.com/en-us/microsoft-teams/connectors">Getting started with 365 Office Connectors For Microsoft Teams</a>.</li>
      <li>Paste the <strong>Webhook URL</strong> into the field below.</li>
      <li>Select events below to enable notifications.</li>
    </ol>'
  end

  def webhook_placeholder
    'https://outlook.office.com/webhook/…'
  end

  def event_field(event)
  end

T
Tiago Botelho 已提交
31 32 33
  def default_channel_placeholder
  end

34 35 36 37
  def default_fields
    [
      { type: 'text', name: 'webhook', placeholder: "e.g. #{webhook_placeholder}" },
      { type: 'checkbox', name: 'notify_only_broken_pipelines' },
38
      { type: 'checkbox', name: 'notify_only_default_branch' }
39 40 41
    ]
  end

T
Tiago Botelho 已提交
42
  private
43

T
Tiago Botelho 已提交
44 45
  def notify(message, opts)
    MicrosoftTeams::Notifier.new(webhook).ping(
46
      title: message.project_name,
47
      summary: message.summary,
48
      activity: message.activity,
49
      attachments: message.attachments
T
Tiago Botelho 已提交
50 51 52 53 54
    )
  end

  def custom_data(data)
    super(data).merge(markdown: true)
55 56
  end
end