I am building a service responsible for sending email/sms communications. The service receives a request that contains information necessary to build an email/sms template and the recipient information of where to send it.
Example CURL request:
curl -X POST \ http://service.local/api/finance/payment-reminder \ -H 'Postman-Token: ec32d436-8eef-4660-8424-600bfca6a3fb' \ -H 'X-API-KEY: secret' \ -H 'cache-control: no-cache' \ -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ -F method=email \ -F name=dave \ -F email@example.com \ -F amount=100 \ -F due_date=now \ -F phone_number=8957598696
Now from here I load the relevant class, send the template via the specified method to the recipient.
From here I need to persist the information I have sent to the customer in order to be able to show consumers of the system what communications have been sent to any given customer.
Thinking about it I have two options:
- I can store the request data and the class path used to generate the template and rebuild it if required.
The issue with this is the template may very well be changed in the future. If this happens then my representation of the communication sent is not accurate. Also at some time in the future a template could be moved/deleted and this would cause rebuilding to be impossible.
- Store the entire generated output of the template file (HTML for email, text for SMS)
This doesn't feel 'clean' for me as I don't necessarily like the idea of storing HTML in a database table.
Am I overthinking the storing of HTML and in this scenario it is fine to do. Obviously there will be no need to edit the information once the content has been persisted.