Tổng hợp

Send data into Slack in real-time.

posted by tungnt 16/07/2016 0 comments

Incoming Webhooks are a simple way to post messages from external sources into Slack. They make use of normal HTTP requests with a JSON payload that includes the message text and some options. Message Attachments can also be used in Incoming Webhooks to display richly-formatted messages that stand out from regular chat messages.

Let’s learn how to send this in-channel message as an incoming webhook:

  1. Visit: https://slack.com
  2. Create a new team.
  3. View below video and follow step by step.

Source code

<!DOCTYPE html>
<html lang="en">
 <meta charset="UTF-8">
 <title>Slack - Incoming Message</title>
<input type="text" name="message" id="message">
<button onclick="sendToSlack()">
 Send to Slack

<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
 function sendToSlack() {
 var settings = {
 url: "https://hooks.slack.com/services/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",
 method: "POST",
 dataType: "application/x-www-form-urlencoded",
 data: {
 "payload": JSON.stringify({text: $("#message").val()})

$.ajax(settings).done(function (response) {
Bình luận
1355 Total Views 2 Views Today

You may also like