Skip to content

Instantly share code, notes, and snippets.

@cyberplanner
Forked from achavez/gist:9767499
Last active June 29, 2017 15:13
Show Gist options
  • Save cyberplanner/4069a48d14360df6f0c1c4c2548c7f8d to your computer and use it in GitHub Desktop.
Save cyberplanner/4069a48d14360df6f0c1c4c2548c7f8d to your computer and use it in GitHub Desktop.
Post to Slack using javascript
// https://googlechrome.github.io/samples/fetch-api/fetch-post.html
var request = new Request('https://hooks.slack.com/services/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', {
method: 'POST',
body: JSON.stringify({text: 'Hello'}),
headers: new Headers({'Content-type': 'application/json'})
});
fetch(request).then(function(response) { console.log(response)});
var url = // Webhook URL
var text = // Text to post
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment