Node.jsでSlackにメッセージを投稿する(SlackAPI)

// Post message to slack
// using request_promise
//
// 2020-12-24 (Thu.)
// Ryo Chiba

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

const SLACK_USER_TOKEN = 'xoxp-881518928711-868191264403-yyyyyyyyyyyyy6-10458077c9cd0df36681ce05
99334ca5';
const CHANNEL_ID = 'GSX2FOKA03';
const USER_NAME = 'poco';
const text = 'Node.js posting message to Slack...';


(async () => {
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_USER_TOKEN,
        channel: CHANNEL_ID,
        username: USER_NAME,
        text: text
    },
    json: true
});

console.log(res);
})();