deliver-contact-form-message.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. module.exports = {
  2. friendlyName: 'Deliver contact form message',
  3. description: 'Deliver a contact form message to the appropriate internal channel(s).',
  4. inputs: {
  5. emailAddress: {
  6. required: true,
  7. type: 'string',
  8. description: 'A return email address where we can respond.',
  9. example: 'hermione@hogwarts.edu'
  10. },
  11. topic: {
  12. required: true,
  13. type: 'string',
  14. description: 'The topic from the contact form.',
  15. example: 'I want to buy stuff.'
  16. },
  17. fullName: {
  18. required: true,
  19. type: 'string',
  20. description: 'The full name of the human sending this message.',
  21. example: 'Hermione Granger'
  22. },
  23. message: {
  24. required: true,
  25. type: 'string',
  26. description: 'The custom message, in plain text.'
  27. }
  28. },
  29. exits: {
  30. success: {
  31. description: 'The message was sent successfully.'
  32. }
  33. },
  34. fn: async function(inputs, exits) {
  35. if (!sails.config.custom.internalEmailAddress) {
  36. throw new Error(
  37. `Cannot deliver incoming message from contact form because there is no internal
  38. email address (\`sails.config.custom.internalEmailAddress\`) configured for this
  39. app. To enable contact form emails, you'll need to add this missing setting to
  40. your custom config -- usually in \`config/custom.js\`, \`config/staging.js\`,
  41. \`config/production.js\`, or via system environment variables.`
  42. );
  43. }
  44. await sails.helpers.sendTemplateEmail.with({
  45. to: sails.config.custom.internalEmailAddress,
  46. subject: 'New Contact Form Message',
  47. template: 'internal/email-contact-form',
  48. layout: false,
  49. templateData: {
  50. contactName: inputs.fullName,
  51. contactEmail: inputs.emailAddress,
  52. topic: inputs.topic,
  53. message: inputs.message
  54. }
  55. });
  56. return exits.success();
  57. }
  58. };