Created
August 30, 2016 02:40
-
-
Save jaimerodas/7a7366fae615c63bc64289dd48dffbfd to your computer and use it in GitHub Desktop.
AppSignal to Telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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