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