Skip to content

Instantly share code, notes, and snippets.

@jaimerodas
Created August 30, 2016 02:40
Show Gist options
  • Save jaimerodas/7a7366fae615c63bc64289dd48dffbfd to your computer and use it in GitHub Desktop.
Save jaimerodas/7a7366fae615c63bc64289dd48dffbfd to your computer and use it in GitHub Desktop.
AppSignal to Telegram
var https = require('https');
function generaTexto(event) {
var text;
if (event.marker) {
text = 'AppSignal recibió un release nuevo en el app ' + event.marker.site;
} else if (event.exception) {
text = 'AppSignal registró un error en el app ' + event.exception.site + "\n";
text += '_'+ event.exception.exception +'_ : ' + event.exception.message + "\n";
text += event.exception.url;
} else if (event.performance) {
text = 'AppSignal detectó un problema en el app ' + event.performance.site + "\n";
text += '_'+ event.performance.action +'_ : ' + event.performance.path + "\n";
text += event.performance.url;
} else {
text = false;
}
return text;
}
exports.handler = function(event, context) {
console.log(event);
var body = {
chat_id: 'CHAT_ID',
parse_mode: 'Markdown',
text: generaTexto(event)
};
var jsonObject = JSON.stringify(body);
var optionspost = {
host: 'api.telegram.org',
path: '/botBOT_TOKEN/sendMessage',
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
var req = https.request(optionspost, function(res) {
console.log("Success: ", res);
res.on('data', function (chunk) {
body += chunk;
});
context.succeed('Yaaas');
});
req.write(jsonObject);
req.end();
req.on('error', function (e) {
console.log(e);
context.done(null, 'Failure');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment