Class: InstagramConnect::SendMessageJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- InstagramConnect::SendMessageJob
- Defined in:
- app/jobs/instagram_connect/send_message_job.rb
Overview
Sends one pending outbound Message via the Graph API, exactly once. Claims the row (pending -> sending) with an atomic UPDATE so a duplicate enqueue can't double-send, then enforces Meta's messaging window — auto-applying the HUMAN_AGENT tag once the standard 24h window has passed.
Instance Method Summary collapse
Instance Method Details
#perform(message_id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/jobs/instagram_connect/send_message_job.rb', line 9 def perform() claimed = Message.where(id: , status: "pending") .update_all(status: "sending", updated_at: Time.current) return unless claimed == 1 = Message.find() tag = MessagingWindow.new(last_inbound_at: .conversation.last_inbound_at).send_tag if tag == :blocked return (, "outside_messaging_window", "The reply window has closed; the customer must message again.") end deliver(, tag) end |