import { getResumeUrls } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { encode as base64UrlEncode } from "https://deno.land/std@0.82.0/encoding/base64url.ts";
type Gmail = {
token: string;
};
export async function main(
gmail_auth: Gmail,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) =>
sendEmail(token, to_email, subject),
);
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(
gmail_token: string,
to_email: string,
subject: string,
): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL = `https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
raw: email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeUrls(to_email);
const message = `There is a Windmill flow at ${Deno.env.get(
"WM_FLOW_PATH",
)} run by ${Deno.env.get("WM_USERNAME")} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body = `From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error("Expected at least one approver email");
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes("error")) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by admin 498 days ago
import { getResumeEndpoints } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { encode as base64UrlEncode } from "https://deno.land/std@0.82.0/encoding/base64url.ts";
type Gmail = {
token: string;
};
export async function main(
gmail_auth: Gmail,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) =>
sendEmail(token, to_email, subject),
);
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(
gmail_token: string,
to_email: string,
subject: string,
): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL = `https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
raw: email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeEndpoints(to_email);
const message = `There is a Windmill flow at ${Deno.env.get(
"WM_FLOW_PATH",
)} run by ${Deno.env.get("WM_USERNAME")} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body = `From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error("Expected at least one approver email");
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes("error")) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by admin 528 days ago
import { getResumeEndpoints } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
type Gmail = {
token: string;
};
export async function main(
gmail_auth: Gmail,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeEndpoints(to_email);
const message = `There is a Windmill flow at ${Deno.env.get('WM_FLOW_PATH')} run by ${Deno.env.get(
'WM_USERNAME',
)} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by admin 531 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: Resource<"gmail">,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeEndpoints(to_email);
const message = `There is a Windmill flow at ${Deno.env.get('WM_FLOW_PATH')} run by ${Deno.env.get(
'WM_USERNAME',
)} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by adam186 659 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.70.1/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: Resource<"gmail">,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeEndpoints(to_email);
const message = `There is a Windmill flow at ${Deno.env.get('WM_FLOW_PATH')} run by ${Deno.env.get(
'WM_USERNAME',
)} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by adam186 694 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: Resource<"gmail">,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await getResumeEndpoints(to_email);
const message = `There is a Windmill flow at ${Deno.env.get('WM_FLOW_PATH')} run by ${Deno.env.get(
'WM_USERNAME',
)} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by mrl5 813 days ago
import * as wmill from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: wmill.Resource<"gmail">,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await wmill.getResumeEndpoints(to_email);
const message = `There is a Windmill flow by ${Deno.env.get('WM_USERNAME')} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by mrl5 815 days ago
import * as wmill from "https://deno.land/x/windmill@v1.41.0/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: wmill.Resource<"gmail">,
approver_emails: string[],
subject = "Resume Windmill flow",
) {
throwOnInvalidApprovers(approver_emails);
const token = gmail_auth["token"];
const email_promises = approver_emails.map((to_email) => sendEmail(token, to_email, subject));
const results = await Promise.all(email_promises);
return results;
}
async function sendEmail(gmail_token: string, to_email: string, subject: string): Promise<object> {
const email = await getEmailBody(to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/me/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${gmail_token}`,
},
});
const response_json = await response.json();
return handleSendEmailResult(response_json, to_email);
}
async function getEmailBody(to_email: string, subject: string) {
const { approvalPage } = await wmill.getResumeEndpoints(encodeURIComponent(to_email));
const message = `There is a Windmill flow by ${Deno.env.get('WM_USERNAME')} waiting for your approval to resume.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <me>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
async function handleSendEmailResult(result: object, to_email: string) {
if (Object.keys(result).includes('error')) {
return Promise.reject({ wm_to_email: to_email, ...result });
}
return result;
}
Submitted by mrl5 821 days ago
import * as wmill from "https://deno.land/x/windmill@v1.40.1/mod.ts";
import {
encode as base64UrlEncode,
} from "https://deno.land/std@0.82.0/encoding/base64url.ts";
export async function main(
gmail_auth: wmill.Resource<"gmail">,
to_email: string,
subject = "resume windmill flow request",
userId = "me",
) {
const token = gmail_auth["token"];
const email = await getEmailBody(userId, to_email, subject);
const SEND_EMAIL_URL =
`https://gmail.googleapis.com/gmail/v1/users/${userId}/messages/send`;
const body = {
"raw": email,
};
const response = await fetch(SEND_EMAIL_URL, {
method: "POST",
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${token}`,
},
});
const response_json = await response.json();
return response_json;
}
async function getEmailBody(userId: string, to_email: string, subject: string) {
const { approvalPage } = await wmill.getResumeEndpoints();
const message = `There is a Windmill job waiting for your approval to resume the flow.
In order to resume or cancel the flow go to ${approvalPage}`;
const email_body =
`From: <${userId}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
return base64UrlEncode(email_body);
}
Submitted by mrl5 822 days ago