Pinglik Uptimer webhook example
@pinglik
code:
data:privatelast updated:2 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
active
last updated:-last event:-
steps.
nodejs
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
}
59
const axios = require("axios")
if(steps.trigger.event.method !== "POST") return; // dont trigger this when the request type is not POST
if(!steps.trigger.event.headers["user-agent"].includes("Pinglik Uptimer")) return; // ignore requests that are not sent from Pinglik Uptimer

if(!steps.trigger.event.body.monitor_name) return;
if(!steps.trigger.event.body.monitor_link) return;
let request = steps.trigger.event.body

let color = 16777215 // defauld color - white
let title = `${request.monitor_name} is ${request.type}!`
let url = request.monitor_link
let description = request.message // default notification message (you can also build your own)
let timestamp = request.timestamp // currect timestamp
let footer = `This monitor is owned by ${request.monitor_owner_tag} (${request.monitor_owner_id})`

// embed color
if(request.type == "online") color = 65331 // green when its online
if(request.type == "offline") color = 16747520 // orange when its offline
if(request.type == "down") color = 15413039 // red when its down



// more info how to build your custom Discord webhook message  - https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html
let body = {
  "username": "Pinglik Uptimer",
  "avatar_url": "https://uptimer.pinglik.eu/img/logo.png",
  "embeds": [
    {
      "author": {
        "name": "Pinglik Uptimer",
        "url": "https://uptimer.pinglik.eu",
        "icon_url": "https://uptimer.pinglik.eu/img/logo.png"
      },
      "title": title,
      "url": url,
      "description": description,
      "color": color,
      "timestamp": timestamp,
       "footer": {
        "text": footer,
        "icon_url": "https://uptimer.pinglik.eu/img/logo.png"
      }
    }
  ],
}

// make POST request to Discord webhook - send your notification embed to Discord
const resp = await axios({
  method: "POST",
  url: process.env.notification_webhook + "?wait=true", // Go to https://pipedream.com/settings/env-vars and add your webhook url as notification_webhook
  data: JSON.stringify(body),
  headers: {
    "Content-Type": "application/json",
  },
});

this.message = resp.data; // return message body if it was sent to Discord