media.rb 859 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Whatsapp::Webhook::Message::Media < Whatsapp::Webhook::Message
  3. private
  4. def attachment?
  5. true
  6. end
  7. def body
  8. message[:caption].present? ? "<p>#{message[:caption]}</p>" : ''
  9. end
  10. def content_type
  11. 'text/html'
  12. end
  13. def attachment
  14. media = Whatsapp::Incoming::Media.new(access_token: @channel.options[:access_token])
  15. data, mime_type = media.download(media_id: message[:id])
  16. filename = message[:filename].presence || "#{ticket.number}-#{message[:id]}.#{Whatsapp.file_suffix(mime_type:)}"
  17. [data, filename, mime_type]
  18. end
  19. def article_preferences
  20. preferences = {
  21. media_id: message[:id],
  22. }
  23. if message[:filename].present?
  24. preferences[:filename] = message[:filename]
  25. end
  26. super.merge(preferences)
  27. end
  28. end