Created
June 4, 2018 17:48
-
-
Save dbarkol/0681bc2b705e3b38a104f6e4e7ddec93 to your computer and use it in GitHub Desktop.
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 obj = JSON.parse(inputData.rawBody); | |
if (inputData.eventType === 'SubscriptionValidation') { | |
fetch(obj[0].data.validationUrl) | |
.then(function(res) { | |
return res.text(); | |
}) | |
.then(function(body) { | |
var output = {eventType: inputData.eventType}; | |
callback(null, output); | |
}) | |
.catch(callback); | |
} else if (inputData.eventType === 'Notification'){ | |
var artist = obj[0].data.artist; | |
var song = obj[0].data.song; | |
var body = {"text": artist + " - " + song, "icon_emoji": ":musical_note:"}; | |
var slackUrl = "https://hooks.slack.com/services/{{slack-key}}"; | |
fetch(slackUrl, { | |
method: 'POST', | |
body: JSON.stringify(body), | |
headers:{'Content-Type':'application/json'} | |
}) | |
.then(function(res) { | |
return res.text(); | |
}) | |
.then(function(body) { | |
var output = {eventType: inputData.eventType}; | |
callback(null, output); | |
}) | |
.catch(callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment