Help us understand the problem. What is going on with this article?

Slackへメッセージを送る(PHP)

More than 3 years have passed since last update.

Slack にこんなメッセージを送ってみます

snip_20161101233028.png

ログイン後、左上のメニューから「Apps & integrations」をクリックします

snip_20161101125240.png

「Incoming WebHooks」を検索して選択します

snip_20161101125501.png

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

snip_20161101125635.png

Postするチャンネルを選択し「Add Incoming WebHooks integration」をクリックします

snip_20161101125701.png

Webhook URL が表示されるのでコピーします

snip_20161101125801.png

PHPでメッセージをPOSTします

index.php
<?php

// コピーした Webhook URL
$url = 'https://hooks.slack.com/services/xxxxx';

$message = array(
    'username' => 'なまえ',
    'icon_emoji' => ':smile:',
    'text' => 'Sending Message'
);

// メッセージをjson化します
$message_json = json_encode($message);

// payloadの値としてURLエンコードしてPOSTします
$message_post = 'payload=' . urlencode($message_json);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message_post);
curl_exec($ch);
curl_close($ch);

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした