UNPKG

@websolutespa/payload-plugin-bowl-llm

Version:

LLM plugin for Bowl PayloadCms plugin

53 lines (52 loc) 1.82 kB
import { ResponseSuccess } from '@websolutespa/payload-utils/server'; import { addDataAndFileToRequest } from 'payload'; import { appHandler } from './app.handler'; import { errorHandler } from './error.handler'; export const summaryHandler = async (req)=>{ try { await addDataAndFileToRequest(req); const app = await appHandler(req); const summary = req.data; if (!summary.email) { throw { status: 400, message: 'Bad Request: email is missing' }; } if (!summary.html) { throw { status: 400, message: 'Bad Request: html is missing' }; } if (app.webhooks && app.webhooks.length > 0) { for (const webhook of app.webhooks){ await fetch(webhook.webhook, { method: 'post', body: JSON.stringify({ action: 'summary', data: summary }), headers: { 'Content-Type': 'application/json' } }); } } else { req.payload.sendEmail({ to: summary.email, subject: 'Summary', html: summary.html, // without this param the email won't be sent (Error: Mail command failed: 451 4.0.0 Invalid from) // todo: this and other email settings should be configurable in the app settings from: 'noreply@pesaro2024.it' }); } return ResponseSuccess({ code: 'SENT' }); } catch (error) { return errorHandler(error); } }; //# sourceMappingURL=summary.handler.js.map