-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improvement] WhatsApp file uploading/sending and error handling (#2072)
TODO: - [ ] Add specs for statuses/errors in spec/requests/whats_app/three_sixty_dialog_webhook_spec.rb - [x] refactor app/adapters/whats_app_adapter/three_sixty_dialog_outbound/file.rb to remove disabling rubocop Specs for statuses/errors will be added in the PR that actually handles statuses.
- Loading branch information
Showing
23 changed files
with
735 additions
and
97 deletions.
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.