LoginSignup
9
9

More than 5 years have passed since last update.

node.jsでSlackのBotにポストする簡単なサンプル

Last updated at Posted at 2015-12-20

前提条件(環境)

  • SlackのIncomingWebhookを有効にしていること
  • node.js,npm,request(npmにてインストール)がインストールされていること
  • Ubuntu 14.04

サンプルコード

index.js
var request = require('request');

var options = {
        url: 'https://hooks.slack.com/services/xxxxxxxxxx',
        form: 'payload={"text": "hogehogeegege", "username": "kurewebhookbot","icon_emoji": ":ghost:", "channel": "#random"}',
        json :true
};


request.post(options, function(error, response, body){
  if (!error && response.statusCode == 200) {
    console.log(body.name);
  } else {
    console.log('error: '+ response.statusCode + body);
  }
});

実行

#nodejs index.js
9
9
0

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