Skip to content

Commit

Permalink
DM に送る場合がある時に補助するメッセージを追加しました
Browse files Browse the repository at this point in the history
  • Loading branch information
shigerix committed Jun 7, 2024
1 parent cb42ecd commit d7edb43
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
16 changes: 15 additions & 1 deletion app/models/slack_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@ def received_message_post_body
{ icon_emoji: MESSAGES["intarctive"]["icon"],
channel: @dialog_submission.slack_channel_id,
user: @dialog_submission.slack_user_id,
text: MESSAGES["intarctive"]["text_notification"],
text:,
attachments: [attachment(fields: received_message_attachment_fields)] }
end

def text
if send_to_direct_message?
MESSAGES["intarctive"]["dm_text_notification"]
else
MESSAGES["intarctive"]["text_notification"]
end
end

# @private
# @return [Boolean]
def send_to_direct_message?
%w[DM BOTH].include?(ENV.fetch("SEND_MODE"))
end

# @return [Array] attachment_field array
# @private
def received_message_attachment_fields
Expand Down
1 change: 1 addition & 0 deletions config/messages.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dialog:
<<: *common
intarctive:
text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:"
dm_text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:"
<<: *common
notification:
text_notification: "入館受付が完了しました :tada:"
Expand Down
1 change: 1 addition & 0 deletions config/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dialog:
<<: *common
intarctive:
text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:"
dm_text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray: \n受付が完了すると入館IDとバーコードがslackbotで届きます:mailbox_with_mail:"
<<: *common
notification:
text_notification: "入館受付が完了しました :tada:"
Expand Down
31 changes: 29 additions & 2 deletions spec/app/models/slack_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
let(:instance) { described_class.new }

describe "#received_message_post_body" do
context "ok" do
it do
context "チャンネルに通知する場合" do
it "適切なメッセージが通知されること" do
allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("CHANNEL")
modal_submit_fixture = { type: "dialog_submission",
user: { id: "UCKTXCBRB" },
channel: { id: "CH15TJXEX" },
Expand All @@ -35,6 +36,32 @@
end
end
end
context "DMに通知する場合" do
it "適切なメッセージが通知されること" do
allow(ENV).to receive(:fetch).with("SEND_MODE").and_return("DM")
modal_submit_fixture = { type: "dialog_submission",
user: { id: "UCKTXCBRB" },
channel: { id: "CH15TJXEX" },
submission: { date: "2023/01/01",
time: "08:00",
company_name: "SmartHR",
name: "須磨 英知" } }
dialog_submission = SlackDialogSubmission.new(modal_submit_fixture)
instance = described_class.new(dialog_submission:)

expected = {
channel: "CH15TJXEX",
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
end
end
describe "#received_message_attachment_fields" do
context "ok" do
it do
Expand Down

0 comments on commit d7edb43

Please sign in to comment.