ぐぐっていたところ、tunnelモジュールを見付けました。httpsも可。
以下、認証Proxyを通してSlackに投稿するサンプルです。
//Slack web API
const https = require('https');
const SLACK_HOST = 'slack.com';
const SLACK_PATH = '/api/chat.postMessage';
const TOKEN = 'https://www.utali.io/entry/2016/10/03/004421 を参考に、xoxp-な文字列を入手';
const CHANNEL = '投稿したいチャンネルのコード';
const NAME = '投稿者名';
const ICON = ':ghost:'; // アイコン
//Proxy超えの準備
const tunnel = require('tunnel');
const tunnelAg = tunnel.httpsOverHttp({
'proxy': {
// 'proxyAuth': 'ログインID:ログインPW', // 認証Proxyなとき
'host': 'ProxyのIPアドレス',
'port': Proxyのポート番号
}
});
//slackに投げます(お使いの処理系から呼び出して下さい)
function sendSlack(message, context) {
const formData = {
'token': TOKEN,
'channel': CHANNEL,
'text': message,
'as_user': false,
'icon_emoji': ICON,
'username': NAME
};
const options = {
'agent': tunnelAg, // Proxyを超えるとき
'hostname': SLACK_HOST,
'path': SLACK_PATH,
'method': 'POST',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
let req = https.request(options, function(res) {
res.on('data', function(d) {
// 投稿結果をログに落とす場合
// console.log(d + '\n');
});
});
req.write(querystring.stringify(formData));
req.on('error', function(e) {
console.log('Slackにメッセージを送信できませんでした\n' + e.message);
});
req.end();
}