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

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