8
6

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.

Slack APIを使いたい

Posted at

通知に便利なSlackのAPIを使ってみたい。
ここをみる

#通知用のurl
https://slack.com/api/chat.postMessage

ポイントとなるのは urlにデータをパラメータとしてつける こと。
headerやbodyで送るのではだめ、HTTPメソッドはGETでもPOSTでもOK。
"chat.postMessage"のpostは「投稿する」の意味なのでメソッドには無関係。

#各パラメータ

##requiredとoptional

通知に絶対必要なやつとそうじゃないやつ。

種類 required optional
token
channel
text
parse
link_names
attachments
unfurl_links
unfurl_media
username
as_user
icon_url
icon_emoji

##成功したとき

ok:true 各パラメータがBodyに返ってくる。

{
  "ok": true,
  "channel": "AF80OT8l9D",
  "ts": "1461132218.000011",
  "message": {
    "text": "てすと",
    "username": "bot",
    "type": "message",
    "subtype": "bot_message",
    "ts": "1461132218.000011"
  }
}

##失敗した時

ok:false error:"理由" として返ってくる。

{
  "ok": false,
  "error": "no_text"
}

"not_authed" (token)や "channel_not_found" (channel)など。

8
6
1

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
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?