Class: Talentio::Notifier::Slack::SelectionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/talentio/notifier/slack/selection_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SelectionResult

Returns a new instance of SelectionResult.



6
7
8
# File 'lib/talentio/notifier/slack/selection_result.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/talentio/notifier/slack/selection_result.rb', line 5

def client
  @client
end

Instance Method Details

#notify(data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/talentio/notifier/slack/selection_result.rb', line 10

def notify(data)
  channel_message = []
  param = selection_types[data[:type].to_sym]

  return unless param
  # 納期の計算対象となる日付が登録されていないものはスキップする
  return unless data[param[:limit_key]]

  # 登録当日はスキップする
  base_time = Time.parse(data[param[:limit_key]])
  return if base_time >= Date.today.to_time

  slack_mentions = client.mention_id_from_evaluations(data[:evaluations])
  slack_mentions.each do |m|
    limit_day = base_time + param[:limit_day] * (60*60*24)
    # 納期を設定する
    loop do
      break if ![0, 6].include?(limit_day.wday) && !HolidayJp.holiday?(limit_day)
      limit_day = limit_day + (60*60*24)
    end

    # 個別の通知はトークで実行するので、共有チャンネルに動いたことを通知する
    channel_message << {
      name: m[:name],
      limit:limit_day,
      url: data[:candidate_url]
    }

    client.chat_postMessage(
      channel: m[:id],
      as_user: false,
      text: "#{param[:label]}をお願いします。すぐに対応できないときはtalentioの「採用チーム内のコミュニケーション」にいつまでにやるかを書いてください。",
      attachments: [{
        fields: [
          {
            title: '区分',
            value: data[:requisition_name]
          },
          {
            title: '登録日時',
            value: base_time.strftime("%Y/%m/%d %H:%M:%S")
          },
          {
            title: '納期',
            value: limit_day.to_s
          },
          {
            title: 'url',
            value: data[:candidate_url]
          }
        ],
        color: 'warning'
      }]
    )

    channel_message.sort_by! { |a| a[:limit] }.each_with_object({}) do |m,r|
      r[m[:limit].strftime('%Y/%m/%d')] ||= []
      r[m[:limit].strftime('%Y/%m/%d')] << {
        name: m[:name],
        url: m[:url]
      }
    end.map do |k,v|
      f = v.map do |vv|
        [
          {
            title: vv[:name],
            value: vv[:url]
          },
        ]
      end

      client.chat_postMessage(
        channel: ENV['TELENTIO_SLACK_CHANNEL'] || '#recruiting',
        as_user: false,
        text: "納期:#{k}#{param[:label]}のお願いを通知しました",
        attachments: [{
          fields: f.flatten,
          color: 'warning'
        }]
      )
    end
  end
end