Skip to content

Instantly share code, notes, and snippets.

@dbarkol
Created June 4, 2018 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarkol/0681bc2b705e3b38a104f6e4e7ddec93 to your computer and use it in GitHub Desktop.
Save dbarkol/0681bc2b705e3b38a104f6e4e7ddec93 to your computer and use it in GitHub Desktop.
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