elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.58k stars 8.09k forks source link

[Cases] Move the email template logic from cases to the notification service #159769

Open cnasikas opened 1 year ago

cnasikas commented 1 year ago

In https://github.com/elastic/kibana/pull/159335 we added the ability to send HTML emails to users when they are assigned to a case. We put the logic and the HTML template into the cases plugin. We should move it to the notifications. The notifications service will be responsible for reading the HTML template file, rendering the template using Mustache, and sending the HTML email.

PoC:

export class ConnectorsEmailService implements EmailService {
  constructor(
    private requesterId: string,
    private connectorId: string,
    private actionsClient: IUnsecuredActionsClient,
    private emailFormatter: EmailFormatter,
  ) {}
  async sendPlainTextEmail(params: PlainTextEmail): Promise<void> {
    const actions = params.to.map((to) => ({
      id: this.connectorId,
      params: {
        to: [to],
        subject: params.subject,
        message: params.message,
      },
      relatedSavedObjects: params.context?.relatedObjects,
    }));
    return await this.actionsClient.bulkEnqueueExecution(this.requesterId, actions);
  }
  async sendHtmlTemplateEmail({ templateId, templateData, to, subject, message, relatedSavedObjects }) {
    const body = this.emailFormatter.renderTemplate({ templateId, templateData });
    return await this.sendPlainTextEmail({ });
  }
}
export class EmailFormatter {
  async renderTemplate({ templateId, templateData }): string {
  }
}

cc @gsoldevila

elasticmachine commented 1 year ago

Pinging @elastic/response-ops (Team:ResponseOps)

elasticmachine commented 1 year ago

Pinging @elastic/response-ops-cases (Feature:Cases)