forked from temporalio/samples-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove deprecated mailgun-js in favor of axios (temporalio#130)
* remove deprecated mailgun-js in favor of axios Fix temporalio#123 * add a note about ADMIN_EMAIL * run prettier * clean up README, add .env.example, simplify createActivities()
- Loading branch information
Showing
5 changed files
with
29 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MAILGUN_API= | ||
MAILGUN_DOMAIN= | ||
ADMIN_EMAIL= |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
import { Context } from '@temporalio/activity'; | ||
import mailgun from 'mailgun-js'; | ||
import axios from 'axios'; | ||
|
||
export interface EmailSettings { | ||
to: string | undefined; | ||
interface MailgunSettings { | ||
apiKey?: string; | ||
domain?: string; | ||
to?: string; | ||
from: string; | ||
} | ||
|
||
const mailgunAPI = 'https://api.mailgun.net/v3'; | ||
const subject = 'Order processing taking longer than expected'; | ||
const html = `Order processing is taking longer than expected, but don't worry—the job is still running!`; | ||
|
||
export const createActivities = (mg: mailgun.Mailgun | undefined, { to, from }: EmailSettings) => ({ | ||
export const createActivities = ({ apiKey, domain, to, from }: MailgunSettings) => ({ | ||
async processOrder(sleepMS = 1000): Promise<void> { | ||
await Context.current().sleep(sleepMS); | ||
}, | ||
|
||
async sendNotificationEmail(): Promise<void> { | ||
console.log('Sending email:', html); | ||
|
||
if (mg && to) { | ||
const data = { | ||
to, | ||
from, | ||
subject: 'Order processing taking longer than expected', | ||
html, | ||
}; | ||
|
||
await mg.messages().send(data); | ||
if (apiKey && domain && to) { | ||
console.log('Sending email:', html); | ||
await axios({ | ||
url: `${mailgunAPI}/${domain}/messages`, | ||
method: 'post', | ||
params: { to, from, subject, html }, | ||
auth: { | ||
username: 'api', | ||
password: apiKey, | ||
}, | ||
}); | ||
} else { | ||
console.log('Skipping sending email:', html); | ||
} | ||
}, | ||
}); |
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