Skip to content

Instantly share code, notes, and snippets.

@khavari
Last active July 7, 2020 13:06
Show Gist options
  • Save khavari/ef86be5ee2183ba1b2ac08de349a4193 to your computer and use it in GitHub Desktop.
Save khavari/ef86be5ee2183ba1b2ac08de349a4193 to your computer and use it in GitHub Desktop.
Post to Slack using Webhook

Send a message to slack using webhook via curl:

curl -X POST -H 'Content-type: application/json' --data '{"text":"Text message"}' YOUR_WEBHOOK_URL

Send a message to slack using webhook via javascript:

var xmlHttp = new XMLHttpRequest();
xmlHttp.open('post', 'YOUR_WEBHOOK_URL'); 
xmlHttp.send('{'text':'Test message'}'); 

Send a message to slack using webhook via jQuery:

var url = 'YOUR_WEBHOOK_URL';
var text = 'Text message';
$.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