diff --git a/app/controllers/api/v1/briefings_controller.rb b/app/controllers/api/v1/briefings_controller.rb new file mode 100644 index 0000000..70fe429 --- /dev/null +++ b/app/controllers/api/v1/briefings_controller.rb @@ -0,0 +1,28 @@ +module Api + module V1 + class BriefingsController < ApplicationController + skip_before_action :verify_authenticity_token + + RECIPIENT = "austindanielfrench@gmail.com".freeze + + def send_briefing + subject = params[:subject] + sections = params[:sections] + + if subject.blank? || sections.blank? + return render json: { error: "Missing required fields: subject, sections" }, status: :unprocessable_entity + end + + BriefingMailer.digest( + recipient: RECIPIENT, + subject: subject, + sections: sections.map(&:to_unsafe_h) + ).deliver_later + + render json: { success: true, message: "Briefing email queued for delivery" } + rescue StandardError => e + render json: { error: e.message }, status: :internal_server_error + end + end + end +end diff --git a/app/mailers/briefing_mailer.rb b/app/mailers/briefing_mailer.rb new file mode 100644 index 0000000..b26f153 --- /dev/null +++ b/app/mailers/briefing_mailer.rb @@ -0,0 +1,8 @@ +class BriefingMailer < ApplicationMailer + def digest(recipient:, subject:, sections:) + @sections = sections + @subject = subject + + mail(to: recipient, subject: subject) + end +end diff --git a/app/views/briefing_mailer/digest.html.erb b/app/views/briefing_mailer/digest.html.erb new file mode 100644 index 0000000..e1bfb14 --- /dev/null +++ b/app/views/briefing_mailer/digest.html.erb @@ -0,0 +1,56 @@ + + + + + + <%= @subject %> + + + + + + +
+ + + + + + + + <% @sections.each_with_index do |section, index| %> + + + + <% end %> + + + + + +
+

<%= @subject %>

+
+
+ + + + + + + + + +
+

<%= section[:title] || section["title"] %>

+
+ <%= raw(section[:content] || section["content"]) %> +
+
+

+ Sent by Hermes Agent from austn.net +

+
+
+ + diff --git a/app/views/briefing_mailer/digest.text.erb b/app/views/briefing_mailer/digest.text.erb new file mode 100644 index 0000000..7de0031 --- /dev/null +++ b/app/views/briefing_mailer/digest.text.erb @@ -0,0 +1,16 @@ +<%= @subject %> +<%= "=" * @subject.length %> + +<% @sections.each_with_index do |section, index| %> +<%= (section[:title] || section["title"]).upcase %> +<%= "-" * (section[:title] || section["title"]).length %> + +<%= strip_tags(section[:content] || section["content"]) %> + +<% unless index == @sections.length - 1 %> +--- + +<% end %> +<% end %> +-- +Sent by Hermes Agent from austn.net diff --git a/config/routes.rb b/config/routes.rb index 8f03b4f..eb29dc0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -229,6 +229,9 @@ post "images/generate", to: "images#generate" # Sync - blocks until complete post "images/generate_async", to: "images#generate_async" # Async - returns generation ID get "images/:id/status", to: "images#status", as: :image_status + + # Briefing email endpoint + post "briefings/send", to: "briefings#send_briefing" end end