LoginSignup
3
2

More than 5 years have passed since last update.

Azure Function で Slash Commands 作ってみた

Last updated at Posted at 2016-11-16

Azure FunctionでSlash Commands を試してみる。
(Slash Commands は /command のフォーマットで、任意のコマンド機能)

Function App を作成する

Marketplace から [Function App] を検索して、選択する。

image

アプリ名やサブスクリプション、プランなど設定して、作成する。
image

Function を作成する

[+ 新しい関数] から [GenericWebHook-CSharp] を選択し、関数名を指定して作成する。

image

今回は単純な現在時刻のメッセージを返すだけの Slash Commands を作る。
開発タブで以下のようにコードに変更する。

using System;
using System.Net;

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
    return req.CreateResponse(HttpStatusCode.OK, new
    {
        text = DateTime.Now.ToString(),
        response_type = "in_channel",
    });
}

統合タブでモードを [Standard] に 変更する。

image

Slash Commands の設定

作成した Azure Function を Slack から呼び出すため、Slash Commands の設定を行う

まず、「Function App」の開発タブの [関数の URL] をコピーして置く。

image

slaskの画面より[Apps & integrations] をクリックして「Slack App Directory」に移動する。
「Slash Commands」 を検索して、Integrationとして追加する。

image

コマンド名を指定して、[Add Slash Command Integration] をクリック。

image

URL に 上記でコピーした [関数の URL] を設定する。

image

[Add integration] をクリックしてSlash Commandsを登録する。

実行してみる

Slack のチャット画面で '/now' と入力すると。。

image

Azure Function から 以下のように応答してくれる。

image

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2