strapi-plugin-brevo-template-sender 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ <!-- markdownlint-disable MD033 MD041 -->
2
+
3
+ <div align="center" width="150px">
4
+
5
+ ![Logo - Brevo Template Sender](./doc/logo.webp)
6
+
7
+ <h1>Strapi Brevo Template Sender</h1>
8
+
9
+ <p>
10
+ Strapi (v5) plugin to send HTML emails via <strong>Brevo</strong>: configure by content-type and event (Create, Update, Delete, Publish, Unpublish), HTML or Brevo templates, and on-demand send API.
11
+ </p>
12
+
13
+ <p>
14
+ <a href="https://strapi.io">
15
+ <img src="https://img.shields.io/badge/strapi-v5-blue" alt="Strapi supported version" />
16
+ </a>
17
+ </p>
18
+
19
+ ![Demo - Brevo Template Sender](./doc/demo.gif)
20
+
21
+ </div>
22
+
23
+ ## Features
24
+
25
+ - **Brevo config**: API key, sender (email / name), optional OpenAI API key for AI-generated templates
26
+ - **Templates per content-type**: one template (subject + HTML or Brevo template) per content-type, tied to Create, Update, Delete, Publish, Unpublish events
27
+ - **Template modes**: **HTML** (subject + HTML in Strapi) or **Brevo template** (ID of template created in Brevo)
28
+ - **Send API**: endpoint `POST /api/brevo-template-sender/send` with body `{ params: { ... } }` only. Template and recipients from Strapi config.
29
+ - **AI generation**: “Generate with AI” button in the template editor (requires OpenAI key in config or `OPENAI_API_KEY`)
30
+ ## Installation
31
+
32
+ ### Requirements
33
+
34
+ - Strapi **v5**
35
+ - **Brevo** account (API key)
36
+ - Optional: **OpenAI** key for “Generate with AI”
37
+
38
+ ### Enable the plugin in Strapi
39
+
40
+ In `config/plugins.ts`:
41
+
42
+ Local install (plugin inside your Strapi project). **Config is optional**: by default the plugin uses its own content-type `plugin::brevo-template-sender.email-template` and `logoUrl` from `STRAPI_LOGO_URL` (or empty).
43
+
44
+ ```ts
45
+ export default ({ env }) => ({
46
+ "brevo-template-sender": {
47
+ enabled: true,
48
+ resolve: "./src/plugins/strapi-plugin-brevo-template-sender",
49
+ // Optional config: only add when overriding defaults
50
+ // config: {
51
+ // templateContentType: "api::email-template.email-template", // project custom content-type
52
+ // logoUrl: env("STRAPI_LOGO_URL", ""), // or leave default (env)
53
+ // // OpenAI: set OPENAI_API_KEY in .env or in plugin Config (admin) for "Generate with AI"
54
+ // },
55
+ },
56
+ });
57
+ ```
58
+
59
+ To use an Email Template content-type defined in your project (e.g. `api::email-template.email-template`) or to set the logo URL in config instead of an env variable, uncomment and fill in `config`.
60
+
61
+ ### Rebuild Strapi
62
+
63
+ ```bash
64
+ npm run build
65
+ npm run develop
66
+ ```
67
+
68
+ or with yarn:
69
+
70
+ ```bash
71
+ yarn build
72
+ yarn develop
73
+ ```
74
+
75
+ ## Usage
76
+
77
+ ### 1) Configuration page (admin)
78
+
79
+ In the **Brevo Template Sender** menu:
80
+
81
+ - **Config**: Brevo API key, sender email and name, OpenAI key (optional)
82
+ - **Active Content-Type templates**: “Manage content types” to enable events per content-type, “Edit Template” for subject / HTML / recipients
83
+ - **Send Email API**: default template for the `send` endpoint, configurable via “Configure template”
84
+
85
+ ### 2) Template editor (Edit Template)
86
+
87
+ For each enabled content-type, “Edit Template” lets you set:
88
+
89
+ - **Subject**: with `{{variable}}` placeholders
90
+ - **Message (HTML)** or **Brevo template**: HTML mode (editor) or Brevo template ID
91
+ - **Recipients**: Recipients field (used by the Send API)
92
+ - **Generate with AI**: button to create or adapt HTML via OpenAI
93
+
94
+ ### 3) Send API
95
+
96
+ Body: `{ params: { ... } }` only. Template and recipients are set in Strapi (plugin → Configure template).
97
+
98
+ **Example:**
99
+
100
+ ```json
101
+ POST /api/brevo-template-sender/send
102
+ {
103
+ "params": {
104
+ "firstname": "Jean",
105
+ "message": "Content..."
106
+ }
107
+ }
108
+ ```
109
+
110
+ ## Email Template content-type
111
+
112
+ By default the plugin uses its own content-type `plugin::brevo-template-sender.email-template`. If you set `templateContentType` (e.g. `api::email-template.email-template`), your project content-type must expose at least: **name**, **code** (unique), **subject**, **html**. Variables in subject and HTML use the `{{variable_name}}` syntax.
113
+
114
+ ## Template variables
115
+
116
+ - **Subject and HTML**: `{{variable_name}}` (optional spaces). Keys in `params` replace these placeholders.
117
+ - **`{{logo_url}}`**: injected automatically by the plugin (config `logoUrl` or `STRAPI_LOGO_URL`).
118
+
119
+ Example subject: `New message: {{subject}}` — HTML: `<p><img src="{{logo_url}}" alt="Logo" /></p><p>From: {{email}}</p><p>{{message}}</p>`
120
+
121
+ Template codes and variables are defined by your project: create the templates you need in Strapi (or in Brevo) and reference them by `code` or document ID when calling the API.
122
+
123
+ ## Preview
124
+
125
+ In the template editor, a preview on the right replaces variables with sample values (including `{{logo_url}}` when configured).
126
+
127
+ ## Technical requirements
128
+
129
+ - **Brevo**: `BREVO_API_KEY` and sender (admin config or `.env` / `BREVO_SENDER`)
130
+ - **OpenAI (optional)**: key in Config or `OPENAI_API_KEY` for “Generate with AI”
131
+ - Project uses the `@getbrevo/brevo` package
132
+
133
+ ## Contributors
134
+
135
+ - Florian Dupuis ([dupflo](https://github.com/dupflo))
136
+
137
+ ## License
138
+
139
+ MIT — see [repository](https://github.com/calistock/strapi-plugin-brevo-template-sender).