モーダルを閉じる工作HardwareHub ロゴ画像

工作HardwareHubは、ロボット工作や電子工作に関する情報やモノが行き交うコミュニティサイトです。さらに詳しく

利用規約、プライバシーポリシー に同意したうえでログインしてください。

工作HardwareHub ロゴ画像 (Laptop端末利用時)
工作HardwareHub ロゴ画像 (Mobile端末利用時)

Mattermost インストール手順および API の利用例

モーダルを閉じる

ステッカーを選択してください

モーダルを閉じる

お支払い内容をご確認ください

購入商品
「」ステッカーの表示権
メッセージ
料金
¥(税込)
決済方法
GooglePayマーク
決済プラットフォーム
確認事項

※利用規約をご確認のうえお支払いください

※カード情報はGoogleアカウント内に保存されます。本サイトやStripeには保存されません

※記事の執筆者は購入者のユーザー名を知ることができます

※購入後のキャンセルはできません

公開日公開日
2018/06/19
最終更新最終更新
2021/12/28
記事区分記事区分
一般公開

目次

    アカウント プロフィール画像 (サイドバー)

    アルゴリズムが大好きなエンジニアです。グラフ理論や効率的な解法に関する記事を書く予定。

    0
    ステッカーを贈るとは?

    Mattermost においても Slack のような API が提供されています。動作確認のためのインストール手順および API の利用例を記載します。

    インストール手順

    CentOS6 の場合は以下のようになります。

    Database のインストール

    古いバージョンの MySQL では Mattermost が利用する UTF8MB4 に対応していません。例えば MySQL 5.7 をインストールする場合は RPM が利用できます。DB とユーザを作成します。

    CREATE USER 'mmuser'@'%' IDENTIFIED BY 'mmuser_password';
    CREATE USER 'mmuser'@'localhost' IDENTIFIED BY 'mmuser_password';
    CREATE DATABASE mattermost;
    GRANT ALL PRIVILEGES ON mattermost.* TO 'mmuser'@'%';
    GRANT ALL PRIVILEGES ON mattermost.* TO 'mmuser'@'localhost';
    

    Mattermost ダウンロードおよびインストール

    こちらのページからダウンロードして解凍およびインストールします。

    wget https://releases.mattermost.com/5.0.0/mattermost-5.0.0-linux-amd64.tar.gz
    tar zxvf mattermost-5.0.0-linux-amd64.tar.gz
    sudo mv mattermost /opt
    sudo mkdir /opt/mattermost/data
    sudo useradd --system --user-group mattermost
    sudo chown -R mattermost:mattermost /opt/mattermost
    sudo chmod -R g+w /opt/mattermost
    

    設定ファイルを更新して MySQL 認証情報を設定します。

    sudo vim /opt/mattermost/config/config.json
    

    設定例

    "DataSource": "mmuser:mmuser_password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",
    

    外部から利用する場合は iptables を停止しておきます。

    sudo service iptables stop
    

    動作確認

    cd /opt/mattermost/
    sudo -u mattermost ./bin/mattermost
    curl http://localhost:8065/
    

    API の利用

    Slack と同様に Incoming Webhooks 等の Integration および API が利用できます。

    Incoming Webhooks

    Main Menu → Integrations から Incoming Webhooks を選択して、エンドポイントを新規作成します。HTTP POST するとメッセージを投稿できます。

    curl -XPOST -H 'Content-Type: application/json' -d '{"text": "Hello, this is some text\nThis is more text. :tada:"}' http://192.168.56.10:8065/hooks/63mt7dzfmtdn7cegjs35mumxkw
    

    Web API

    何らかの認証を利用して、各種 API が利用できます。Personal Access Tokens が利用できる設定になっている Mattermost の場合は、以下のようにして自分の情報を取得できます。

    $ curl -H 'Authorization: Bearer eib158e47i81xe4dpzg346qqqr' http://192.168.56.10:8065/api/v4/users/me | jq .
    {
      "id": "h9n3rrbuzbnt3cmu333o3h1www",
      "create_at": 1529463111662,
      "update_at": 1529463742269,
      "delete_at": 0,
      "username": "myuser",
      "auth_data": "",
      "auth_service": "",
      "email": "myuser@example.com",
      "nickname": "",
      "first_name": "",
      "last_name": "",
      "position": "",
      "roles": "system_admin system_user",
      "allow_marketing": true,
      "notify_props": {
        "channel": "true",
        "comments": "never",
        "desktop": "mention",
        "desktop_sound": "true",
        "email": "true",
        "first_name": "false",
        "mention_keys": "myuser,@myuser",
        "push": "mention",
        "push_status": "away"
      },
      "last_password_update": 1529463111662,
      "locale": "en",
      "timezone": {
        "automaticTimezone": "",
        "manualTimezone": "",
        "useAutomaticTimezone": "true"
      }
    }
    

    サーバに HTTP POST するボタン

    Interactive Messages を利用します。

    curl -XPOST -H 'Content-Type: application/json' -d '{
      "attachments": [
        {
          "pretext": "This is the attachment pretext.",
          "text": "This is the attachment text.",
          "actions": [
            {
              "name": "Ephemeral Message",
              "integration": {
                "url": "http://www.example.com/hello",
                "context": {
                  "action": "do_something_ephemeral"
                }
              }
            }, {
              "name": "Update",
              "integration": {
                "url": "http://www.example.com/hello2",
                "context": {
                  "action": "do_something_update"
                }
              }
            }
          ]
        }
      ]
    }' https://mattermost.example.com/hooks/xxxxxxxxxxxxx
    

    サーバには以下のような JSON が HTTP POST されます。レスポンスまたは別途 Incoming Webhooks 等で処理結果を Mattermost に反映させます。

    {
      "user_id": "xxxxxxxxxxxxx",
      "channel_id": "xxxxxxxxxxxxx",
      "team_id": "xxxxxxxxxxxxx",
      "post_id": "xxxxxxxxxxxxx",
      "type": "",
      "data_source": "",
      "context": {
        "action": "do_something_ephemeral"
      }
    }
    

    サーバに HTTP POST/GET するコマンド

    Slackと同様に Slash Commands が利用できます。HTTP GET または POST でサーバにリクエストを送れます。確かに Mattermost からのリクエストであることをサーバ側で確認するために Token が含まれたリクエストとなります。事前に Mattermost から取得してサーバに設定しておきます。以下は HTTP POST の例です。

    Host: www.example.com
    User-Agent: Go-http-client/1.1
    Content-Length: 338
    Accept: application/json
    Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxx
    Content-Type: application/x-www-form-urlencoded
    Accept-Encoding: gzip
    
    channel_id=yyyyyyyyyyyyyyyyyy
    &channel_name=yyyyyyyyyyyyyyyyyy
    &command=%2Fyyyyyyyyyyyyyyyyyy
    &response_url=https%3A%2F%2Fmattermost.example.com%2Fhooks%2Fcommands%2Fyyyyyyyyyyyyyyyyyy
    &team_domain=yyyyyyyyyyyyyyyyyy
    &team_id=yyyyyyyyyyyyyyyyyy
    &text=
    &token=xxxxxxxxxxxxxxxxxxxxxxxxxx
    &user_id=yyyyyyyyyyyyyyyyyy
    &user_name=yyyyyyyyyyyyyyyyyy
    
    0
    詳細設定を開く/閉じる
    アカウント プロフィール画像 (本文下)

    アルゴリズムが大好きなエンジニアです。グラフ理論や効率的な解法に関する記事を書く予定。

    記事の執筆者にステッカーを贈る

    有益な情報に対するお礼として、またはコメント欄における質問への返答に対するお礼として、 記事の読者は、執筆者に有料のステッカーを贈ることができます。

    さらに詳しく →
    ステッカーを贈る コンセプト画像

    Feedbacks

    Feedbacks コンセプト画像

      ログインするとコメントを投稿できます。