Skip to content

Instantly share code, notes, and snippets.

@logemann
Last active September 30, 2015 21:57
Show Gist options
  • Save logemann/295c3cb7d6a0bbf2326a to your computer and use it in GitHub Desktop.
Save logemann/295c3cb7d6a0bbf2326a to your computer and use it in GitHub Desktop.
GA PassThrough
module['exports'] = function gapassthrough(hook) {
var request = require('request');
console.log("Starting Hook: "+hook.params.hook);
// console.log(body) // Show the HTML for the Google homepage.
var jsonRequest = createJson(body);
// Set up the options for the HTTP request.
var options = {
// Use the Webhook URL from the Slack Incoming Webhooks integration.
uri: hook.env.SLACK_WEBHOOK_URL,
method: 'POST',
// Slack expects a JSON payload with a "text" property.
json: jsonRequest
};
// Make the POST request to the Slack incoming webhook.
request(options, function(error, response, body) {
// Pass error back to client if request endpoint can't be reached.
if (error) {
hook.res.end(error.message);
}
hook.res.end("normally ended");
});
if(resp2.statusCode != 200) {
hook.res.end("Error "+resp2.statusCode);
} else {
hook.res.end("normally ended");
};
hook.res.end("Something weird happened");
};
function createJson(json) {
var json = JSON.parse(json);
return {
"channel": "#general",
"username": "Wetter",
"icon_emoji": ":sunny:",
"attachments": [{
"fallback": "Wetter heute: "+json.list[0].weather[0].description,
"color": "#36a64f",
"author_name": "Wetter heute:",
"title": json.list[0].weather[0].description,
"title_link": "http://www.wetter.com/wetter_aktuell/aktuelles_wetter/deutschland/osnabrueck/DE0008003.html",
"text": "",
"fields": [{
"title": "Temp. Min:",
"value": json.list[0].main.temp_min,
"short": true
}, {
"title": "Temp. Max:",
"value": json.list[0].main.temp_max,
"short": true
}, {
"title": "Luftfeuchte",
"value": json.list[0].main.humidity + "%",
"short": true
}, {
"title": "Windgeschw.",
"value": json.list[0].wind.speed + " Knoten",
"short": true
}]
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment