slackbot/handler.js
// make the call to slack to post the message
make the call to slack to post the message
make the call to slack to post the message
function postMessage(message, callback) {
  const body = JSON.stringify(message);
  const options = url.parse(hookUrl);
  options.method = 'POST';
  options.headers = {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(body),
  };
  const postReq = https.request(options, (res) => {
    const chunks = [];
    res.setEncoding('utf8');
    res.on('data', (chunk) => chunks.push(chunk));
    res.on('end', () => {
      if (callback) {
        callback({
          body: chunks.join(''),
          statusCode: res.statusCode,
          statusMessage: res.statusMessage,
        });
      }
    });
    return res;
  });
  postReq.write(body);
  postReq.end();
}
function postMessage ( message , callback ) { const body = JSON . stringify ( message ) ; const options = url . parse ( hookUrl ) ; options . method = 'POST' ; options . headers = { 'Content-Type' : 'application/json' , 'Content-Length' : Buffer . byteLength ( body ) , } ; const postReq = https . request ( options , ( res ) => { const chunks = [ ] ; res . setEncoding ( 'utf8' ) ; res . on ( 'data' , ( chunk ) => chunks . push ( chunk ) ) ; res . on ( 'end' , ( ) => { if ( callback ) { callback ( { body : chunks . join ( '' ) , statusCode : res . statusCode , statusMessage : res . statusMessage , } ) ; } } ) ; return res ; } ) ; postReq . write ( body ) ; postReq . end ( ) ; }
make the call to slack to post the message
make the call to slack to post the message
// support chunked encoding