LoginSignup
2
3

More than 3 years have passed since last update.

NodejsでSlackにメッセージ投稿(2019年1月版)

Last updated at Posted at 2019-01-27

本家の説明 => https://api.slack.com/methods/chat.postMessage

postMsgToSlack.js
  const SLACK_TOKEN = 'ここにトークンを入力'; 
  const CHANNEL_ID = '投稿したいチャンネルのIDを入力';
  const USER_NAME = '投稿する際のユーザーネームを入力';
  const msg = '投稿したいメッセージ';

  const request_promise = require("request-promise");

  const res = await request_promise({
    uri : 'https://slack.com/api/chat.postMessage',
    method : "POST",
    headers : {
        'content-type' : 'application/x-www-form-urlencoded',
        'charset' : 'utf-8' 
    },
    form : {
      token: SLACK_TOKEN,
      channel: CHANNEL_ID ,
      username: USER_NAME ,
      text: msg
    },
    json : true
  });

  console.log(res);
2
3
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
2
3