Sending Notifications to a Slack Webhook

INFO
This documentation is for FAKE version 5.0 or later. The old documentation can be found here

In this article you will learn how to create a Slack webhook integration and send a notification to it. This article assumes that you already have a Slack team setup.

API-Reference

Adding a Webhook Integration to a Channel

Follow the instructions for setting up an incoming webhook integration. When finished, you should have a Webhook URL that looks like "https://hooks.slack.com/services/some/random/text".

Sending a Notification to the Webhook

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
open Fake.Api

// The webhook URL from the integration you set up
let webhookUrl = "https://hooks.slack.com/services/some/random/text"

Slack.sendNotification webhookUrl (fun p ->
    {p with
        Text = "My Slack Notification!\n<https://google.com|Click Here>!"
        Channel = "@SomeoneImportant"
		Username = "My Slack User"
        IconEmoji = ":ghost:"
        Attachments = [| 
            {Slack.NotificationAttachmentDefaults with
                Fallback = "Attachment Plain"
                Text = "Attachment Rich"
                Pretext = "Attachment Pretext"
                Color = "danger"
                Fields = [|
                    {Slack.NotificationAttachmentFieldDefaults with
                        Title = "Field Title 1"
                        Value = "Field Value 2"}
                    {Slack.NotificationAttachmentFieldDefaults with
                        Title = "Field Title 1"
                        Value = "Field Value 2"}|]
            }
            {Slack.NotificationAttachmentDefaults with
                Fallback = "Attachment 2 Plain"
                Text = "Attachment 2 Rich"
                Pretext = "Attachment 2 Pretext"
                Color = "#FFCCDD"
            }|]
    })
|> printfn "Result: %s"

The result should look something like this:

alt text

For additional information on the parameters, check out Slack's Webhook Documentation

val webhookUrl : string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T