const request = require('request');

module.exports = (app) => {
  app.post('/zingbot', (req, res) => {
    const imageUrl = 'https://pbs.twimg.com/media/CKE98yIUMAA4Y0o.jpg';

    const payload = {
      channel: req.channel,
      text: imageUrl,
      icon_emoji: ':zap:',
    };

    const requestOpts = {
      url: app.get('webhook'),
      form: {payload: JSON.stringify(payload)},
    };

    request.post(requestOpts, (err) => {
      if (err) {
        return res.status(500).send({success: false, error: err.message});
      }
      return res.status(200).send();
    });
  });
};

@@ -1,21 +1,22 @@
 const re
-quest
+sponse
  = requi
@@ -19,23 +19,37 @@
 equire('
-request
+../lib/responseHelper
 ');%0A%0Amod
@@ -300,300 +300,34 @@
     
-const requestOpts = %7B%0A      url: app.get('webhook'),%0A      form: %7Bpayload: JSON.stringify(payload)%7D,%0A    %7D;%0A%0A    request.post(requestOpts, (err) =%3E %7B%0A      if (err) %7B%0A        return res.status(500).send(%7Bsuccess: false, error: err.message%7D);%0A      %7D%0A      return res.status(200).send();%0A    %7D
+response(payload, app, res
 );%0A 

update zingbot to use responseHelper