Skip to content

Commit

Permalink
Merge pull request #137 from sahilas/main
Browse files Browse the repository at this point in the history
Added filename in send_document
  • Loading branch information
ignacio-chiazzo authored May 1, 2024
2 parents ad98efe + 3399da6 commit e7b413f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ messages_api.send_document(
)
```

Note, you can specify the filename via file [`filename` argument](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages).

**Send a sticker message**
It could use a link or a sticker_id.

Expand Down
5 changes: 3 additions & 2 deletions lib/whatsapp_sdk/api/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def send_video(
params(
sender_id: Integer, recipient_number: Integer,
document_id: T.nilable(String), link: T.nilable(String), caption: String,
message_id: T.nilable(String)
message_id: T.nilable(String), filename: T.nilable(String)
).returns(Api::Response)
end
def send_document(
sender_id:, recipient_number:, document_id: nil, link: nil, caption: "", message_id: nil
sender_id:, recipient_number:, document_id: nil, link: nil, caption: "", message_id: nil, filename: nil
)
if !document_id && !link
raise Resource::Errors::MissingArgumentError,
Expand All @@ -258,6 +258,7 @@ def send_document(
else
{ id: document_id, caption: caption }
end
params[:document] = params[:document].merge({ filename: filename }) if filename
params[:context] = { message_id: message_id } if message_id

response = send_request(
Expand Down
23 changes: 23 additions & 0 deletions test/whatsapp/api/messages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,29 @@ def test_send_document_message_with_a_link
assert_predicate(message_response, :ok?)
end

def test_send_document_message_with_file_name
@messages_api.expects(:send_request).with(
endpoint: "123123/messages",
params: {
messaging_product: "whatsapp",
to: 56_789,
recipient_type: "individual",
type: "document",
document: { link: document_link, caption: "Ignacio Chiazzo Profile" }
filename: "custom_name"
},
headers: { "Content-Type" => "application/json" }
).returns(valid_response(valid_contacts, valid_messages))

message_response = @messages_api.send_document(
sender_id: 123_123, recipient_number: 56_789,
link: document_link, caption: "Ignacio Chiazzo Profile", filename: "custom_name"
)

assert_mock_response(valid_contacts, valid_messages, message_response)
assert_predicate(message_response, :ok?)
end

def test_send_document_message_with_a_document_id
document_id = "12_345"
@messages_api.expects(:send_request).with(
Expand Down

0 comments on commit e7b413f

Please sign in to comment.