MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / SlackNotification

Function SlackNotification

internal/notification/notification.go:39–99  ·  view source on GitHub ↗

SlackNotification sends an error message to a Slack webhook. It formats the error details and the current time into a Slack message payload. Parameters: - err: The error to be reported via Slack. The function retrieves configuration for the Slack webhook URL, formats the error, and sends it as a J

(err error)

Source from the content-addressed store, hash-verified

37//
38// The function retrieves configuration for the Slack webhook URL, formats the error,
39// and sends it as a JSON payload to the Slack webhook.
40func SlackNotification(err error) {
41 // Format the Slack message payload using the error message and the current time
42 data := json.RawMessage(fmt.Sprintf(`{
43 "blocks": [
44 {
45 "type": "header",
46 "text": {
47 "type": "plain_text",
48 "text": "Error From LedgerForge 🐞",
49 "emoji": true
50 }
51 },
52 {
53 "type": "section",
54 "fields": [
55 {
56 "type": "mrkdwn",
57 "text": "*Error:*\n%v"
58 }
59 ]
60 },
61 {
62 "type": "section",
63 "fields": [
64 {
65 "type": "mrkdwn",
66 "text": "*Time:*\n%v"
67 }
68 ]
69 }
70 ]
71 }`, err.Error(), time.Now().Format(time.RFC822)))
72
73 // Fetch the configuration, including the Slack webhook URL
74 conf, err := config.Fetch()
75 if err != nil {
76 logrus.Error(err)
77 return
78 }
79
80 // Convert the Slack message to a JSON request payload
81 payload, err := request.ToJsonReq(&data)
82 if err != nil {
83 logrus.Error(err)
84 return
85 }
86
87 // Create an HTTP request to send the Slack notification
88 req, err := http.NewRequest("POST", conf.Notification.Slack.WebhookUrl, payload)
89 if err != nil {
90 logrus.Error(err)
91 return
92 }
93
94 // Send the request and handle the response
95 var response map[string]interface{}
96 _, err = request.Call(req, &response)

Callers 1

NotifyErrorFunction · 0.85

Calls 4

FetchFunction · 0.92
ToJsonReqFunction · 0.92
CallFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected