使用Node.js向Slack发送消息(2019年1月版本)

本家的说明链接:https://api.slack.com/methods/chat.postMessage

  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);
bannerAds