Not sure what type of confirmation would be helpful, but I can confirm that the upload happens inside of a messages loop, and a single message can have multiple recipients, the twitter media id is sent on each recipient.
Here is the code:
# Get the media object if present
media = Medium.find(message.media_id) if message.media_id.present?
# p "Media: #{media}"
# if the media search above returned an object then we upload it to twitter
twitter_media_id = nil
if media.present?
# file = Paperclip.io_adapters.for(media.object).read
temp_file = Tempfile.new(media.object_file_name)
temp_file.binmode
media.object.copy_to_local_file(:medium, temp_file.path)
# NOTE: Does not appear that marking a media object as shared is working so for now the solution is to upload media for each recipient otherwise this could be done once per message
twitter_media_id = MediaHelper.upload_media_to_twitter(message.oauth_token, message.oauth_secret, temp_file)
# p "Twitter media id: #{twitter_media_id}"
end
# Attempt to send message and record status on recipient
recipients.each do |rec|
# p '****** Debug ******'
# p "Message: #{message.inspect}"
# p "Recipient: #{rec.inspect}"
result = MessagesHelper.send_twitter_dm(message.oauth_token, message.oauth_secret, message.body, rec.recipient, rec.name, twitter_media_id)
if result.present?
rec.platform_id = result['id']
rec.status = result['status']
rec.response = result['response']
rec.sent_at = Time.now if result['status'] == 'sent'
rec.save
end
end
Hope that is useful…