-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improvement] WhatsApp file uploading/sending and error handling #2072
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
225d1ba
Send out the text of a message that has an image
mattwr18 0a2fc74
Refactor image uploads
mattwr18 b567f66
Handle errors in statuses
mattwr18 b2388d6
Adapt tests to new api
mattwr18 2ce3c5a
Refactor and add specs for BroadcastRequestJob
mattwr18 f650d45
Refactor and add specs for 360dialog file sending
mattwr18 791bbb0
Mock endpoint to fix failing specs on runner
mattwr18 1087670
Set up retry policy for 5xx responses
mattwr18 f41f217
Remove undesired change
mattwr18 8637544
Ensure failure to upload files does not block request broadcast
mattwr18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module WhatsAppAdapter | ||
class BroadcastMessagesJob < ApplicationJob | ||
queue_as :broadcast_whats_app_messages | ||
|
||
attr_reader :request, :recipients | ||
|
||
def perform(request_id: request.id) | ||
@request = Request.find(request_id) | ||
@recipients = request.organization.contributors.active.with_tags(request.tag_list).with_whats_app | ||
|
||
upload_files_to_meta if request.files.attached? | ||
create_and_send_messages | ||
end | ||
|
||
private | ||
|
||
def upload_files_to_meta | ||
WhatsAppAdapter::ThreeSixtyDialog::UploadFileService.call(request_id: request.id) | ||
end | ||
|
||
def create_and_send_messages | ||
recipients.each do |contributor| | ||
message = Message.new( | ||
sender: request.user, | ||
recipient: contributor, | ||
text: request.personalized_text(contributor), | ||
request: request, | ||
broadcasted: true | ||
) | ||
|
||
message.files = Message::File.attach_files(request.files) if request.files.attached? | ||
|
||
message.save! | ||
message.send! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
db/migrate/20241108101857_add_external_file_ids_to_requests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddExternalFileIdsToRequests < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :requests, :external_file_ids, :string, array: true, default: [] | ||
add_index :requests, :external_file_ids, using: 'gin' | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to enqueue
UploadFileJob
s for every_file
. Does it matter that we enqueue only one job now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually was an oversight. We iterated through every file attached to a message to schedule a job to upload the file, but then iterated through a request's files to actually upload them so we were uploading many more files than were necessary.