43 lines
813 B
Go
Raw Normal View History

2024-05-27 14:51:22 +02:00
package discord
2024-05-08 01:56:48 +02:00
import (
"bytes"
"encoding/json"
"log"
"net/http"
"os"
2024-05-27 14:16:50 +02:00
"wazuh-notify/services"
2024-05-08 01:56:48 +02:00
"wazuh-notify/types"
)
func SendDiscord(params types.Params) {
2024-05-10 14:23:54 +02:00
2024-05-27 14:16:50 +02:00
embedDescription := services.BuildMessage(params, "discord", params.MarkdownEmphasis.Discord) +
"**Tags:** " + params.Tags + "\n\n" +
params.General.Click
2024-05-08 01:56:48 +02:00
2024-05-27 14:51:22 +02:00
message := DiscordMessage{
2024-05-27 13:01:39 +02:00
Username: params.General.Sender,
2024-05-13 16:03:00 +02:00
Content: params.Mention,
2024-05-27 14:51:22 +02:00
Embeds: []Embed{
2024-05-08 01:56:48 +02:00
{
2024-05-27 13:01:39 +02:00
Title: params.General.Sender,
2024-05-08 01:56:48 +02:00
Description: embedDescription,
2024-05-13 16:03:00 +02:00
Color: params.Color,
2024-05-08 01:56:48 +02:00
},
},
}
payload := new(bytes.Buffer)
err := json.NewEncoder(payload).Encode(message)
if err != nil {
return
}
2024-05-09 19:03:34 +02:00
_, err = http.Post(os.Getenv("DISCORD_URL"), "application/json", payload)
2024-05-08 01:56:48 +02:00
if err != nil {
log.Fatalf("An Error Occured %v", err)
}
}