112
112

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPでSlackに通知を送る

Last updated at Posted at 2015-03-09

1. APIを使うためにAPIキーを作成する

2. PHPでSlackに通知を送る

<?php

$slackApiKey = 'xxxx-xxxxxxxxx-xxxx'; //上で作成したAPIキー
$text = 'Hello!';
$text = urlencode($text);
$url = "https://slack.com/api/chat.postMessage?token=${slackApiKey}&channel=%23hogehoge&text=${text}&as_user=true";
file_get_contents($url);

  • urlencode($text):urlに埋め込むときはurlエンコードをする。
  • リクエストパラメータ(token, channel, textは必須パラメータ)
    • token:作成したAPIキー
    • channel:通知を送るチャンネル名(%23#のurlエンコード。この例なら、チャンネル名は「#hogehoge」)
    • text:通知内容
    • as_user:これを指定しなければ「bot」が投稿。trueにしたら、「APIキーの作成者」が投稿。
    • ドキュメントは下記参照。
    • https://api.slack.com/methods/chat.postMessage
112
112
3

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
112
112

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?