概要
- Envoyというオフィスのエントランスで受付をするシステムがあります。
- 理想のワークフローは、Envoyで訪問者が受付をした際に、担当者宛にSlackで通知を飛ばすこと。
- Envoyが提供しているSlackのIntegrationを使うと、通知が届くまで4〜5分かかるのでかなり問題。(どうやら、2回めの通知は早い。SlackのIntegrationの初回呼び出しが遅い感じ。)
- Envoyからのwebhookは即時で届くので、SlackのIntegrationを使うのではなく自作したプログラムを使います。
設計
通信のフローは以下のようになります。
Envoy => (webhook) => なんかしらのScript => (webhook) => Slack
Scriptの部分を作って設置します。
スクリプトは以下のような感じです。EnvoyからはPOSTでいろいろなデータが送られてくるので、必要なデータを抽出してSlackへ通知します。
SlackのWebhookのURLはパラメータで受け取れるようにしておきます。
設定
予め、Slack側で通知を送りたいチャネルでwebhookのURLを発行しておきます。
Envoyに管理者でログインして、上記のスクリプトのURLを登録します。
Envoy

設定するWebhookのURLには忘れずにurlパラメータでslackの通知先webhookを入力します。一応、urlencodeした値を入れておきます。
URL例
Example Domain
通知のサンプル

まとめ
- ほぼ即時に通知が来るようになりました。
- webhookを動かしているPHPのアプリケーションサーバが落ちると通知が来なくて辛い状態になります。
- mentionさせるためには、SlackとEnvoy間でユーザの紐付けをしないといけないので今回はやってません。
参考資料
EnvoyからWebhookで送られてくるサンプルデータはこちらです。
Array
(
[event] => entry_sign_in
[meta] => Array
(
[location] => Array
(
[id] => xxxx
[type] => locations
[attributes] => Array
(
[name] => xx
[company-name-override] =>
[time-zone] => Asia/Tokyo
[timezone] => Asia/Tokyo
[locale] => ja
[address] => 〒xxx-xxxx xxxxxxxxxxx
[address-line-one] => undefined
[address-line-two] => 1F
[city] => xxxx
[state] => xxxx
[country] => xx
[zip] => xxx-xxxx
[longitude] => xxxx.xxxxxx
[latitude] => xx.xxxxxxxxx
[created-at] => 20xx-04-11T08:18:24.829Z
)
[relationships] => Array
(
[company] => Array
(
[data] => Array
(
[id] => xxxx
[type] => companies
)
)
)
)
[company] => Array
(
[id] => xxx
[type] => companies
[attributes] => Array
(
[name] => xxxxxxxxx
[plan-intent] => basic
[buy-intent] =>
[active] => 1
[created-at] => 20xx-04-11T08:18:24.795Z
)
)
)
[payload] => Array
(
[id] => xxxxxxxxxxxxxxx
[type] => entries
[attributes] => Array
(
[agreements-status] => not_applicable
[full-name] => xxxxxx
[email] =>
[employee-screening-flow] =>
[host] => @here
[host-email] => [email protected]
[private-notes] =>
[signed-in-at] => 20xx-03-24 02:21:53 UTC
[device-session-uuid] =>
[signed-in-via] => xxxxx
[signed-in-by] =>
[signed-out-via] => xxxxxx
[signed-out-by] =>
[signed-out-at] => 20xx-03-24 02:21:53 UTC
[thumbnails] => Array
(
[large] =>
[original] =>
[small] =>
)
[flow-name] => Visitor
[original-nda-sign-date] =>
[group-name] =>
[id-check-status] =>
[is-delivery] => 1
[agreement-refused] =>
[pov-key] => Purpose of visit
[user-data] => Array
(
[0] => Array
(
[field] => Host
[value] => @here
)
)
[sms-status] => not_sent
[approval-status] =>
[push-status] => not_sent
[email-status] => not_sent
)
[relationships] => Array
(
[location] => Array
(
[data] => Array
(
[type] => locations
[id] => xxxxx
)
)
[device] => Array
(
[data] => Array
(
[type] => devices
[id] => xxxxx
)
)
[employee] => Array
(
[data] => Array
(
[type] => employees
[id] => xxxxxx
)
)
[flow] => Array
(
[data] => Array
(
[type] => flows
[id] => xxxxxx
)
)
[previous-entries] => Array
(
[links] => Array
(
[related] => https://app.envoy.com/api/v3/entries/xxxxxxxxx/previous-entries
)
)
[platform-jobs] => Array
(
[links] => Array
(
[related] => https://app.envoy.com/api/v3/entries/xxxxxxxx/platform-jobs
)
)
)
)
)


Comments