48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|
import { sendEmail } from '../email';
|
|
export const emailHandler = async (notification, context) => {
|
|
const { data, id } = notification;
|
|
try {
|
|
const result = await sendEmail(data, context);
|
|
if (result?.success) {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'succeed',
|
|
data: {},
|
|
filter: {
|
|
id,
|
|
},
|
|
}, { dontCollect: true });
|
|
}
|
|
else {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'fail',
|
|
data: {
|
|
data2: {
|
|
res: result?.error,
|
|
},
|
|
},
|
|
filter: {
|
|
id,
|
|
},
|
|
}, { dontCollect: true });
|
|
}
|
|
}
|
|
catch (err) {
|
|
await context.operate('notification', {
|
|
id: await generateNewIdAsync(),
|
|
action: 'fail',
|
|
data: {
|
|
data2: {
|
|
res: err?.message,
|
|
},
|
|
},
|
|
filter: {
|
|
id,
|
|
},
|
|
}, { dontCollect: true });
|
|
console.warn('发邮件消息失败', err);
|
|
}
|
|
};
|