Skip to content

Commit cf00578

Browse files
committed
fix: update EmailAdapter to make HTML parameter optional and enhance email sending functionality
1 parent a4dacb1 commit cf00578

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

adminforth/documentation/docs/tutorial/08-Plugins/01-agent.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ type SendEmailBody = {
614614
userId: string;
615615
subject: string;
616616
body: string;
617+
htmlBody?: string;
617618
};
618619

619620
export function initApi(app: Express, admin: IAdminForth) {
@@ -629,6 +630,7 @@ export function initApi(app: Express, admin: IAdminForth) {
629630
userId: { type: 'string' },
630631
subject: { type: 'string', minLength: 1 },
631632
body: { type: 'string', minLength: 1 },
633+
htmlBody: { type: 'string', minLength: 1 },
632634
},
633635
},
634636
response_schema: {
@@ -642,7 +644,7 @@ export function initApi(app: Express, admin: IAdminForth) {
642644
},
643645
},
644646
handler: async ({ body, response }) => {
645-
const { userId, subject, body: emailBody } = body as SendEmailBody;
647+
const { userId, subject, body: emailBody, htmlBody } = body as SendEmailBody;
646648

647649
await agentEmailAdapter.validate();
648650

@@ -659,7 +661,7 @@ export function initApi(app: Express, admin: IAdminForth) {
659661
agentSendFrom,
660662
user.email as string,
661663
emailBody,
662-
renderEmailHtml(emailBody),
664+
htmlBody ?? renderEmailHtml(emailBody),
663665
subject,
664666
);
665667

@@ -712,9 +714,9 @@ Use `send_email_to_user` to send the final report after you have one exact targe
712714
# Instructions
713715

714716
- For each resource in system use fetch data default skill to collect total count of records in each resource.
715-
- Create html report in format `Resource Label (resourceId): count` for each resource on a new line, sort resources by count in descending order.
717+
- Create both a plain text report and an HTML report in format `Resource Label (resourceId): count` for each resource on a new line, sort resources by count in descending order.
716718
- Use modern, stylish but compatible html formatting in the email.
717-
- Call `send_email_to_user` with the resolved user primary key, the final subject, and the final plain text body.
719+
- Call `send_email_to_user` with the resolved user primary key, the final subject, the final plain text `body`, and the final HTML markup in `htmlBody`.
718720
- After the tool succeeds, tell the user the email was sent and include a short summary in chat.
719721
```
720722

adminforth/types/adapters/EmailAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export interface EmailAdapter {
1111
* @param from - The sender's email address
1212
* @param to - The recipient's email address
1313
* @param text - The plain text version of the email
14-
* @param html - The HTML version of the email
14+
* @param html - The optional HTML version of the email
1515
* @param subject - The subject of the email
1616
*/
1717
sendEmail(
1818
from: string,
1919
to: string,
2020
text: string,
21-
html: string,
21+
html: string | undefined,
2222
subject: string
2323
): Promise<{
2424
error?: string;

0 commit comments

Comments
 (0)