Created
January 31, 2024 05:52
-
-
Save hhsecond/f868d3e0ad464738b4188302d92f66a8 to your computer and use it in GitHub Desktop.
Loops client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LoopsClient from "loops"; | |
function getLoopsClient(): LoopsClient { | |
if (!process.env.LOOPS_APIKEY) { | |
throw new Error("Missing LOOPS_APIKEY environment variable"); | |
} | |
return new LoopsClient(process.env.LOOPS_APIKEY); | |
} | |
interface DataVariables { | |
[key: string]: string; | |
} | |
export async function sendTransactionalEmail( | |
transactionId: string, | |
newUserEmail: string, | |
dataVariables: DataVariables | |
): Promise<void> { | |
// return immedietly if not in production | |
if (process.env.NODE_ENV !== "production") { | |
return; | |
} | |
try { | |
const loops = getLoopsClient(); | |
const txnEmailResp = await loops.sendTransactionalEmail( | |
transactionId, | |
newUserEmail, | |
dataVariables | |
); | |
if (txnEmailResp.success === false) { | |
console.error("Error sending transactional email:", txnEmailResp); | |
} | |
} catch (error) { | |
console.error("An error occurred in sendTransactionalEmail:", error); | |
} | |
} |
Author
hhsecond
commented
Jan 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment