From 91bb35668cf384aaf663be39cdaac870a7418277 Mon Sep 17 00:00:00 2001 From: Mike Wright Date: Sat, 8 Oct 2016 10:48:50 -0700 Subject: [PATCH] Added javascript example to incoming_webhooks docs While a public site probably should avoid having an open webhook lying around - many developers use slack on internal tools where users are trusted. Plus, having a working javascript example will help users quick check their config & payloads when crafting messages. --- index_incoming_webhooks.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index_incoming_webhooks.md b/index_incoming_webhooks.md index 126ce5e..0290f5f 100644 --- a/index_incoming_webhooks.md +++ b/index_incoming_webhooks.md @@ -69,6 +69,18 @@ The trickiest part of this approach is that you must properly [URL encode](https Many HTTP clients provide convenient functions for URL encoding and setting the `Content-type`. +
+
javascript example
+
var webhook_url = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
+var request = new XMLHttpRequest(); 
+// important: replace #myChannel with the name of your channel. Keep the # sign
+var json = 'payload={"channel": "#myChannel", "username": "myBot", "text": "This is a line of text.\nAnd this is another one."}'; 
+request.open('POST', webhook_url, false); 
+request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+request.send(json);
+
+
+
curl example
curl -X POST --data-urlencode 'payload={"text":"This is a line of text.\nAnd this is another one."}' https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX