Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sendEmailNotification utility function #4

Open
kamarmack opened this issue Apr 12, 2024 · 0 comments
Open

Add a sendEmailNotification utility function #4

kamarmack opened this issue Apr 12, 2024 · 0 comments

Comments

@kamarmack
Copy link
Owner

kamarmack commented Apr 12, 2024

import { default as ky } from 'ky-universal';
import { GeneralizedResponse } from 'ergonomic';

export type SendEmailNotificationParams = {
	html_body: string;
	recipient_email: string;
	subject: string;
};
export type SendEmailNotificationResponseData = {
	emailNotificationId: string | null | undefined;
	success: true;
	threadId: string | null | undefined;
};
export type SendEmailNotificationResponse =
	GeneralizedResponse<SendEmailNotificationResponseData> & {
		readonly data: [SendEmailNotificationResponseData];
	};
export const sendEmailNotification = async (
	prefixUrl: string,
	bearerToken: string,
	params: SendEmailNotificationParams,
): Promise<SendEmailNotificationResponse> => {
	try {
		const data = await ky
			.post('v0/health/notifications', {
				json: params,
				prefixUrl,
				headers: {
					Authorization: `Bearer ${bearerToken}`,
				},
			})
			.json<SendEmailNotificationResponse>();
		return data;
	} catch (err) {
		console.error(err);
		return Promise.reject(err);
	}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant