Skip to content

allow to filter templates by any field that is acceptable by whatsapp… #232

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, Stri
return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId, Map.of("name", templateName)));
}

/**
* Retrieve filtered templates message templates.
*
* @param whatsappBusinessAccountId Represents a specific WhatsApp Business Account (WABA). Make the API call to the WABA ID.
* @param filters map of query objects, key is query parameter and value is query parameter value, i.e. Map.of("name", "templateName") will search by name.
* For all filters see <a href="https://developers.facebook.com/docs/graph-api/reference/whats-app-business-hsm/#fields">Allowed fields for filtering</a>
* @return {@link MessageTemplates} List of templates
* @see <a href="https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates">Message templates</a>
*/
public MessageTemplates retrieveTemplates(String whatsappBusinessAccountId, Map<String, Object> filters) {
return executeSync(whatsappBusinessManagementApiService.retrieveTemplates(apiVersion.getValue(), whatsappBusinessAccountId, filters));
}
/**
* Retrieve templates message templates.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;

import static com.whatsapp.api.configuration.WhatsappApiConfig.getApiVersion;

Expand Down Expand Up @@ -507,6 +508,24 @@ void testRetrieveMessageTemplate3() throws IOException, URISyntaxException

}

@Test
void testRetrieveFilteredMessageTemplate() throws IOException, URISyntaxException, InterruptedException {
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);

WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi();
mockWebServer.enqueue(new MockResponse().newBuilder().code(200).body(fromResource("/retTemplate3.json")).build());

var templates = whatsappBusinessCloudApi.retrieveTemplates(WABA_ID, Map.of("name", "welcome_template3"));

RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("GET", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates?name=welcome_template3", recordedRequest.getPath());

Assertions.assertEquals(1, templates.data().size());
Assertions.assertEquals("welcome_template3", templates.data().get(0).name());
Assertions.assertEquals("Hello {{1}}, welcome to our {{2}} test.", templates.data().get(0).components().get(1).getText());
}

@Test
void testRetrieveMessageTemplate3WithLimit() throws IOException, URISyntaxException
{
Expand Down