import { getResumeUrls } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
type Slack = {
token: string;
};
export async function main(approver_emails: string[], slack: Slack) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(
approver_emails.map((email) => getUserData(client, email)),
);
console.log(usersData);
const dmPromises = usersData.map((userData) =>
sendDirectMessage(client, userData),
);
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeUrls(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error("Expected at least one approver email");
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by admin 498 days ago
import { getResumeEndpoints } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
type Slack = {
token: string;
};
export async function main(approver_emails: string[], slack: Slack) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(
approver_emails.map((email) => getUserData(client, email)),
);
console.log(usersData);
const dmPromises = usersData.map((userData) =>
sendDirectMessage(client, userData),
);
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error("Expected at least one approver email");
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by admin 528 days ago
import { getResumeEndpoints } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
type Slack = {
token: string;
};
export async function main(
approver_emails: string[],
slack: Slack,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(approver_emails.map((email) => getUserData(client, email)));
console.log(usersData);
const dmPromises = usersData.map((userData) => sendDirectMessage(client, userData));
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by admin 531 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_emails: string[],
slack: Resource<"slack">,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(approver_emails.map((email) => getUserData(client, email)));
console.log(usersData);
const dmPromises = usersData.map((userData) => sendDirectMessage(client, userData));
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by adam186 659 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.70.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_emails: string[],
slack: Resource<"slack">,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(approver_emails.map((email) => getUserData(client, email)));
console.log(usersData);
const dmPromises = usersData.map((userData) => sendDirectMessage(client, userData));
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by adam186 694 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_emails: string[],
slack: Resource<"slack">,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(approver_emails.map((email) => getUserData(client, email)));
console.log(usersData);
const dmPromises = usersData.map((userData) => sendDirectMessage(client, userData));
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const { ok, ts, channel } = await client.chat.postMessage({
channel: userData.id,
text,
});
return { ok, ts, channel, email: userData.email };
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function handleApiResponse(email, error) {
return Promise.reject({ email, err_msg: error.message });
}
Submitted by mrl5 813 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_emails: string[],
slack: Resource<"slack">,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const usersData = await Promise.all(approver_emails.map((email) => getUserData(client, email)));
console.log(usersData);
const dmPromises = usersData.map((userData) => sendDirectMessage(client, userData));
const results = await Promise.all(dmPromises);
return results;
}
interface UserData {
id: string;
email: string;
real_name: string;
}
async function getUserData(client: WebClient, email: string): UserData {
try {
const response = await client.users.lookupByEmail({ email: email });
const { id, real_name } = response.user;
return { id, email, real_name };
} catch (err) {
return handleApiResponse(email, err);
}
}
async function sendDirectMessage(client: WebClient, userData: UserData) {
const text = await getApprovalMsg(userData.email);
const result = await client.chat.postMessage({
channel: userData.id,
text,
});
return result;
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function handleApiResponse(user_email, error) {
return Promise.reject({ user_email, err_msg: error.message });
}
Submitted by mrl5 813 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_emails: string[],
slack: Resource<"slack">,
) {
throwOnInvalidApprovers(approver_emails);
const client = new WebClient(slack.token);
const dmPromises = approver_emails.map((approver_email) => sendDirectMessage(client, approver_email));
const results = await Promise.all(dmPromises);
return results;
}
async function sendDirectMessage(client: WebClient, approver_email: string) {
const userId = await getUserId(client, approver_email);
const text = await getApprovalMsg(approver_email);
const result = await client.chat.postMessage({
channel: userId,
text,
});
return result;
}
async function getUserId(client: WebClient, user_email: string) {
let response = await client.users.lookupByEmail({ email: user_email });
throwOnApiError(response);
const { id, real_name } = response.user;
console.log({ id, real_name, user_email });
return id;
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnInvalidApprovers(approvers: string[]) {
if (!Array.isArray(approvers) || approvers.length === 0) {
throw new Error('Expected at least one approver email');
}
}
function throwOnApiError(response) {
if (!response?.ok) {
throw new Error(response);
}
}
Submitted by mrl5 813 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_email: string,
slack: Resource<"slack">,
) {
const client = new WebClient(slack.token);
const userId = await getUserId(client, approver_email);
const text = await getApprovalMsg(approver_email);
const result = await client.chat.postMessage({
channel: userId,
text,
});
return result;
}
async function getUserId(client: WebClient, user_email: string) {
let response = await client.users.lookupByEmail({ email: user_email });
throwOnApiError(response);
const { id, real_name } = response.user;
console.log({ id, real_name, user_email });
return id;
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnApiError(response) {
if (!response?.ok) {
throw new Error(response);
}
}
Submitted by mrl5 813 days ago
import { getResumeEndpoints, Resource } from "https://deno.land/x/windmill@v1.42.1/mod.ts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";
export async function main(
approver_email: string,
slack: Resource<"slack">,
) {
const client = new WebClient(slack.token);
const userId = await getUserId(client, approver_email);
const text = await getApprovalMsg(approver_email);
const result = await client.chat.postMessage({
channel: userId,
text,
});
return result;
}
async function getUserId(client: WebClient, user_email: string) {
let response = await client.users.lookupByEmail({ email: user_email });
throwOnApiError(response);
const { id, real_name } = response.user;
console.log({ id, real_name, user_email });
return id;
}
async function getApprovalMsg(to_email) {
const { approvalPage } = await getResumeEndpoints(to_email);
return `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}`;
}
function throwOnApiError(response) {
if (!response?.ok) {
throw new Error(response);
}
}
Submitted by mrl5 814 days ago