1 | |
2 |
|
3 | export async function main( |
4 | email_recipients: string[], |
5 | workspace_id: string, |
6 | job_id: string, |
7 | path: string, |
8 | is_flow: boolean, |
9 | error: object, |
10 | started_at: string, |
11 | trigger_path?: string, |
12 | ) { |
13 |
|
14 | const token = process.env["WM_TOKEN"] |
15 | const base_internal_url = process.env["BASE_INTERNAL_URL"] |
16 | const fullUrl = `${base_internal_url}/api/w/${workspace_id}/jobs/send_email_with_instance_smtp` |
17 | const body = { workspace_id, job_id, is_flow, error, started_at, runnable_path: path, trigger_path, email_recipients } |
18 | try { |
19 | console.log(`Sending request to ${fullUrl}`) |
20 | let response = await fetch(fullUrl, { |
21 | method: "POST", |
22 | headers: { |
23 | "Content-Type": "application/json", |
24 | "Authorization": `Bearer ${token}` |
25 | }, |
26 | body: JSON.stringify(body) |
27 | }) |
28 |
|
29 | if (!response.ok) { |
30 | throw Error(await response.text()) |
31 | } |
32 |
|
33 | response = await response.json() |
34 | console.log(`Response: ${response}`) |
35 | return response |
36 | } catch (error) { |
37 | console.error(`Error: ${error}`) |
38 | } |
39 | } |