# 概要
- SlackからVSTSのビルドをトリガーできるようにします
- Slack、VSTSの連携にMicrosoft Flowを使用します
- ビルド実行結果の通知はSlackとVSTSを直接連携します
- こんなイメージ

事前準備
- VSTSでビルドしたいもの
- VSTSのアカウント
- やり取りするSlack
- Microsoft Flowのアカウント
本題
VSTSのビルド完了通知をSlackに
こちらの記事の Slackにチェックインを通知する
の項目がまさしくなので省略します。
誰でもできる!VSTSとSlackの超簡単な連携方法
Slack、VSTS、Flow連携設定
- Slack上で「Apps & Integrations」をクリックします。

- (ブラウザに飛んで)「Outgoing WebHook」を検索して選択します。

- 「Add Configuration」をクリックします。

- 「Add Outgoing WebHook integration」をクリックします。

- Integration Settingsで「Channel」に通知対象の部屋を、「Trigger Words」にWebHookの起点となるフレーズを登録ます。

- Micorosoft Flowのマイフローページに移動し、「一から作成」をクリックします。

- トリガーの追加で「要求と応答 - 要求」を選択します。「要求本文の JSON スキーマ」は現状「サンプルのペイロードを使用してスキーマを生成する」に{ "sample": "test"} と入力して設定されるものでかまいません。

- アクションとして「Visual Studio Team Services - Queue a new build」を設定します。初回設定時には認証を求められます。

- 「Account Name」、「Project Name」、「Build Definition Id」をドロップダウンから選択します。

- アクションとして「Slack - 投稿メッセージ」を選択します。

- サインインしてAuthorizeしてください。

- VSTSでのビルド開始後にSlackに通知するときの「チャネル名」、「メッセージテキスト」を選択します。メッセージには「動的なコンテンツ」として別のアクションからの出力を埋め込むことができます。ビルド完了後の通知はVSTSとSlackを直接連携させているのでこの設定とは別です。

-
「フローの更新」で一旦保存します。
-
「要求」を開き、URLをコピーします。

- SlackのIntegration Settingsに戻り、URL(s)に14でコピーしたURLをペーストします。

以上で設定完了です。Slackに戻って設定したフレーズを投稿して動作確認してみましょう。
サービス連携時に次のような投稿もされているはずなので、念のため合わせて確認してみてください。

FAQ
なんでMicrosoft Flow使うん?Logic Apps使えばいいんちゃうん?

とのことで、最初Logic Appsで構築しようとしました。
が、今VSTSとの接続に問題があり、連携できずになんとかMS Flowで間に合わせたという事情があります。
Logic AppsでVisual Studio Team Servicesへの接続認証を保存できません。回避策はありますか?
なんでSlackのWebHook無条件に受けて入れてるん?条件で絞るべきちゃうん?
「想定するtokenのときだけビルドする」みたいな条件で絞るべきだと思います。
ただ、現状SlackのWebHookで送信されるのはこういうもので「要求」で受け取れるjsonではありません。
token=bJ21uDt3aR4OITjUSeYuldZ2
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=test
timestamp=1355517523.000005
user_id=U2147483697
user_name=Steve
text=googlebot: What is the air-speed velocity of an unladen swallow?
trigger_word=googlebot:
リクエストのBodyに上記相当のパラメタは入っているのでMicrosoroft Flowで使用できるフィルターや条件でマッチさせる、ということも考えられますが
「Body」 に 「xxxxx」 の値を含む
みたいな条件を足しても動かなかったのでとりあえず上記のような形で置くことにしました。僕のやり方が間違ってる可能性もだいぶあるので、うまくいった方教えてくださいm(_ _)m
今回のような専用のコネクタを使わずにがんばれば実現できる方法はあるようですが、専用のコネクタの「プレビュー」がとれたら実現できると信じつつ待ちます!