From a939c454a301e5b315329eb100acd1f04bfa2b8e Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 19:38:19 +0900 Subject: [PATCH 01/22] =?UTF-8?q?modal=20view=E7=94=A8=E3=81=AEselect?= =?UTF-8?q?=E8=A6=81=E7=B4=A0=E3=81=AEoptions=E3=81=AE=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog.rb | 10 +- spec/app/models/slack_dialog_spec.rb | 180 +++++++++++++-------------- 2 files changed, 97 insertions(+), 93 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index 4a29ac6..b279868 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -15,11 +15,12 @@ class SlackDialog # Factory Method # @param trigger_id [String] def self.open(trigger_id) - post_body = new.send(:post_body, trigger_id) + post_body = new.send(:post_body) # https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/dialog.rb client = Slack::Web::Client.new(token: ENV.fetch("SLACK_TOKEN")) - client.dialog_open(post_body) + # client.dialog_open(post_body) + client.views_open(trigger_id:, view: post_body) end private @@ -92,7 +93,10 @@ def date_select_options date_text = date.strftime("%Y/%m/%d") wday = %w[日 月 火 水 木 金 土][date.wday] - { label: "#{date_text} #{wday}", + { text: { + type: "plain_text", + text: "#{date_text} #{wday}" + }, value: date_text } end end diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index b5439d1..7358a48 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -68,96 +68,96 @@ describe "#date_select_options" do context "ok" do it do - expected = [{ label: "2022/12/31 土", value: "2022/12/31" }, - { label: "2023/01/01 日", value: "2023/01/01" }, - { label: "2023/01/02 月", value: "2023/01/02" }, - { label: "2023/01/03 火", value: "2023/01/03" }, - { label: "2023/01/04 水", value: "2023/01/04" }, - { label: "2023/01/05 木", value: "2023/01/05" }, - { label: "2023/01/06 金", value: "2023/01/06" }, - { label: "2023/01/07 土", value: "2023/01/07" }, - { label: "2023/01/08 日", value: "2023/01/08" }, - { label: "2023/01/09 月", value: "2023/01/09" }, - { label: "2023/01/10 火", value: "2023/01/10" }, - { label: "2023/01/11 水", value: "2023/01/11" }, - { label: "2023/01/12 木", value: "2023/01/12" }, - { label: "2023/01/13 金", value: "2023/01/13" }, - { label: "2023/01/14 土", value: "2023/01/14" }, - { label: "2023/01/15 日", value: "2023/01/15" }, - { label: "2023/01/16 月", value: "2023/01/16" }, - { label: "2023/01/17 火", value: "2023/01/17" }, - { label: "2023/01/18 水", value: "2023/01/18" }, - { label: "2023/01/19 木", value: "2023/01/19" }, - { label: "2023/01/20 金", value: "2023/01/20" }, - { label: "2023/01/21 土", value: "2023/01/21" }, - { label: "2023/01/22 日", value: "2023/01/22" }, - { label: "2023/01/23 月", value: "2023/01/23" }, - { label: "2023/01/24 火", value: "2023/01/24" }, - { label: "2023/01/25 水", value: "2023/01/25" }, - { label: "2023/01/26 木", value: "2023/01/26" }, - { label: "2023/01/27 金", value: "2023/01/27" }, - { label: "2023/01/28 土", value: "2023/01/28" }, - { label: "2023/01/29 日", value: "2023/01/29" }, - { label: "2023/01/30 月", value: "2023/01/30" }, - { label: "2023/01/31 火", value: "2023/01/31" }, - { label: "2023/02/01 水", value: "2023/02/01" }, - { label: "2023/02/02 木", value: "2023/02/02" }, - { label: "2023/02/03 金", value: "2023/02/03" }, - { label: "2023/02/04 土", value: "2023/02/04" }, - { label: "2023/02/05 日", value: "2023/02/05" }, - { label: "2023/02/06 月", value: "2023/02/06" }, - { label: "2023/02/07 火", value: "2023/02/07" }, - { label: "2023/02/08 水", value: "2023/02/08" }, - { label: "2023/02/09 木", value: "2023/02/09" }, - { label: "2023/02/10 金", value: "2023/02/10" }, - { label: "2023/02/11 土", value: "2023/02/11" }, - { label: "2023/02/12 日", value: "2023/02/12" }, - { label: "2023/02/13 月", value: "2023/02/13" }, - { label: "2023/02/14 火", value: "2023/02/14" }, - { label: "2023/02/15 水", value: "2023/02/15" }, - { label: "2023/02/16 木", value: "2023/02/16" }, - { label: "2023/02/17 金", value: "2023/02/17" }, - { label: "2023/02/18 土", value: "2023/02/18" }, - { label: "2023/02/19 日", value: "2023/02/19" }, - { label: "2023/02/20 月", value: "2023/02/20" }, - { label: "2023/02/21 火", value: "2023/02/21" }, - { label: "2023/02/22 水", value: "2023/02/22" }, - { label: "2023/02/23 木", value: "2023/02/23" }, - { label: "2023/02/24 金", value: "2023/02/24" }, - { label: "2023/02/25 土", value: "2023/02/25" }, - { label: "2023/02/26 日", value: "2023/02/26" }, - { label: "2023/02/27 月", value: "2023/02/27" }, - { label: "2023/02/28 火", value: "2023/02/28" }, - { label: "2023/03/01 水", value: "2023/03/01" }, - { label: "2023/03/02 木", value: "2023/03/02" }, - { label: "2023/03/03 金", value: "2023/03/03" }, - { label: "2023/03/04 土", value: "2023/03/04" }, - { label: "2023/03/05 日", value: "2023/03/05" }, - { label: "2023/03/06 月", value: "2023/03/06" }, - { label: "2023/03/07 火", value: "2023/03/07" }, - { label: "2023/03/08 水", value: "2023/03/08" }, - { label: "2023/03/09 木", value: "2023/03/09" }, - { label: "2023/03/10 金", value: "2023/03/10" }, - { label: "2023/03/11 土", value: "2023/03/11" }, - { label: "2023/03/12 日", value: "2023/03/12" }, - { label: "2023/03/13 月", value: "2023/03/13" }, - { label: "2023/03/14 火", value: "2023/03/14" }, - { label: "2023/03/15 水", value: "2023/03/15" }, - { label: "2023/03/16 木", value: "2023/03/16" }, - { label: "2023/03/17 金", value: "2023/03/17" }, - { label: "2023/03/18 土", value: "2023/03/18" }, - { label: "2023/03/19 日", value: "2023/03/19" }, - { label: "2023/03/20 月", value: "2023/03/20" }, - { label: "2023/03/21 火", value: "2023/03/21" }, - { label: "2023/03/22 水", value: "2023/03/22" }, - { label: "2023/03/23 木", value: "2023/03/23" }, - { label: "2023/03/24 金", value: "2023/03/24" }, - { label: "2023/03/25 土", value: "2023/03/25" }, - { label: "2023/03/26 日", value: "2023/03/26" }, - { label: "2023/03/27 月", value: "2023/03/27" }, - { label: "2023/03/28 火", value: "2023/03/28" }, - { label: "2023/03/29 水", value: "2023/03/29" }, - { label: "2023/03/30 木", value: "2023/03/30" }] + expected = [{ text: { text: "2022/12/31 土", type: "plain_text" }, value: "2022/12/31" }, + { text: { text: "2023/01/01 日", type: "plain_text" }, value: "2023/01/01" }, + { text: { text: "2023/01/02 月", type: "plain_text" }, value: "2023/01/02" }, + { text: { text: "2023/01/03 火", type: "plain_text" }, value: "2023/01/03" }, + { text: { text: "2023/01/04 水", type: "plain_text" }, value: "2023/01/04" }, + { text: { text: "2023/01/05 木", type: "plain_text" }, value: "2023/01/05" }, + { text: { text: "2023/01/06 金", type: "plain_text" }, value: "2023/01/06" }, + { text: { text: "2023/01/07 土", type: "plain_text" }, value: "2023/01/07" }, + { text: { text: "2023/01/08 日", type: "plain_text" }, value: "2023/01/08" }, + { text: { text: "2023/01/09 月", type: "plain_text" }, value: "2023/01/09" }, + { text: { text: "2023/01/10 火", type: "plain_text" }, value: "2023/01/10" }, + { text: { text: "2023/01/11 水", type: "plain_text" }, value: "2023/01/11" }, + { text: { text: "2023/01/12 木", type: "plain_text" }, value: "2023/01/12" }, + { text: { text: "2023/01/13 金", type: "plain_text" }, value: "2023/01/13" }, + { text: { text: "2023/01/14 土", type: "plain_text" }, value: "2023/01/14" }, + { text: { text: "2023/01/15 日", type: "plain_text" }, value: "2023/01/15" }, + { text: { text: "2023/01/16 月", type: "plain_text" }, value: "2023/01/16" }, + { text: { text: "2023/01/17 火", type: "plain_text" }, value: "2023/01/17" }, + { text: { text: "2023/01/18 水", type: "plain_text" }, value: "2023/01/18" }, + { text: { text: "2023/01/19 木", type: "plain_text" }, value: "2023/01/19" }, + { text: { text: "2023/01/20 金", type: "plain_text" }, value: "2023/01/20" }, + { text: { text: "2023/01/21 土", type: "plain_text" }, value: "2023/01/21" }, + { text: { text: "2023/01/22 日", type: "plain_text" }, value: "2023/01/22" }, + { text: { text: "2023/01/23 月", type: "plain_text" }, value: "2023/01/23" }, + { text: { text: "2023/01/24 火", type: "plain_text" }, value: "2023/01/24" }, + { text: { text: "2023/01/25 水", type: "plain_text" }, value: "2023/01/25" }, + { text: { text: "2023/01/26 木", type: "plain_text" }, value: "2023/01/26" }, + { text: { text: "2023/01/27 金", type: "plain_text" }, value: "2023/01/27" }, + { text: { text: "2023/01/28 土", type: "plain_text" }, value: "2023/01/28" }, + { text: { text: "2023/01/29 日", type: "plain_text" }, value: "2023/01/29" }, + { text: { text: "2023/01/30 月", type: "plain_text" }, value: "2023/01/30" }, + { text: { text: "2023/01/31 火", type: "plain_text" }, value: "2023/01/31" }, + { text: { text: "2023/02/01 水", type: "plain_text" }, value: "2023/02/01" }, + { text: { text: "2023/02/02 木", type: "plain_text" }, value: "2023/02/02" }, + { text: { text: "2023/02/03 金", type: "plain_text" }, value: "2023/02/03" }, + { text: { text: "2023/02/04 土", type: "plain_text" }, value: "2023/02/04" }, + { text: { text: "2023/02/05 日", type: "plain_text" }, value: "2023/02/05" }, + { text: { text: "2023/02/06 月", type: "plain_text" }, value: "2023/02/06" }, + { text: { text: "2023/02/07 火", type: "plain_text" }, value: "2023/02/07" }, + { text: { text: "2023/02/08 水", type: "plain_text" }, value: "2023/02/08" }, + { text: { text: "2023/02/09 木", type: "plain_text" }, value: "2023/02/09" }, + { text: { text: "2023/02/10 金", type: "plain_text" }, value: "2023/02/10" }, + { text: { text: "2023/02/11 土", type: "plain_text" }, value: "2023/02/11" }, + { text: { text: "2023/02/12 日", type: "plain_text" }, value: "2023/02/12" }, + { text: { text: "2023/02/13 月", type: "plain_text" }, value: "2023/02/13" }, + { text: { text: "2023/02/14 火", type: "plain_text" }, value: "2023/02/14" }, + { text: { text: "2023/02/15 水", type: "plain_text" }, value: "2023/02/15" }, + { text: { text: "2023/02/16 木", type: "plain_text" }, value: "2023/02/16" }, + { text: { text: "2023/02/17 金", type: "plain_text" }, value: "2023/02/17" }, + { text: { text: "2023/02/18 土", type: "plain_text" }, value: "2023/02/18" }, + { text: { text: "2023/02/19 日", type: "plain_text" }, value: "2023/02/19" }, + { text: { text: "2023/02/20 月", type: "plain_text" }, value: "2023/02/20" }, + { text: { text: "2023/02/21 火", type: "plain_text" }, value: "2023/02/21" }, + { text: { text: "2023/02/22 水", type: "plain_text" }, value: "2023/02/22" }, + { text: { text: "2023/02/23 木", type: "plain_text" }, value: "2023/02/23" }, + { text: { text: "2023/02/24 金", type: "plain_text" }, value: "2023/02/24" }, + { text: { text: "2023/02/25 土", type: "plain_text" }, value: "2023/02/25" }, + { text: { text: "2023/02/26 日", type: "plain_text" }, value: "2023/02/26" }, + { text: { text: "2023/02/27 月", type: "plain_text" }, value: "2023/02/27" }, + { text: { text: "2023/02/28 火", type: "plain_text" }, value: "2023/02/28" }, + { text: { text: "2023/03/01 水", type: "plain_text" }, value: "2023/03/01" }, + { text: { text: "2023/03/02 木", type: "plain_text" }, value: "2023/03/02" }, + { text: { text: "2023/03/03 金", type: "plain_text" }, value: "2023/03/03" }, + { text: { text: "2023/03/04 土", type: "plain_text" }, value: "2023/03/04" }, + { text: { text: "2023/03/05 日", type: "plain_text" }, value: "2023/03/05" }, + { text: { text: "2023/03/06 月", type: "plain_text" }, value: "2023/03/06" }, + { text: { text: "2023/03/07 火", type: "plain_text" }, value: "2023/03/07" }, + { text: { text: "2023/03/08 水", type: "plain_text" }, value: "2023/03/08" }, + { text: { text: "2023/03/09 木", type: "plain_text" }, value: "2023/03/09" }, + { text: { text: "2023/03/10 金", type: "plain_text" }, value: "2023/03/10" }, + { text: { text: "2023/03/11 土", type: "plain_text" }, value: "2023/03/11" }, + { text: { text: "2023/03/12 日", type: "plain_text" }, value: "2023/03/12" }, + { text: { text: "2023/03/13 月", type: "plain_text" }, value: "2023/03/13" }, + { text: { text: "2023/03/14 火", type: "plain_text" }, value: "2023/03/14" }, + { text: { text: "2023/03/15 水", type: "plain_text" }, value: "2023/03/15" }, + { text: { text: "2023/03/16 木", type: "plain_text" }, value: "2023/03/16" }, + { text: { text: "2023/03/17 金", type: "plain_text" }, value: "2023/03/17" }, + { text: { text: "2023/03/18 土", type: "plain_text" }, value: "2023/03/18" }, + { text: { text: "2023/03/19 日", type: "plain_text" }, value: "2023/03/19" }, + { text: { text: "2023/03/20 月", type: "plain_text" }, value: "2023/03/20" }, + { text: { text: "2023/03/21 火", type: "plain_text" }, value: "2023/03/21" }, + { text: { text: "2023/03/22 水", type: "plain_text" }, value: "2023/03/22" }, + { text: { text: "2023/03/23 木", type: "plain_text" }, value: "2023/03/23" }, + { text: { text: "2023/03/24 金", type: "plain_text" }, value: "2023/03/24" }, + { text: { text: "2023/03/25 土", type: "plain_text" }, value: "2023/03/25" }, + { text: { text: "2023/03/26 日", type: "plain_text" }, value: "2023/03/26" }, + { text: { text: "2023/03/27 月", type: "plain_text" }, value: "2023/03/27" }, + { text: { text: "2023/03/28 火", type: "plain_text" }, value: "2023/03/28" }, + { text: { text: "2023/03/29 水", type: "plain_text" }, value: "2023/03/29" }, + { text: { text: "2023/03/30 木", type: "plain_text" }, value: "2023/03/30" }] travel_to Date.new(2022, 12, 31) do expect(instance.send(:date_select_options)).to eq expected From 93a5027f0b27cb237c71c29b073fd58fbee22e6d Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 19:44:06 +0900 Subject: [PATCH 02/22] =?UTF-8?q?=E6=99=82=E5=88=BB=E3=81=AE=E9=81=B8?= =?UTF-8?q?=E6=8A=9E=E3=82=82=E5=90=8C=E6=A7=98=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog.rb | 4 +- spec/app/models/slack_dialog_spec.rb | 56 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index b279868..0813ec7 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -107,8 +107,8 @@ def time_select_options hours = (SELECT_TIME_HOUR_START..SELECT_TIME_HOUR_END).to_a hours.map do |hour| padded_hours = format("%.2d", hour) - [{ label: "#{padded_hours}:00", value: "#{padded_hours}:00" }, - { label: "#{padded_hours}:30", value: "#{padded_hours}:30" }] + [{ text: { type: "plain_text", text: "#{padded_hours}:00" }, value: "#{padded_hours}:00" }, + { text: { type: "plain_text", text: "#{padded_hours}:30" }, value: "#{padded_hours}:30" }] end.flatten end end diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index 7358a48..6a9d555 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -168,34 +168,34 @@ describe "#time_select_options" do context "ok" do it do - expected = [{ label: "08:00", value: "08:00" }, - { label: "08:30", value: "08:30" }, - { label: "09:00", value: "09:00" }, - { label: "09:30", value: "09:30" }, - { label: "10:00", value: "10:00" }, - { label: "10:30", value: "10:30" }, - { label: "11:00", value: "11:00" }, - { label: "11:30", value: "11:30" }, - { label: "12:00", value: "12:00" }, - { label: "12:30", value: "12:30" }, - { label: "13:00", value: "13:00" }, - { label: "13:30", value: "13:30" }, - { label: "14:00", value: "14:00" }, - { label: "14:30", value: "14:30" }, - { label: "15:00", value: "15:00" }, - { label: "15:30", value: "15:30" }, - { label: "16:00", value: "16:00" }, - { label: "16:30", value: "16:30" }, - { label: "17:00", value: "17:00" }, - { label: "17:30", value: "17:30" }, - { label: "18:00", value: "18:00" }, - { label: "18:30", value: "18:30" }, - { label: "19:00", value: "19:00" }, - { label: "19:30", value: "19:30" }, - { label: "20:00", value: "20:00" }, - { label: "20:30", value: "20:30" }, - { label: "21:00", value: "21:00" }, - { label: "21:30", value: "21:30" }] + expected = [{ text: { text: "08:00", type: "plain_text" }, value: "08:00" }, + { text: { text: "08:30", type: "plain_text" }, value: "08:30" }, + { text: { text: "09:00", type: "plain_text" }, value: "09:00" }, + { text: { text: "09:30", type: "plain_text" }, value: "09:30" }, + { text: { text: "10:00", type: "plain_text" }, value: "10:00" }, + { text: { text: "10:30", type: "plain_text" }, value: "10:30" }, + { text: { text: "11:00", type: "plain_text" }, value: "11:00" }, + { text: { text: "11:30", type: "plain_text" }, value: "11:30" }, + { text: { text: "12:00", type: "plain_text" }, value: "12:00" }, + { text: { text: "12:30", type: "plain_text" }, value: "12:30" }, + { text: { text: "13:00", type: "plain_text" }, value: "13:00" }, + { text: { text: "13:30", type: "plain_text" }, value: "13:30" }, + { text: { text: "14:00", type: "plain_text" }, value: "14:00" }, + { text: { text: "14:30", type: "plain_text" }, value: "14:30" }, + { text: { text: "15:00", type: "plain_text" }, value: "15:00" }, + { text: { text: "15:30", type: "plain_text" }, value: "15:30" }, + { text: { text: "16:00", type: "plain_text" }, value: "16:00" }, + { text: { text: "16:30", type: "plain_text" }, value: "16:30" }, + { text: { text: "17:00", type: "plain_text" }, value: "17:00" }, + { text: { text: "17:30", type: "plain_text" }, value: "17:30" }, + { text: { text: "18:00", type: "plain_text" }, value: "18:00" }, + { text: { text: "18:30", type: "plain_text" }, value: "18:30" }, + { text: { text: "19:00", type: "plain_text" }, value: "19:00" }, + { text: { text: "19:30", type: "plain_text" }, value: "19:30" }, + { text: { text: "20:00", type: "plain_text" }, value: "20:00" }, + { text: { text: "20:30", type: "plain_text" }, value: "20:30" }, + { text: { text: "21:00", type: "plain_text" }, value: "21:00" }, + { text: { text: "21:30", type: "plain_text" }, value: "21:30" }] expect(instance.send(:time_select_options)).to eq expected end end From 74d552ed85e1da65b0fd85905fe76ee0b15ac096 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 19:59:40 +0900 Subject: [PATCH 03/22] =?UTF-8?q?select=E8=A6=81=E7=B4=A0=E3=82=92modal=20?= =?UTF-8?q?view=E7=94=A8=E3=81=AE=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog.rb | 100 +++++++++++++++++---------- spec/app/models/slack_dialog_spec.rb | 25 +++++-- 2 files changed, 81 insertions(+), 44 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index 0813ec7..634312c 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -25,38 +25,55 @@ def self.open(trigger_id) private - # @param trigger_id [String] # @return [Hash] # @private - def post_body(trigger_id) - { trigger_id:, - dialog: { - title: MESSAGES["dialog"]["tilte"], - callback_id: "callback_id", - submit_label: MESSAGES["dialog"]["submit"], - elements: [ - select_element( - label: MESSAGES["dialog"]["recept_date"], - name: "date", - options: date_select_options - ), - select_element( - label: MESSAGES["dialog"]["recept_time"], - name: "time", - options: time_select_options - ), - textarea_element( - label: MESSAGES["dialog"]["recept_company"], - name: "company_name", - placeholder: MESSAGES["dialog"]["recept_company_placeholder"] - ), - textarea_element( - label: MESSAGES["dialog"]["recept_name"], - name: "name", - placeholder: MESSAGES["dialog"]["recept_name_placeholder"] - ) - ] - } } + def post_body + { type: "modal", + callback_id: "callback_id", + title: { + type: "plain_text", + text: MESSAGES["dialog"]["tilte"] + }, + submit: { + type: "plain_text", + text: "送信" + }, + close: { + type: "plain_text", + text: "キャンセル" + }, + blocks: [ + select_element( + block_id: "recept_date", + label_text: MESSAGES["dialog"]["recept_date"], + options: date_select_options + ), + select_element( + block_id: "recept_time", + label_text: MESSAGES["dialog"]["recept_time"], + options: time_select_options + ), + { type: "input", + block_id: "recept_company", + element: { + action_id: "recept_company", + type: "plain_text_input" + }, + label: { + type: "plain_text", + text: MESSAGES["dialog"]["recept_company"] + } }, + { type: "input", + block_id: "recept_name", + element: { + action_id: "recept_name", + type: "plain_text_input" + }, + label: { + type: "plain_text", + text: MESSAGES["dialog"]["recept_name"] + } } + ] } end # @param label [String] @@ -72,17 +89,26 @@ def textarea_element(label:, name:, placeholder:) placeholder: } end - # @param label [String] - # @param name [String] + # @param block_id [String] + # @param label_text [String] # @param options [Array] # @return [Hash] # @see https://api.slack.com/dialogs#select_elements # @pprivate - def select_element(label:, name:, options:) - { label:, - type: "select", - name:, - options: } + def select_element(block_id:, label_text:, options:, action_id: nil) + { + type: "input", + block_id:, + element: { + type: "static_select", + action_id: action_id || block_id, + options: + }, + label: { + type: "plain_text", + text: label_text + } + } end # @return [Array] diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index 6a9d555..2706af1 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -54,13 +54,24 @@ describe "#select_element" do context "ok" do it do - expected = { label: "label", - type: "select", - name: "element name", - options: [] } - args = { label: "label", - name: "element name", - options: [] } + expected = { + type: "input", + block_id: "block_id", + element: { + type: "static_select", + action_id: "block_id", + options: [] + }, + label: { + type: "plain_text", + text: "label_text" + } + } + args = { + block_id: "block_id", + label_text: "label_text", + options: [] + } expect(instance.send(:select_element, **args)).to eq expected end end From cfc08c1d1a328021d20fcfe319f669d03ad3a2d6 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:12:17 +0900 Subject: [PATCH 04/22] =?UTF-8?q?text=E5=85=A5=E5=8A=9B=E7=94=A8=E3=81=AE?= =?UTF-8?q?=E8=A6=81=E7=B4=A0=E3=82=92modal=20view=E7=94=A8=E3=81=AE?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog.rb | 70 +++++++++++++++------------- spec/app/models/slack_dialog_spec.rb | 32 +++++++++---- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index 634312c..7ef7252 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -28,7 +28,8 @@ def self.open(trigger_id) # @return [Hash] # @private def post_body - { type: "modal", + { + type: "modal", callback_id: "callback_id", title: { type: "plain_text", @@ -53,47 +54,52 @@ def post_body label_text: MESSAGES["dialog"]["recept_time"], options: time_select_options ), - { type: "input", + plain_text_element( block_id: "recept_company", - element: { - action_id: "recept_company", - type: "plain_text_input" - }, - label: { - type: "plain_text", - text: MESSAGES["dialog"]["recept_company"] - } }, - { type: "input", + label: MESSAGES["dialog"]["recept_company"], + placeholder: MESSAGES["dialog"]["recept_company_placeholder"] + ), + plain_text_element( block_id: "recept_name", - element: { - action_id: "recept_name", - type: "plain_text_input" - }, - label: { - type: "plain_text", - text: MESSAGES["dialog"]["recept_name"] - } } - ] } + label: MESSAGES["dialog"]["recept_name"], + placeholder: MESSAGES["dialog"]["recept_name_placeholder"] + ) + ] + } end - # @param label [String] - # @param name [String] + # @param block_id [String] + # @param label [String] # @param placeholder [String] + # @param action_id [String] # @return [Hash] - # @see https://api.slack.com/dialogs#dialogs__dialog-form-elements__textarea-elements + # @see https://api.slack.com/reference/block-kit/block-elements#input # @pprivate - def textarea_element(label:, name:, placeholder:) - { label:, - type: "text", - name:, - placeholder: } + def plain_text_element(block_id:, label:, placeholder:, action_id: nil) + { + type: "input", + block_id:, + element: { + action_id: action_id || block_id, + type: "plain_text_input", + placeholder: { + type: "plain_text", + text: placeholder + } + }, + label: { + type: "plain_text", + text: label + } + } end - # @param block_id [String] - # @param label_text [String] - # @param options [Array] + # @param block_id [String] + # @param label_text [String] + # @param options [Array] + # @param action_id [String] # @return [Hash] - # @see https://api.slack.com/dialogs#select_elements + # @see https://api.slack.com/reference/block-kit/block-elements#select # @pprivate def select_element(block_id:, label_text:, options:, action_id: nil) { diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index 2706af1..e3d5a99 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -37,17 +37,31 @@ end end end - describe "#textarea_element" do + describe "#plain_text_element" do context "ok" do it do - expected = { label: "label", - type: "text", - name: "element name", - placeholder: "placeholder" } - args = { label: "label", - name: "element name", - placeholder: "placeholder" } - expect(instance.send(:textarea_element, **args)).to eq expected + expected = { + type: "input", + block_id: "block_id", + element: { + action_id: "block_id", + type: "plain_text_input", + placeholder: { + type: "plain_text", + text: "placeholder" + } + }, + label: { + type: "plain_text", + text: "label" + } + } + args = { + block_id: "block_id", + label: "label", + placeholder: "placeholder" + } + expect(instance.send(:plain_text_element, **args)).to eq expected end end end From f10f268a49254c3ed71e9f9d32ad590b77d30f01 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:13:28 +0900 Subject: [PATCH 05/22] =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=AA=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E3=81=AA=E3=81=AE=E3=81=A7=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog.rb | 10 +++++----- spec/app/models/slack_dialog_spec.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index 7ef7252..98b8a7a 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -46,12 +46,12 @@ def post_body blocks: [ select_element( block_id: "recept_date", - label_text: MESSAGES["dialog"]["recept_date"], + label: MESSAGES["dialog"]["recept_date"], options: date_select_options ), select_element( block_id: "recept_time", - label_text: MESSAGES["dialog"]["recept_time"], + label: MESSAGES["dialog"]["recept_time"], options: time_select_options ), plain_text_element( @@ -95,13 +95,13 @@ def plain_text_element(block_id:, label:, placeholder:, action_id: nil) end # @param block_id [String] - # @param label_text [String] + # @param label [String] # @param options [Array] # @param action_id [String] # @return [Hash] # @see https://api.slack.com/reference/block-kit/block-elements#select # @pprivate - def select_element(block_id:, label_text:, options:, action_id: nil) + def select_element(block_id:, label:, options:, action_id: nil) { type: "input", block_id:, @@ -112,7 +112,7 @@ def select_element(block_id:, label_text:, options:, action_id: nil) }, label: { type: "plain_text", - text: label_text + text: label } } end diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index e3d5a99..3805168 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -83,7 +83,7 @@ } args = { block_id: "block_id", - label_text: "label_text", + label: "label_text", options: [] } expect(instance.send(:select_element, **args)).to eq expected From 371375e36e265d634bb9f79c099fa19bd39dc2b6 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:25:47 +0900 Subject: [PATCH 06/22] =?UTF-8?q?post=5Fbody=E3=81=AEspec=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/app/models/slack_dialog_spec.rb | 99 +++++++++++++++++++++------- 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_dialog_spec.rb index 3805168..4e3d473 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_dialog_spec.rb @@ -10,30 +10,83 @@ context "ok" do it do expected = { - trigger_id: "trigger_id", - dialog: { - title: "六本木グランドタワー入館受付申請", - callback_id: "callback_id", - submit_label: "送信", - elements: [{ label: "来訪日", - type: "select", - name: "date", - options: instance.send(:date_select_options) }, - { label: "訪問時間", - type: "select", - name: "time", - options: instance.send(:time_select_options) }, - { label: "来訪者会社名", - type: "text", - name: "company_name", - placeholder: "会社名がない場合は「面接」「なし」等" }, - { label: "来訪者名", - type: "text", - name: "name", - placeholder: "「様」をつけると入館証が「様様」になるよ!" }] - } + type: "modal", + callback_id: "callback_id", + title: { + type: "plain_text", + text: "六本木グランドタワー入館受付申請" + }, + submit: { + type: "plain_text", + text: "送信" + }, + close: { + type: "plain_text", + text: "キャンセル" + }, + blocks: [ + { + type: "input", + block_id: "recept_date", + element: { + type: "static_select", + action_id: "recept_date", + options: instance.send(:date_select_options) + }, + label: { + type: "plain_text", + text: "来訪日" + } + }, + { + type: "input", + block_id: "recept_time", + element: { + type: "static_select", + action_id: "recept_time", + options: instance.send(:time_select_options) + }, + label: { + type: "plain_text", + text: "訪問時間" + } + }, + { + type: "input", + block_id: "recept_company", + element: { + action_id: "recept_company", + type: "plain_text_input", + placeholder: { + type: "plain_text", + text: "会社名がない場合は「面接」「なし」等" + } + }, + label: { + type: "plain_text", + text: "来訪者会社名" + } + }, + { + type: "input", + block_id: "recept_name", + element: { + action_id: "recept_name", + type: "plain_text_input", + placeholder: { + type: "plain_text", + text: "「様」をつけると入館証が「様様」になるよ!" + } + }, + label: { + type: "plain_text", + text: "来訪者名" + } + } + ] } - expect(instance.send(:post_body, "trigger_id")).to eq expected + + expect(instance.send(:post_body)).to eq expected end end end From e5718d9e16cf58fbe974c6a6e8c14422045a6743 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:26:18 +0900 Subject: [PATCH 07/22] fix typo --- app/models/slack_dialog.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/slack_dialog.rb b/app/models/slack_dialog.rb index 98b8a7a..b221e1d 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_dialog.rb @@ -74,7 +74,7 @@ def post_body # @param action_id [String] # @return [Hash] # @see https://api.slack.com/reference/block-kit/block-elements#input - # @pprivate + # @private def plain_text_element(block_id:, label:, placeholder:, action_id: nil) { type: "input", @@ -100,7 +100,7 @@ def plain_text_element(block_id:, label:, placeholder:, action_id: nil) # @param action_id [String] # @return [Hash] # @see https://api.slack.com/reference/block-kit/block-elements#select - # @pprivate + # @private def select_element(block_id:, label:, options:, action_id: nil) { type: "input", @@ -118,7 +118,7 @@ def select_element(block_id:, label:, options:, action_id: nil) end # @return [Array] - # @pprivate + # @private def date_select_options dates = (Date.today...(Date.today + SELECT_DATE_RANGE_NUM)).to_a dates.map do |date| @@ -134,7 +134,7 @@ def date_select_options end # @return [Array] - # @pprivate + # @private def time_select_options hours = (SELECT_TIME_HOUR_START..SELECT_TIME_HOUR_END).to_a hours.map do |hour| From beee775302121f03c894d934a162c41409b20151 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:29:46 +0900 Subject: [PATCH 08/22] =?UTF-8?q?=E5=AE=9F=E7=8A=B6=E3=81=AB=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=A6=E3=82=AF=E3=83=A9=E3=82=B9=E5=90=8D?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/{slack_dialog.rb => slack_modal.rb} | 6 +----- .../models/{slack_dialog_spec.rb => slack_modal_spec.rb} | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) rename app/models/{slack_dialog.rb => slack_modal.rb} (95%) rename spec/app/models/{slack_dialog_spec.rb => slack_modal_spec.rb} (99%) diff --git a/app/models/slack_dialog.rb b/app/models/slack_modal.rb similarity index 95% rename from app/models/slack_dialog.rb rename to app/models/slack_modal.rb index b221e1d..097d4c4 100644 --- a/app/models/slack_dialog.rb +++ b/app/models/slack_modal.rb @@ -4,7 +4,7 @@ require "yaml" # @see https://api.slack.com/dialogs -class SlackDialog +class SlackModal SELECT_DATE_RANGE_NUM = 90 SELECT_TIME_HOUR_START = 8 SELECT_TIME_HOUR_END = 21 @@ -16,10 +16,7 @@ class SlackDialog # @param trigger_id [String] def self.open(trigger_id) post_body = new.send(:post_body) - - # https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/dialog.rb client = Slack::Web::Client.new(token: ENV.fetch("SLACK_TOKEN")) - # client.dialog_open(post_body) client.views_open(trigger_id:, view: post_body) end @@ -124,7 +121,6 @@ def date_select_options dates.map do |date| date_text = date.strftime("%Y/%m/%d") wday = %w[日 月 火 水 木 金 土][date.wday] - { text: { type: "plain_text", text: "#{date_text} #{wday}" diff --git a/spec/app/models/slack_dialog_spec.rb b/spec/app/models/slack_modal_spec.rb similarity index 99% rename from spec/app/models/slack_dialog_spec.rb rename to spec/app/models/slack_modal_spec.rb index 4e3d473..1eac75f 100644 --- a/spec/app/models/slack_dialog_spec.rb +++ b/spec/app/models/slack_modal_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" require_relative "../../../app/models/slack_dialog" -describe SlackDialog do +describe SlackModal do let(:instance) { described_class.new } describe "#post_body" do From 9c9773c4d02091cb4a98d7763c308759c83bdb63 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:31:33 +0900 Subject: [PATCH 09/22] =?UTF-8?q?path=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/app/models/slack_modal_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/app/models/slack_modal_spec.rb b/spec/app/models/slack_modal_spec.rb index 1eac75f..bd07c6b 100644 --- a/spec/app/models/slack_modal_spec.rb +++ b/spec/app/models/slack_modal_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "spec_helper" -require_relative "../../../app/models/slack_dialog" +require_relative "../../../app/models/slack_modal" describe SlackModal do let(:instance) { described_class.new } From e2c1c9a88ae236143183bc49805e6e3ebc51a3f3 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Thu, 22 Aug 2024 20:33:05 +0900 Subject: [PATCH 10/22] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=BC=8F=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/slack_slash_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/slack_slash_command.rb b/app/controllers/slack_slash_command.rb index 82597f9..1872359 100644 --- a/app/controllers/slack_slash_command.rb +++ b/app/controllers/slack_slash_command.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative "../models/slack_dialog" +require_relative "../models/slack_modal" # @see https://api.slack.com/interactivity/slash-commands module SlackSlashCommand def run(request) - SlackDialog.open(request["trigger_id"]) + SlackModal.open(request["trigger_id"]) "" end From 767423eae657d0cbbbe24b02ddbeef9442db132d Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 14:21:18 +0900 Subject: [PATCH 11/22] =?UTF-8?q?modal=E3=81=AEsubmission=E6=99=82?= =?UTF-8?q?=E3=81=AEpost=5Fbody=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog_submission.rb | 9 ++--- .../models/slack_dialog_submission_spec.rb | 36 ++++++------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/app/models/slack_dialog_submission.rb b/app/models/slack_dialog_submission.rb index ef4e827..3793442 100644 --- a/app/models/slack_dialog_submission.rb +++ b/app/models/slack_dialog_submission.rb @@ -8,6 +8,7 @@ class SlackDialogSubmission # @param post_body [Hash] def initialize(post_body) @post_body = post_body.deep_symbolize_keys + @values = @post_body.dig(:view, :state, :values) end # @return [String] @@ -22,21 +23,21 @@ def slack_channel_id # @return [String] def recept_date - @post_body.dig(:submission, :date) + @values[:recept_date][:recept_date][:selected_option][:value] end # @return [String] def recept_time - @post_body.dig(:submission, :time) + @values[:recept_time][:recept_time][:selected_option][:value] end # @return [String] def company_name - @post_body.dig(:submission, :company_name) + @values[:recept_company][:recept_company][:value] end # @return [String] def visitor_name - @post_body.dig(:submission, :name) + @values[:recept_name][:recept_name][:value] end end diff --git a/spec/app/models/slack_dialog_submission_spec.rb b/spec/app/models/slack_dialog_submission_spec.rb index 89189d9..a0458db 100644 --- a/spec/app/models/slack_dialog_submission_spec.rb +++ b/spec/app/models/slack_dialog_submission_spec.rb @@ -7,13 +7,19 @@ describe SlackDialogSubmission do let(:instance) { described_class.new(post_body) } let(:fixture) do - { type: "dialog_submission", + { type: "view_submission", user: { id: "UCKTXCBRB" }, channel: { id: "CH15TJXEX" }, - submission: { date: "2023/01/01", - time: "08:00", - company_name: "SmartHR", - name: "須磨 英知" } } + view: { + state: { + values: { + recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, + recept_time: { recept_time: { selected_option: { value: "08:00" } } }, + recept_company: { recept_company: { value: "SmartHR" } }, + recept_name: { recept_name: { value: "須磨 英知" } } + } + } + } } end describe "#slack_user_id" do @@ -27,50 +33,30 @@ end end describe "#slack_channel_id" do - context "ok" do - let(:post_body) { { channel: { id: "CH15TJXEX" } } } - it { expect(instance.slack_channel_id).to eq "CH15TJXEX" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.slack_channel_id).to eq "CH15TJXEX" } end end describe "#recept_date" do - context "ok" do - let(:post_body) { { submission: { date: "2023/01/01" } } } - it { expect(instance.recept_date).to eq "2023/01/01" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.recept_date).to eq "2023/01/01" } end end describe "#recept_time" do - context "ok" do - let(:post_body) { { submission: { time: "08:00" } } } - it { expect(instance.recept_time).to eq "08:00" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.recept_time).to eq "08:00" } end end describe "#company_name" do - context "ok" do - let(:post_body) { { submission: { company_name: "SmartHR" } } } - it { expect(instance.company_name).to eq "SmartHR" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.company_name).to eq "SmartHR" } end end describe "#visitor_name" do - context "ok" do - let(:post_body) { { submission: { name: "須磨 英知" } } } - it { expect(instance.visitor_name).to eq "須磨 英知" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.visitor_name).to eq "須磨 英知" } From 48e88172b393878a960afca7fdc6df69664e0625 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 14:24:09 +0900 Subject: [PATCH 12/22] =?UTF-8?q?SlackDialogSubmission=E3=82=92=E5=8F=82?= =?UTF-8?q?=E7=85=A7=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/workers/reception_worker.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/workers/reception_worker.rb b/app/workers/reception_worker.rb index 0668160..712bb4c 100644 --- a/app/workers/reception_worker.rb +++ b/app/workers/reception_worker.rb @@ -13,11 +13,11 @@ class ReceptionWorker def perform(slack_dialog) dialog_submission = SlackDialogSubmission.new(slack_dialog) # slack dialog input - recept_date = slack_dialog["submission"]["date"] - recept_time = slack_dialog["submission"]["time"] - recept_company_name = slack_dialog["submission"]["company_name"] - recept_visitor_name = slack_dialog["submission"]["name"] - slack_id = slack_dialog["user"]["id"] + recept_date = dialog_submission.recept_date + recept_time = dialog_submission.recept_time + recept_company_name = dialog_submission.company_name + recept_visitor_name = dialog_submission.visitor_name + slack_id = dialog_submission.slack_user_id # srd-gate login agent = Mechanize.new From 55c707d86c7b572b0548b01af322247e6a5571c5 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 14:37:02 +0900 Subject: [PATCH 13/22] =?UTF-8?q?modal=E3=81=AEsubmission=E3=81=AFchannel?= =?UTF-8?q?=5Fid=E3=82=92=E6=8C=81=E3=81=9F=E3=81=AA=E3=81=84=E3=81=AE?= =?UTF-8?q?=E3=81=A7SLACK=5FCHANNEL=5FID=E3=82=92=E5=8F=82=E7=85=A7?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_dialog_submission.rb | 2 +- .../app/models/slack_dialog_submission_spec.rb | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/slack_dialog_submission.rb b/app/models/slack_dialog_submission.rb index 3793442..6cd1b76 100644 --- a/app/models/slack_dialog_submission.rb +++ b/app/models/slack_dialog_submission.rb @@ -18,7 +18,7 @@ def slack_user_id # @return [String] def slack_channel_id - @post_body.dig(:channel, :id) + ENV.fetch("SLACK_CHANNEL", slack_user_id) end # @return [String] diff --git a/spec/app/models/slack_dialog_submission_spec.rb b/spec/app/models/slack_dialog_submission_spec.rb index a0458db..a6be428 100644 --- a/spec/app/models/slack_dialog_submission_spec.rb +++ b/spec/app/models/slack_dialog_submission_spec.rb @@ -9,7 +9,6 @@ let(:fixture) do { type: "view_submission", user: { id: "UCKTXCBRB" }, - channel: { id: "CH15TJXEX" }, view: { state: { values: { @@ -23,19 +22,24 @@ end describe "#slack_user_id" do - context "ok" do - let(:post_body) { { user: { id: "UCKTXCBRB" } } } - it { expect(instance.slack_user_id).to eq "UCKTXCBRB" } - end context "ok fixture" do let(:post_body) { fixture } it { expect(instance.slack_user_id).to eq "UCKTXCBRB" } end end describe "#slack_channel_id" do - context "ok fixture" do + context "環境変数が指定されていない場合" do + let(:post_body) { fixture } + it "投稿者のslack_user_idを返す" do + expect(instance.slack_channel_id).to eq "UCKTXCBRB" + end + end + context "環境変数が指定されている場合" do let(:post_body) { fixture } - it { expect(instance.slack_channel_id).to eq "CH15TJXEX" } + it "環境変数(SLACK_CHANNEL_ID)の値を返す" do + allow(ENV).to receive(:fetch).with("SLACK_CHANNEL", "UCKTXCBRB").and_return("SLACK_CHANNEL") + expect(instance.slack_channel_id).to eq "SLACK_CHANNEL" + end end end describe "#recept_date" do From 57809a3a29f63a0eb20b83d1693a714e9117a8fb Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 14:55:32 +0900 Subject: [PATCH 14/22] =?UTF-8?q?dialog=E3=81=8B=E3=82=89modal=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=9F=E3=81=AE=E3=81=A7=E9=96=A2?= =?UTF-8?q?=E9=80=A3=E5=87=A6=E7=90=86=E3=82=92rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/slack_interactive_message.rb | 2 +- app/models/slack_message.rb | 21 +++++++++---------- app/models/slack_modal.rb | 2 +- ...ubmission.rb => slack_modal_submission.rb} | 4 ++-- app/workers/reception_worker.rb | 20 +++++++++--------- spec/app/models/slack_message_spec.rb | 14 ++++++------- ...spec.rb => slack_modal_submission_spec.rb} | 4 ++-- 7 files changed, 33 insertions(+), 34 deletions(-) rename app/models/{slack_dialog_submission.rb => slack_modal_submission.rb} (92%) rename spec/app/models/{slack_dialog_submission_spec.rb => slack_modal_submission_spec.rb} (95%) diff --git a/app/controllers/slack_interactive_message.rb b/app/controllers/slack_interactive_message.rb index 845d5d6..34e7406 100644 --- a/app/controllers/slack_interactive_message.rb +++ b/app/controllers/slack_interactive_message.rb @@ -6,7 +6,7 @@ module SlackInteractiveMessage def run(request) # Slack のレスポンス3秒以内ルールのため非同期処理 - # https://api.slack.com/dialogs#submit + # https://api.slack.com/reference/interaction-payloads/views#view_submission ReceptionWorker.perform_async JSON.parse(request["payload"]) "" diff --git a/app/models/slack_message.rb b/app/models/slack_message.rb index bb8d103..415a849 100644 --- a/app/models/slack_message.rb +++ b/app/models/slack_message.rb @@ -6,16 +6,15 @@ class SlackMessage # TODO: fix Ruby 3.1+ https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Security/YAMLLoadQ MESSAGES = open("./config/messages.yml", "r") { |f| YAML.unsafe_load(f) } - # @param dialog_submission [SlackDialogSubmission] - # @param dialog_submission [Email] - def initialize(dialog_submission: nil) - @dialog_submission = dialog_submission + # @param modal_submission [SlackModalSubmission] + def initialize(modal_submission: nil) + @modal_submission = modal_submission end # Factory Method - # @param dialog_submission [SlackDialogSubmission] - def self.post_received_message(dialog_submission) - post_body = new(dialog_submission:) + # @param modal_submission [SlackModalSubmission] + def self.post_received_message(modal_submission) + post_body = new(modal_submission:) .send(:received_message_post_body) ChatMessageSender.new.post_private_message(post_body) @@ -29,8 +28,8 @@ def self.post_received_message(dialog_submission) # @private def received_message_post_body { icon_emoji: MESSAGES["intarctive"]["icon"], - channel: @dialog_submission.slack_channel_id, - user: @dialog_submission.slack_user_id, + channel: @modal_submission.slack_channel_id, + user: @modal_submission.slack_user_id, text:, attachments: [attachment(fields: received_message_attachment_fields)] } end @@ -55,11 +54,11 @@ def received_message_attachment_fields [ attachment_field( title: MESSAGES["intarctive"]["recept_name"], - value: "#{@dialog_submission.company_name} #{@dialog_submission.visitor_name} 様" + value: "#{@modal_submission.company_name} #{@modal_submission.visitor_name} 様" ), attachment_field( title: MESSAGES["intarctive"]["recept_datetime"], - value: "#{@dialog_submission.recept_date} #{@dialog_submission.recept_time}" + value: "#{@modal_submission.recept_date} #{@modal_submission.recept_time}" ) ] end diff --git a/app/models/slack_modal.rb b/app/models/slack_modal.rb index 097d4c4..7555c2e 100644 --- a/app/models/slack_modal.rb +++ b/app/models/slack_modal.rb @@ -3,7 +3,7 @@ require "date" require "yaml" -# @see https://api.slack.com/dialogs +# @see https://api.slack.com/surfaces/modals class SlackModal SELECT_DATE_RANGE_NUM = 90 SELECT_TIME_HOUR_START = 8 diff --git a/app/models/slack_dialog_submission.rb b/app/models/slack_modal_submission.rb similarity index 92% rename from app/models/slack_dialog_submission.rb rename to app/models/slack_modal_submission.rb index 6cd1b76..2e1e32d 100644 --- a/app/models/slack_dialog_submission.rb +++ b/app/models/slack_modal_submission.rb @@ -3,8 +3,8 @@ require "active_support" require "active_support/core_ext/hash/indifferent_access" -# @see https://api.slack.com/dialogs -class SlackDialogSubmission +# @see https://api.slack.com/surfaces/modals +class SlackModalSubmission # @param post_body [Hash] def initialize(post_body) @post_body = post_body.deep_symbolize_keys diff --git a/app/workers/reception_worker.rb b/app/workers/reception_worker.rb index 712bb4c..1036f03 100644 --- a/app/workers/reception_worker.rb +++ b/app/workers/reception_worker.rb @@ -3,21 +3,21 @@ require "mechanize" require "sidekiq" require "slack-ruby-client" -require_relative "../models/slack_dialog_submission" +require_relative "../models/slack_modal_submission" require_relative "../models/slack_message" class ReceptionWorker include Sidekiq::Worker sidekiq_options queue: :default, retry: false - def perform(slack_dialog) - dialog_submission = SlackDialogSubmission.new(slack_dialog) - # slack dialog input - recept_date = dialog_submission.recept_date - recept_time = dialog_submission.recept_time - recept_company_name = dialog_submission.company_name - recept_visitor_name = dialog_submission.visitor_name - slack_id = dialog_submission.slack_user_id + def perform(slack_modal) + modal_submission = SlackModalSubmission.new(slack_modal) + # slack modal input + recept_date = modal_submission.recept_date + recept_time = modal_submission.recept_time + recept_company_name = modal_submission.company_name + recept_visitor_name = modal_submission.visitor_name + slack_id = modal_submission.slack_user_id # srd-gate login agent = Mechanize.new @@ -46,6 +46,6 @@ def perform(slack_dialog) # regist agent.page.form.submit - SlackMessage.post_received_message(dialog_submission) + SlackMessage.post_received_message(modal_submission) end end diff --git a/spec/app/models/slack_message_spec.rb b/spec/app/models/slack_message_spec.rb index 0dd692a..6b2be29 100644 --- a/spec/app/models/slack_message_spec.rb +++ b/spec/app/models/slack_message_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" require_relative "../../../app/models/email" -require_relative "../../../app/models/slack_dialog_submission" +require_relative "../../../app/models/slack_modal_submission" require_relative "../../../app/models/slack_message" describe SlackMessage do @@ -19,8 +19,8 @@ time: "08:00", company_name: "SmartHR", name: "須磨 英知" } } - dialog_submission = SlackDialogSubmission.new(modal_submit_fixture) - instance = described_class.new(dialog_submission:) + modal_submission = SlackModalSubmission.new(modal_submit_fixture) + instance = described_class.new(modal_submission:) expected = { channel: "CH15TJXEX", @@ -46,8 +46,8 @@ time: "08:00", company_name: "SmartHR", name: "須磨 英知" } } - dialog_submission = SlackDialogSubmission.new(modal_submit_fixture) - instance = described_class.new(dialog_submission:) + modal_submission = SlackModalSubmission.new(modal_submit_fixture) + instance = described_class.new(modal_submission:) expected = { channel: "CH15TJXEX", @@ -72,8 +72,8 @@ time: "08:00", company_name: "SmartHR", name: "須磨 英知" } } - dialog_submission = SlackDialogSubmission.new(modal_submit_fixture) - instance = described_class.new(dialog_submission:) + modal_submission = SlackModalSubmission.new(modal_submit_fixture) + instance = described_class.new(modal_submission:) expected = [ { short: true, title: "来訪者名", value: "SmartHR 須磨 英知 様" }, diff --git a/spec/app/models/slack_dialog_submission_spec.rb b/spec/app/models/slack_modal_submission_spec.rb similarity index 95% rename from spec/app/models/slack_dialog_submission_spec.rb rename to spec/app/models/slack_modal_submission_spec.rb index a6be428..ddaf808 100644 --- a/spec/app/models/slack_dialog_submission_spec.rb +++ b/spec/app/models/slack_modal_submission_spec.rb @@ -2,9 +2,9 @@ require "spec_helper" require "json" -require_relative "../../../app/models/slack_dialog_submission" +require_relative "../../../app/models/slack_modal_submission" -describe SlackDialogSubmission do +describe SlackModalSubmission do let(:instance) { described_class.new(post_body) } let(:fixture) do { type: "view_submission", From 7ede5fee8fe9c37592f4fb2d49c6131cce09c590 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 15:15:20 +0900 Subject: [PATCH 15/22] =?UTF-8?q?SlackMessage=E3=81=AEspec=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/app/models/slack_message_spec.rb | 58 ++++++++++++++++++--------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/spec/app/models/slack_message_spec.rb b/spec/app/models/slack_message_spec.rb index 6b2be29..7929c95 100644 --- a/spec/app/models/slack_message_spec.rb +++ b/spec/app/models/slack_message_spec.rb @@ -11,19 +11,26 @@ describe "#received_message_post_body" do context "チャンネルに通知する場合" do it "適切なメッセージが通知されること" do + allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("CHANNEL") - modal_submit_fixture = { type: "dialog_submission", + allow(ENV).to receive(:fetch).with("SLACK_CHANNEL", "UCKTXCBRB").and_return("SLACK_CHANNEL") + modal_submit_fixture = { type: "view_submission", user: { id: "UCKTXCBRB" }, - channel: { id: "CH15TJXEX" }, - submission: { date: "2023/01/01", - time: "08:00", - company_name: "SmartHR", - name: "須磨 英知" } } + view: { + state: { + values: { + recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, + recept_time: { recept_time: { selected_option: { value: "08:00" } } }, + recept_company: { recept_company: { value: "SmartHR" } }, + recept_name: { recept_name: { value: "須磨 英知" } } + } + } + } } modal_submission = SlackModalSubmission.new(modal_submit_fixture) instance = described_class.new(modal_submission:) expected = { - channel: "CH15TJXEX", + channel: "SLACK_CHANNEL", icon_emoji: ":office:", text: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:", user: "UCKTXCBRB", @@ -38,19 +45,25 @@ end context "DMに通知する場合" do it "適切なメッセージが通知されること" do + allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("DM") - modal_submit_fixture = { type: "dialog_submission", + modal_submit_fixture = { type: "view_submission", user: { id: "UCKTXCBRB" }, - channel: { id: "CH15TJXEX" }, - submission: { date: "2023/01/01", - time: "08:00", - company_name: "SmartHR", - name: "須磨 英知" } } + view: { + state: { + values: { + recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, + recept_time: { recept_time: { selected_option: { value: "08:00" } } }, + recept_company: { recept_company: { value: "SmartHR" } }, + recept_name: { recept_name: { value: "須磨 英知" } } + } + } + } } modal_submission = SlackModalSubmission.new(modal_submit_fixture) instance = described_class.new(modal_submission:) expected = { - channel: "CH15TJXEX", + channel: "UCKTXCBRB", icon_emoji: ":office:", text: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:", user: "UCKTXCBRB", @@ -65,13 +78,18 @@ describe "#received_message_attachment_fields" do context "ok" do it do - modal_submit_fixture = { type: "dialog_submission", + modal_submit_fixture = { type: "view_submission", user: { id: "UCKTXCBRB" }, - channel: { id: "CH15TJXEX" }, - submission: { date: "2023/01/01", - time: "08:00", - company_name: "SmartHR", - name: "須磨 英知" } } + view: { + state: { + values: { + recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, + recept_time: { recept_time: { selected_option: { value: "08:00" } } }, + recept_company: { recept_company: { value: "SmartHR" } }, + recept_name: { recept_name: { value: "須磨 英知" } } + } + } + } } modal_submission = SlackModalSubmission.new(modal_submit_fixture) instance = described_class.new(modal_submission:) From d96bb92e14ac4f8ea5ec1263adb3ca1a14954a8b Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 15:17:58 +0900 Subject: [PATCH 16/22] =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/chat_message_sender.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/chat_message_sender.rb b/app/models/chat_message_sender.rb index fbe60cb..014beb0 100644 --- a/app/models/chat_message_sender.rb +++ b/app/models/chat_message_sender.rb @@ -14,10 +14,6 @@ def post_public_message(post_body) @slack_api_client.chat_postMessage(post_body) end - def post_direct_message(post_body) - @slack_api_client.chat_postMessage(post_body) - end - # 特定のユーザーだけに見える形で投稿 # @param post_body [Hash] # @see https://api.slack.com/methods/chat.postEphemeral From c11b2618cb49fbae69cb69328e787b27524a7e66 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 15:19:41 +0900 Subject: [PATCH 17/22] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=81=A8=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E6=85=8B=E3=81=AB=E4=BD=B5=E3=81=9B=E3=81=A6=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/chat_message_sender.rb | 3 +-- app/models/slack_message.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/chat_message_sender.rb b/app/models/chat_message_sender.rb index 014beb0..670611a 100644 --- a/app/models/chat_message_sender.rb +++ b/app/models/chat_message_sender.rb @@ -6,7 +6,6 @@ def initialize @slack_api_client = Slack::Web::Client.new(token: ENV.fetch("SLACK_TOKEN")) end - # 全ユーザーに見える形で投稿 # @param post_body [Hash] # @see https://api.slack.com/methods/chat.postMessage # @see https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/chat.rb @@ -18,7 +17,7 @@ def post_public_message(post_body) # @param post_body [Hash] # @see https://api.slack.com/methods/chat.postEphemeral # @see https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/chat.rb - def post_private_message(post_body) + def post_ephemeral_message(post_body) @slack_api_client.chat_postEphemeral(post_body) end end diff --git a/app/models/slack_message.rb b/app/models/slack_message.rb index 415a849..76b986a 100644 --- a/app/models/slack_message.rb +++ b/app/models/slack_message.rb @@ -17,7 +17,7 @@ def self.post_received_message(modal_submission) post_body = new(modal_submission:) .send(:received_message_post_body) - ChatMessageSender.new.post_private_message(post_body) + ChatMessageSender.new.post_ephemeral_message(post_body) end private From 34bc2cad969d02d5c7aec79ef1a6ed5faf7b66b8 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 15:22:54 +0900 Subject: [PATCH 18/22] =?UTF-8?q?typo=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_message.rb | 10 +++++----- config/messages.sample.yml | 2 +- config/messages.yml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/slack_message.rb b/app/models/slack_message.rb index 76b986a..15afea1 100644 --- a/app/models/slack_message.rb +++ b/app/models/slack_message.rb @@ -27,7 +27,7 @@ def self.post_received_message(modal_submission) # @see https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/chat.rb # @private def received_message_post_body - { icon_emoji: MESSAGES["intarctive"]["icon"], + { icon_emoji: MESSAGES["interactive"]["icon"], channel: @modal_submission.slack_channel_id, user: @modal_submission.slack_user_id, text:, @@ -36,9 +36,9 @@ def received_message_post_body def text if send_to_direct_message? - MESSAGES["intarctive"]["dm_text_notification"] + MESSAGES["interactive"]["dm_text_notification"] else - MESSAGES["intarctive"]["text_notification"] + MESSAGES["interactive"]["text_notification"] end end @@ -53,11 +53,11 @@ def send_to_direct_message? def received_message_attachment_fields [ attachment_field( - title: MESSAGES["intarctive"]["recept_name"], + title: MESSAGES["interactive"]["recept_name"], value: "#{@modal_submission.company_name} #{@modal_submission.visitor_name} 様" ), attachment_field( - title: MESSAGES["intarctive"]["recept_datetime"], + title: MESSAGES["interactive"]["recept_datetime"], value: "#{@modal_submission.recept_date} #{@modal_submission.recept_time}" ) ] diff --git a/config/messages.sample.yml b/config/messages.sample.yml index 73a9de3..22bc561 100644 --- a/config/messages.sample.yml +++ b/config/messages.sample.yml @@ -12,7 +12,7 @@ dialog: recept_company_placeholder: 会社名がない場合は「面接」「なし」等 recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! <<: *common -intarctive: +interactive: text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:" dm_text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:" <<: *common diff --git a/config/messages.yml b/config/messages.yml index 247dc8d..62214c2 100644 --- a/config/messages.yml +++ b/config/messages.yml @@ -12,7 +12,7 @@ dialog: recept_company_placeholder: 会社名がない場合は「面接」「なし」等 recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! <<: *common -intarctive: +interactive: text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:" dm_text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:" <<: *common From 7b3eac94f1e009aa503379ded27f53e854f9873b Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 15:24:11 +0900 Subject: [PATCH 19/22] =?UTF-8?q?title=20typo=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_modal.rb | 2 +- config/messages.sample.yml | 2 +- config/messages.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/slack_modal.rb b/app/models/slack_modal.rb index 7555c2e..45cafe5 100644 --- a/app/models/slack_modal.rb +++ b/app/models/slack_modal.rb @@ -30,7 +30,7 @@ def post_body callback_id: "callback_id", title: { type: "plain_text", - text: MESSAGES["dialog"]["tilte"] + text: MESSAGES["dialog"]["title"] }, submit: { type: "plain_text", diff --git a/config/messages.sample.yml b/config/messages.sample.yml index 22bc561..3e779c0 100644 --- a/config/messages.sample.yml +++ b/config/messages.sample.yml @@ -7,7 +7,7 @@ common: &common recept_id: 入館ID icon: ":office:" dialog: - tilte: 入館受付申請 + title: 入館受付申請 submit: 送信 recept_company_placeholder: 会社名がない場合は「面接」「なし」等 recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! diff --git a/config/messages.yml b/config/messages.yml index 62214c2..da37611 100644 --- a/config/messages.yml +++ b/config/messages.yml @@ -7,7 +7,7 @@ common: &common recept_id: 入館ID icon: ":office:" dialog: - tilte: 六本木グランドタワー入館受付申請 + title: 六本木グランドタワー入館受付申請 submit: 送信 recept_company_placeholder: 会社名がない場合は「面接」「なし」等 recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! From 263b4e13b530773576ec6bb3a90e79611f15f7b0 Mon Sep 17 00:00:00 2001 From: yoyogix Date: Tue, 27 Aug 2024 16:29:07 +0900 Subject: [PATCH 20/22] rubocop:disable Metrics/ClassLength --- app/models/slack_modal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/slack_modal.rb b/app/models/slack_modal.rb index 45cafe5..dc46c6a 100644 --- a/app/models/slack_modal.rb +++ b/app/models/slack_modal.rb @@ -4,7 +4,7 @@ require "yaml" # @see https://api.slack.com/surfaces/modals -class SlackModal +class SlackModal # rubocop:disable Metrics/ClassLength SELECT_DATE_RANGE_NUM = 90 SELECT_TIME_HOUR_START = 8 SELECT_TIME_HOUR_END = 21 From d34f84b325c240c2d859976aa35a78f82c5b394b Mon Sep 17 00:00:00 2001 From: yoyogix Date: Wed, 28 Aug 2024 10:58:03 +0900 Subject: [PATCH 21/22] =?UTF-8?q?=E7=94=B3=E8=AB=8B=E5=8F=97=E4=BB=98?= =?UTF-8?q?=E6=99=82=E3=81=AE=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=81=AF=E4=B8=80=E5=BE=8B=E3=81=A7DM=E3=81=A7=E9=80=81?= =?UTF-8?q?=E4=BF=A1=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/slack_message.rb | 9 ++- app/models/slack_modal_submission.rb | 5 -- spec/app/models/slack_message_spec.rb | 80 ++++++++----------- .../app/models/slack_modal_submission_spec.rb | 15 ---- 4 files changed, 39 insertions(+), 70 deletions(-) diff --git a/app/models/slack_message.rb b/app/models/slack_message.rb index 15afea1..5667d21 100644 --- a/app/models/slack_message.rb +++ b/app/models/slack_message.rb @@ -17,7 +17,7 @@ def self.post_received_message(modal_submission) post_body = new(modal_submission:) .send(:received_message_post_body) - ChatMessageSender.new.post_ephemeral_message(post_body) + ChatMessageSender.new.post_public_message(post_body) end private @@ -28,8 +28,7 @@ def self.post_received_message(modal_submission) # @private def received_message_post_body { icon_emoji: MESSAGES["interactive"]["icon"], - channel: @modal_submission.slack_channel_id, - user: @modal_submission.slack_user_id, + channel: @modal_submission.slack_user_id, text:, attachments: [attachment(fields: received_message_attachment_fields)] } end @@ -42,6 +41,10 @@ def text end end + def send_to_channel_message? + %w[CHANNEL BOTH].include?(ENV.fetch("SEND_MODE")) + end + # @private # @return [Boolean] def send_to_direct_message? diff --git a/app/models/slack_modal_submission.rb b/app/models/slack_modal_submission.rb index 2e1e32d..8935b93 100644 --- a/app/models/slack_modal_submission.rb +++ b/app/models/slack_modal_submission.rb @@ -16,11 +16,6 @@ def slack_user_id @post_body.dig(:user, :id) end - # @return [String] - def slack_channel_id - ENV.fetch("SLACK_CHANNEL", slack_user_id) - end - # @return [String] def recept_date @values[:recept_date][:recept_date][:selected_option][:value] diff --git a/spec/app/models/slack_message_spec.rb b/spec/app/models/slack_message_spec.rb index 7929c95..e1849b0 100644 --- a/spec/app/models/slack_message_spec.rb +++ b/spec/app/models/slack_message_spec.rb @@ -9,31 +9,31 @@ let(:instance) { described_class.new } describe "#received_message_post_body" do + let!(:modal_submit_fixture) do + { type: "view_submission", + user: { id: "UCKTXCBRB" }, + view: { + state: { + values: { + recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, + recept_time: { recept_time: { selected_option: { value: "08:00" } } }, + recept_company: { recept_company: { value: "SmartHR" } }, + recept_name: { recept_name: { value: "須磨 英知" } } + } + } + } } + end + let!(:modal_submission) { SlackModalSubmission.new(modal_submit_fixture) } + let!(:instance) { described_class.new(modal_submission:) } context "チャンネルに通知する場合" do it "適切なメッセージが通知されること" do allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("CHANNEL") - allow(ENV).to receive(:fetch).with("SLACK_CHANNEL", "UCKTXCBRB").and_return("SLACK_CHANNEL") - modal_submit_fixture = { type: "view_submission", - user: { id: "UCKTXCBRB" }, - view: { - state: { - values: { - recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, - recept_time: { recept_time: { selected_option: { value: "08:00" } } }, - recept_company: { recept_company: { value: "SmartHR" } }, - recept_name: { recept_name: { value: "須磨 英知" } } - } - } - } } - modal_submission = SlackModalSubmission.new(modal_submit_fixture) - instance = described_class.new(modal_submission:) expected = { - channel: "SLACK_CHANNEL", + channel: "UCKTXCBRB", icon_emoji: ":office:", text: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:", - user: "UCKTXCBRB", attachments: [{ color: "good", fields: instance.send(:received_message_attachment_fields) @@ -42,39 +42,25 @@ expect(instance.send(:received_message_post_body)).to eq expected end end - end - context "DMに通知する場合" do - it "適切なメッセージが通知されること" do - allow(ENV).to receive(:fetch).and_call_original - allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("DM") - modal_submit_fixture = { type: "view_submission", - user: { id: "UCKTXCBRB" }, - view: { - state: { - values: { - recept_date: { recept_date: { selected_option: { value: "2023/01/01" } } }, - recept_time: { recept_time: { selected_option: { value: "08:00" } } }, - recept_company: { recept_company: { value: "SmartHR" } }, - recept_name: { recept_name: { value: "須磨 英知" } } - } - } - } } - modal_submission = SlackModalSubmission.new(modal_submit_fixture) - instance = described_class.new(modal_submission:) + context "DMに通知する場合" do + it "適切なメッセージが通知されること" do + allow(ENV).to receive(:fetch).and_call_original + allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("DM") - expected = { - channel: "UCKTXCBRB", - icon_emoji: ":office:", - text: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:", - user: "UCKTXCBRB", - attachments: [{ - color: "good", - fields: instance.send(:received_message_attachment_fields) - }] - } - expect(instance.send(:received_message_post_body)).to eq expected + expected = { + channel: "UCKTXCBRB", + icon_emoji: ":office:", + text: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:", + attachments: [{ + color: "good", + fields: instance.send(:received_message_attachment_fields) + }] + } + expect(instance.send(:received_message_post_body)).to eq expected + end end end + describe "#received_message_attachment_fields" do context "ok" do it do diff --git a/spec/app/models/slack_modal_submission_spec.rb b/spec/app/models/slack_modal_submission_spec.rb index ddaf808..4c10a00 100644 --- a/spec/app/models/slack_modal_submission_spec.rb +++ b/spec/app/models/slack_modal_submission_spec.rb @@ -27,21 +27,6 @@ it { expect(instance.slack_user_id).to eq "UCKTXCBRB" } end end - describe "#slack_channel_id" do - context "環境変数が指定されていない場合" do - let(:post_body) { fixture } - it "投稿者のslack_user_idを返す" do - expect(instance.slack_channel_id).to eq "UCKTXCBRB" - end - end - context "環境変数が指定されている場合" do - let(:post_body) { fixture } - it "環境変数(SLACK_CHANNEL_ID)の値を返す" do - allow(ENV).to receive(:fetch).with("SLACK_CHANNEL", "UCKTXCBRB").and_return("SLACK_CHANNEL") - expect(instance.slack_channel_id).to eq "SLACK_CHANNEL" - end - end - end describe "#recept_date" do context "ok fixture" do let(:post_body) { fixture } From 036059e0d4fa746de0c728972a96538511fc159a Mon Sep 17 00:00:00 2001 From: yoyogix Date: Wed, 28 Aug 2024 10:59:45 +0900 Subject: [PATCH 22/22] =?UTF-8?q?=E5=80=8B=E4=BA=BA=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E3=81=AB=E8=A6=8B=E3=81=88=E3=82=8B=E3=83=A1=E3=83=83=E3=82=BB?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=81=AE=E9=80=81=E4=BF=A1=E3=81=8C=E3=81=AA?= =?UTF-8?q?=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/chat_message_sender.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/models/chat_message_sender.rb b/app/models/chat_message_sender.rb index 670611a..abd6baf 100644 --- a/app/models/chat_message_sender.rb +++ b/app/models/chat_message_sender.rb @@ -12,12 +12,4 @@ def initialize def post_public_message(post_body) @slack_api_client.chat_postMessage(post_body) end - - # 特定のユーザーだけに見える形で投稿 - # @param post_body [Hash] - # @see https://api.slack.com/methods/chat.postEphemeral - # @see https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/chat.rb - def post_ephemeral_message(post_body) - @slack_api_client.chat_postEphemeral(post_body) - end end