Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
web: bundle exec rackup config.ru -p $PORT | ||
web: bundle exec rackup config.ru -p $PORT | ||
worker: bundle exec sidekiq -C ./config/sidekiq.yml -r ./app/workers/reception_worker.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'json' | ||
require_relative '../workers/reception_worker' | ||
|
||
module SlackInteractiveMessage | ||
def run(request) | ||
|
||
req = URI.decode_www_form(request.body.read) | ||
payload = req.assoc('payload').last | ||
slack_dialog = JSON.parse(payload) | ||
|
||
# Slack のレスポンス3秒以内ルールのため非同期処理 | ||
ReceptionWorker.perform_async slack_dialog | ||
|
||
return | ||
end | ||
|
||
module_function :run | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'json' | ||
require 'slack-ruby-client' | ||
|
||
module SlackNotification | ||
def run(request) | ||
|
||
json = JSON.parse(request.body.read) | ||
mail_body = json['body'] | ||
mail_body = mail_body.gsub("\\n", "") | ||
|
||
slack_id = mail_body.match(/(?:To:【)(.+)(?:】)/)[1] | ||
recept_name = mail_body.match(/(?:】)(.+)(?:\s様)/)[1] | ||
recept_date = mail_body.match(/\d{4}\/\d{2}\/\d{2}.+\d{2}:\d{2}/)[0] | ||
recept_id = mail_body.match(/(?:ID:)(\d+)(?:\s+\*)/)[1] | ||
|
||
day_of_the_week_eg2jp = { | ||
'Sun' => '日', | ||
'Mon' => '月', | ||
'Tue' => '火', | ||
'Wed' => '水', | ||
'Thu' => '木', | ||
'Fri' => '金', | ||
'Sat' => '土', | ||
} | ||
recept_date = recept_date.gsub(/([a-zA-Z]{3})/, day_of_the_week_eg2jp) | ||
|
||
client = Slack::Web::Client.new( | ||
token: ENV['SLACK_TOKEN'] | ||
) | ||
|
||
messages = open('./config/messages.yml', 'r') { |f| YAML.load(f) } | ||
|
||
res = client.chat_postMessage( | ||
icon_emoji: messages['notification']['icon'], | ||
channel: ENV['SLACK_CHANNEL'], | ||
text: "<@#{slack_id}> #{messages['notification']['text_notification']}", | ||
attachments: [ | ||
{ | ||
color: "#36a64f", | ||
fields: [ | ||
{ | ||
title: messages['notification']['recept_name'], | ||
value: "#{recept_name} 様", | ||
short: true | ||
}, | ||
{ | ||
title: messages['notification']['recept_datetime'], | ||
value: recept_date, | ||
short: true | ||
}, | ||
{ | ||
title: messages['notification']['recept_id'], | ||
value: recept_id, | ||
short: true | ||
} | ||
] | ||
} | ||
] | ||
) | ||
|
||
barcode_url = "https://barcode.tec-it.com/barcode.ashx?data=#{recept_id}&code=Code128" | ||
text_guide = messages['notification']['text_guide'] | ||
text_guide.gsub!('RECEPT_DATE', "#{recept_date}") | ||
text_guide.gsub!('RECEPT_ID', "#{recept_id}\n#{barcode_url}") | ||
|
||
res = client.chat_postMessage( | ||
icon_emoji: ':office:', | ||
channel: res.channel, | ||
text: text_guide, | ||
attachments: [ | ||
{ | ||
title: "バーコード/Barcode", | ||
image_url: barcode_url, | ||
} | ||
], | ||
thread_ts: res.ts | ||
) | ||
|
||
return | ||
end | ||
|
||
module_function :run | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'mechanize' | ||
require 'sidekiq' | ||
require 'slack-ruby-client' | ||
|
||
class ReceptionWorker | ||
include Sidekiq::Worker | ||
sidekiq_options queue: :default, retry: false | ||
|
||
def perform(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'] | ||
slack_channel = slack_dialog['channel']['id'] | ||
|
||
# srd-gate login | ||
agent = Mechanize.new | ||
page = agent.get("https://srd-gate.com/03/login.cgi") | ||
agent.page.form.field_with(name: 'userid').value = ENV['SRD_GATE_USERNAME'] | ||
agent.page.form.field_with(name: 'passwd').value = ENV['SRD_GATE_PASSWORD'] | ||
page = agent.page.form.submit | ||
|
||
# srd-gate regist page | ||
page = agent.get("https://srd-gate.com/03/sinsei.cgi") | ||
|
||
# regist parameter | ||
agent.page.form.field_with(name: 'raihoubi').value = recept_date | ||
agent.page.form.field_with(name: 'raihoujikan').value = recept_time | ||
agent.page.form.checkbox_with(name: 'seminarcheck').check # 団体受付可能フラグ | ||
# slack id を会社名につけて登録結果メールに情報を引回す | ||
# メール受信 webhook を受け取って、登録者にメンションするため | ||
# 半角記号は使えない仕様なので削除する | ||
agent.page.form.field_with(name: 'kaisha[]').value = '【' + slack_id + '】' + recept_company_name.gsub(/[[:punct:]]/, "") | ||
agent.page.form.field_with(name: 'mei[]').value = recept_visitor_name.gsub(/[[:punct:]]/, "") | ||
agent.page.form.field_with(name: 'kana[]').value = "カナ" | ||
agent.page.form.field_with(name: 'mail[]').value = ENV['MAIL_ADDRESS_WEBHOOK'] | ||
agent.page.form.field_with(name: 'sinseiemail').value = ENV['MAIL_ADDRESS_HOST'] | ||
agent.page.form.field_with(name: 'sinseitel').value = ENV['COMPANY_TEL'] | ||
|
||
# regist | ||
page = agent.page.form.submit | ||
|
||
client = Slack::Web::Client.new( | ||
token: ENV['SLACK_TOKEN'] | ||
) | ||
|
||
messages = open('./config/messages.yml', 'r') { |f| YAML.load(f) } | ||
|
||
client.chat_postEphemeral( | ||
icon_emoji: messages['intarctive']['icon'], | ||
channel: slack_channel, | ||
user: slack_id, | ||
text: messages['intarctive']['text_notification'], | ||
attachments: [ | ||
{ | ||
color: "#439FE0", | ||
fields: [ | ||
{ | ||
title: messages['intarctive']['recept_name'], | ||
value: "#{recept_company_name} #{recept_visitor_name} 様", | ||
short: true | ||
}, | ||
{ | ||
title: messages['intarctive']['recept_datetime'], | ||
value: "#{recept_date} #{recept_time}" , | ||
short: true | ||
}, | ||
] | ||
} | ||
] | ||
) | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Sidekiq.configure_server do |config| | ||
config.redis = { url: ENV['REDIS_PROVIDER'] } | ||
end | ||
|
||
Sidekiq.configure_client do |config| | ||
config.redis = { url: ENV['REDIS_PROVIDER'] } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
common: &common | ||
recept_date: 来訪日 | ||
recept_time: 訪問時間 | ||
recept_datetime: 訪問日時 | ||
recept_company: 来訪者会社名 | ||
recept_name: 来訪者名 | ||
user: dbuser | ||
password: |- | ||
recept_id: 入館ID | ||
icon: ":office:" | ||
dialog: | ||
tilte: 入館受付申請 | ||
submit: 送信 | ||
recept_company_placeholder: 会社名がない場合は「面接」「なし」等 | ||
recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! | ||
<<: *common | ||
intarctive: | ||
text_notification: "以下の内容で受け付けました。受け付け完了までしばらくお待ちください :pray:" | ||
<<: *common | ||
notification: | ||
text_notification: "入館受付が完了しました :tada:" | ||
text_guide: |- # RECEPT_DATE, RECEPT_ID は置換部分 | ||
``` | ||
◆日時 | ||
2019/08/21(水) 19:00 | ||
RECEPT_DATE | ||
◆場所 | ||
〒106-6239 | ||
東京都港区六本木3-2-1 | ||
住友不動産六本木グランドタワー 39F | ||
https://office.sumitomo-rd.co.jp/63/access.html | ||
南北線「六本木一丁目駅」西改札直結 | ||
日比谷線・大江戸線「六本木駅」5番出口より徒歩5分 | ||
〒123-4567 | ||
東京都港区○○ 1-2-3 | ||
◆入館ID | ||
https://barcode.tec-it.com/barcode.ashx?data=13110365176&code=Code128 | ||
RECEPT_ID | ||
(URLクリックでバーコード画像が表示されます) | ||
◆ビル入館方法 | ||
①(1Fまたは4F)セキュリティゲート前の受付機にバーコードをかざしていただく、もしくは入館IDを入力して下さい。 | ||
①セキュリティゲート前の受付機にバーコードをかざしていただく、もしくは入館IDを入力して下さい。 | ||
②受付機より「入館証」が発券されます。 | ||
(人数分の発券が必要になります) | ||
③入館証のQRコードをゲートにかざし入館します。 | ||
④ゲート右手のシャトルエレベータで29Fへ。 | ||
⑤29Fからは36-40F停車のエレベーターにて39Fへお越しください。 | ||
⑥SmartHR受付のiPadより担当者をお呼び出しください。 | ||
◆SmartHR新オフィスの行き方 | ||
https://shanaiho.smarthr.co.jp/n/n901fe6fc0e28 | ||
※注意点 | ||
「入館証」はご退館時まで必要です。大切にお持ち下さい。 | ||
dialog: | ||
|
||
tilte: 入館受付申請 | ||
submit: 送信 | ||
recept_company_placeholder: 会社名がない場合は「面接」「なし」等 | ||
recept_name_placeholder: 「様」をつけると入館証が「様様」になるよ! | ||
<<: *common | ||
|
||
#data = open('./config/message.yml', 'r') { |f| YAML.load(f) } | ||
``` | ||
<<: *common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:concurrency: 5 | ||
:queues: | ||
- default |