Created
June 29, 2023 14:26
-
-
Save danielestevez/5c366e4e8fba3a73ebcea303b738e4b9 to your computer and use it in GitHub Desktop.
Send notification to slack webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"net/http" | |
) | |
func main() { | |
webhookURL := "https://hooks.slack.com/services/YOUR/WEBHOOK/URL" | |
message := map[string]string{ | |
"text": "Hello, Slack!", | |
} | |
jsonMessage, err := json.Marshal(message) | |
if err != nil { | |
fmt.Println("Failed to marshal JSON:", err) | |
return | |
} | |
response, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonMessage)) | |
if err != nil { | |
fmt.Println("Failed to send message to Slack:", err) | |
return | |
} | |
defer response.Body.Close() | |
fmt.Println("Notification sent successfully!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment