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

PHPでSlackに通知を送る

More than 3 years have passed since last update.

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
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
ユーザーは見つかりませんでした