Skip to content

Commit f66ab82

Browse files
authored
fix: mailgun exported alert task (#4059)
1 parent 28f52b6 commit f66ab82

File tree

1 file changed

+20
-22
lines changed
  • src/flows/pipes/Notification/endpoints/Mailgun

1 file changed

+20
-22
lines changed

src/flows/pipes/Notification/endpoints/Mailgun/index.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export default register => {
2626
const subject = encodeURIComponent('InfluxDB Alert')
2727
const fromEmail = `mailgun@${data.domain}`
2828

29-
return `task_data
29+
return `apiKey = secrets.get(key: "${data.apiKey}")
30+
auth = http.basicAuth(u: "api", p: "\${apiKey}")
31+
32+
task_data
3033
|> schema["fieldsAsCols"]()
3134
|> set(key: "_notebook_link", value: "${window.location.href}")
3235
|> monitor["check"](
@@ -36,27 +39,22 @@ export default register => {
3639
)
3740
|> monitor["notify"](
3841
data: notification,
39-
endpoint: ((r) => {
40-
apiKey = secrets.get(key: "${data.apiKey}")
41-
auth = http.basicAuth(u: "api", p: "\${apiKey}")
42-
url = "https://api.mailgun.net/v3/${data.domain}/messages"
43-
data = strings.joinStr(arr: [
44-
"from=${fromEmail}",
45-
"to=${data.email}",
46-
"subject=${subject}",
47-
"text=\${r._message}"
48-
], v: "&"
49-
)
50-
http.post(
51-
url: url,
52-
headers: {
53-
"Content-Type": "application/x-www-form-urlencoded",
54-
"Authorization": "\${auth}"
55-
},
56-
data: bytes(v: data)
57-
)
58-
array.from(rows: [{value: 0}])
59-
|> yield(name: "ignore")
42+
endpoint: http.endpoint(url: "https://api.mailgun.net/v3/${data.domain}/messages")(
43+
mapFn: (r) => {
44+
data = strings.joinStr(arr: [
45+
"from=${fromEmail}",
46+
"to=${data.email}",
47+
"subject=${subject}",
48+
"text=\${r._message}"
49+
], v: "&"
50+
)
51+
return {
52+
headers: {
53+
"Content-Type": "application/x-www-form-urlencoded",
54+
"Authorization": "\${auth}"
55+
},
56+
data: bytes(v: data)
57+
}
6058
})
6159
)`
6260
},

0 commit comments

Comments
 (0)