0
Schedule success handler Failure
One script reply has been approved by the moderators Verified

NOTE: this script uses the Microsoft Teams workspace settings resource (EE only)

Created by alex308 34 days ago Viewed 4144 times
0
Submitted by alex308 Bun
Verified 34 days ago
1
import dayjs from 'dayjs'
2
import * as wmill from "windmill-client"
3

4
export async function main(
5
  path: string, // The path of the script or flow
6
  is_flow: boolean, // Whether the runnable is a flow
7
  schedule_path: string, // The path of the schedule
8
  success_result: object, // The result of the latest successful job
9
  success_started_at: string, // The start datetime of the latest successful job
10
  channel: string,
11
) {
12
  const baseUrl = process.env["WM_BASE_URL"];
13
  const scheduleUrl = baseUrl + "/runs?schedule_path=" +
14
    encodeURIComponent(schedule_path);
15
  const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") + path;
16

17
  let mdText = `*Schedule [${schedule_path}](${scheduleUrl}) was successful*:\n- ${is_flow ? "Flow" : "Script"}: [${path}](${runnableUrl})`
18

19
  const lastFailureText = `Last failure at: ${dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")}\n`
20

21
  await wmill.TeamsService.sendMessageToConversation(
22
    {
23
      requestBody: {
24
        conversation_id: channel,
25
        success: true,
26
        text: mdText,
27
        card_block: {
28
          "type": "message",
29
          "attachments": [
30
            {
31
              "contentType": "application/vnd.microsoft.card.adaptive",
32
              "content": {
33
                "type": "AdaptiveCard",
34
                "body": [
35
                  {
36
                    "type": "TextBlock",
37
                    "size": "Medium",
38
                    "weight": "Bolder",
39
                    "text": "Success Handler"
40
                  },
41
                  {
42
                    "type": "ColumnSet",
43
                    "columns": [
44
                      {
45
                        "type": "Column",
46
                        "items": [
47
                          {
48
                            "type": "Icon",
49
                            "name": "ServerPlay",
50
                            "size": "Medium",
51
                            "style": "Filled",
52
                            "color": "Good"
53
                          }
54
                        ],
55
                        "width": "auto"
56
                      },
57
                      {
58
                        "type": "Column",
59
                        "items": [
60
                          {
61
                            "type": "TextBlock",
62
                            "text": mdText,
63
                            "wrap": true
64
                          }
65
                        ],
66
                        "width": "stretch"
67
                      }
68
                    ]
69
                  }
70
                ],
71
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
72
                "version": "1.6"
73
              },
74
            }
75
          ]
76
        }
77
      }
78
    }
79
  )
80
}