@@ -1894,6 +1894,34 @@ public TemplateList listWhatsAppTemplates(final int offset, final int limit)
1894
1894
return messageBirdService .requestList (url , offset , limit , TemplateList .class );
1895
1895
}
1896
1896
1897
+ /**
1898
+ * Gets a WhatsAppTemplate listing with specified pagination options and a wabaID or channelID filter.
1899
+ *
1900
+ * @param offset Number of objects to skip.
1901
+ * @param limit Number of objects to take.
1902
+ * @param wabaID The WABA ID to filter templates by.
1903
+ * @param channelID A channel ID filter to return only templates that can be sent via that channel.
1904
+ * @return List of templates.
1905
+ * @throws UnauthorizedException if client is unauthorized
1906
+ * @throws GeneralException general exception
1907
+ * @throws IllegalArgumentException if the provided arguments are not valid
1908
+ */
1909
+ public TemplateList listWhatsAppTemplates (final int offset , final int limit , final String wabaID , final String channelID )
1910
+ throws UnauthorizedException , GeneralException , IllegalArgumentException {
1911
+ validateWABAIDAndChannelIDArguments (wabaID , channelID );
1912
+
1913
+ Map <String , Object > map = new LinkedHashMap <>();
1914
+ if (wabaID != null ) map .put ("wabaId" , wabaID );
1915
+ if (channelID != null ) map .put ("channelId" , channelID );
1916
+ String url = String .format (
1917
+ "%s%s%s" ,
1918
+ INTEGRATIONS_BASE_URL_V3 ,
1919
+ INTEGRATIONS_WHATSAPP_PATH ,
1920
+ TEMPLATES_PATH
1921
+ );
1922
+ return messageBirdService .requestList (url , map , offset , limit , TemplateList .class );
1923
+ }
1924
+
1897
1925
/**
1898
1926
* Gets a template listing with default pagination options.
1899
1927
*
@@ -1913,12 +1941,13 @@ public TemplateList listWhatsAppTemplates() throws UnauthorizedException, Genera
1913
1941
*
1914
1942
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
1915
1943
* @return {@code List<TemplateResponse>} template list
1916
- * @throws UnauthorizedException if client is unauthorized
1917
- * @throws GeneralException general exception
1918
- * @throws NotFoundException if template name is not found
1944
+ * @throws UnauthorizedException if client is unauthorized
1945
+ * @throws GeneralException general exception
1946
+ * @throws NotFoundException if template name is not found
1947
+ * @throws IllegalArgumentException if the provided arguments are not valid
1919
1948
*/
1920
1949
public List <TemplateResponse > getWhatsAppTemplatesBy (final String templateName )
1921
- throws GeneralException , UnauthorizedException , NotFoundException {
1950
+ throws GeneralException , UnauthorizedException , NotFoundException , IllegalArgumentException {
1922
1951
if (templateName == null ) {
1923
1952
throw new IllegalArgumentException ("Template name must be specified." );
1924
1953
}
@@ -1933,19 +1962,50 @@ public List<TemplateResponse> getWhatsAppTemplatesBy(final String templateName)
1933
1962
return messageBirdService .requestByIdAsList (url , templateName , TemplateResponse .class );
1934
1963
}
1935
1964
1965
+ /**
1966
+ * Retrieves the template of an existing template name.
1967
+ *
1968
+ * @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
1969
+ * @param wabaID An optional WABA ID to look for the template ID under.
1970
+ * @param channelID An optional channel ID to specify. If the template can be sent via the channel, it will return the template.
1971
+ *
1972
+ * @return {@code List<TemplateResponse>} template list
1973
+ * @throws UnauthorizedException if client is unauthorized
1974
+ * @throws GeneralException general exception
1975
+ * @throws NotFoundException if template name is not found under the given WABA or cannot be sent under the supplied channel ID
1976
+ * @throws IllegalArgumentException if the provided arguments are not valid
1977
+ */
1978
+ public List <TemplateResponse > getWhatsAppTemplatesBy (final String templateName , final String wabaID , final String channelID )
1979
+ throws GeneralException , UnauthorizedException , NotFoundException , IllegalArgumentException {
1980
+ if (templateName == null ) {
1981
+ throw new IllegalArgumentException ("Template name must be specified." );
1982
+ }
1983
+
1984
+ String id = String .format ("%s%s" , templateName , getWabaIDOrChannelIDQuery (wabaID , channelID ));
1985
+ String url = String .format (
1986
+ "%s%s%s" ,
1987
+ INTEGRATIONS_BASE_URL_V2 ,
1988
+ INTEGRATIONS_WHATSAPP_PATH ,
1989
+ TEMPLATES_PATH
1990
+ );
1991
+
1992
+ return messageBirdService .requestByIdAsList (url , id , TemplateResponse .class );
1993
+ }
1994
+
1936
1995
/**
1937
- * Retrieves the template of an existing template name and language.
1996
+ * Retrieves the template of an existing template name and language under the first waba connected to the requesting user .
1938
1997
*
1939
1998
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
1940
1999
* @param language A language code as returned by getWhatsAppTemplateBy in the language variable
1941
2000
*
1942
- * @return {@code TemplateResponse} template list
2001
+ * @return {@code TemplateResponse} template
1943
2002
* @throws UnauthorizedException if client is unauthorized
1944
2003
* @throws GeneralException general exception
1945
- * @throws NotFoundException if template name and language are not found
2004
+ * @throws NotFoundException if template name and language are not found under the first waba connected to the requesting user.
2005
+ * @throws IllegalArgumentException if the provided arguments are not valid
1946
2006
*/
1947
2007
public TemplateResponse fetchWhatsAppTemplateBy (final String templateName , final String language )
1948
- throws GeneralException , UnauthorizedException , NotFoundException {
2008
+ throws GeneralException , UnauthorizedException , NotFoundException , IllegalArgumentException {
1949
2009
if (templateName == null || language == null ) {
1950
2010
throw new IllegalArgumentException ("Template name and language must be specified." );
1951
2011
}
@@ -1962,51 +2022,98 @@ public TemplateResponse fetchWhatsAppTemplateBy(final String templateName, final
1962
2022
}
1963
2023
1964
2024
/**
1965
- * Delete templates of an existing template name.
2025
+ * Retrieves the template of an existing template name and language under a WABA or for a channel .
1966
2026
*
1967
- * @param templateName A template name which is created on the MessageBird platform
1968
- * @throws UnauthorizedException if client is unauthorized
1969
- * @throws GeneralException general exception
1970
- * @throws NotFoundException if template name is not found
2027
+ * @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
2028
+ * @param language A language code as returned by getWhatsAppTemplateBy in the language variable
2029
+ * @param wabaID An optional WABA ID to look for the template ID under.
2030
+ * @param channelID An optional channel ID to specify. If the template can be sent via the channel, it will return the template.
2031
+ *
2032
+ * @return {@code TemplateResponse} template
2033
+ * @throws UnauthorizedException if client is unauthorized
2034
+ * @throws GeneralException general exception
2035
+ * @throws NotFoundException if template name and language are not found under the given WABA or cannot be sent under the supplied channel ID.
2036
+ * @throws IllegalArgumentException if the provided arguments are not valid
1971
2037
*/
1972
- public void deleteTemplatesBy (final String templateName )
1973
- throws UnauthorizedException , GeneralException , NotFoundException {
1974
- if (templateName == null ) {
1975
- throw new IllegalArgumentException ("Template name must be specified." );
2038
+ public TemplateResponse fetchWhatsAppTemplateBy (final String templateName , final String language , final String wabaID , final String channelID )
2039
+ throws GeneralException , UnauthorizedException , NotFoundException , IllegalArgumentException {
2040
+ if (templateName == null || language == null ) {
2041
+ throw new IllegalArgumentException ("Template name and language must be specified." );
1976
2042
}
1977
2043
1978
2044
String url = String .format (
1979
- "%s%s%s/%s" ,
1980
- INTEGRATIONS_BASE_URL_V2 ,
1981
- INTEGRATIONS_WHATSAPP_PATH ,
1982
- TEMPLATES_PATH ,
1983
- templateName
2045
+ "%s%s%s/%s/%s%s" ,
2046
+ INTEGRATIONS_BASE_URL_V2 ,
2047
+ INTEGRATIONS_WHATSAPP_PATH ,
2048
+ TEMPLATES_PATH ,
2049
+ templateName ,
2050
+ language ,
2051
+ getWabaIDOrChannelIDQuery (wabaID , channelID )
1984
2052
);
1985
- messageBirdService .delete (url , null );
2053
+ return messageBirdService .request (url , TemplateResponse . class );
1986
2054
}
1987
2055
1988
2056
/**
1989
- * Delete template of an existing template name and language.
2057
+ * Validates the WABA ID and Channel ID argument pair.
2058
+ *
2059
+ * @param wabaID A WABA ID.
2060
+ * @param channelID A channel ID.
2061
+ * @throws IllegalArgumentException if the argument pair is invalid.
2062
+ */
2063
+ private void validateWABAIDAndChannelIDArguments (String wabaID , String channelID )
2064
+ throws IllegalArgumentException {
2065
+ if (wabaID == null && channelID == null ) {
2066
+ throw new IllegalArgumentException ("wabaID or channelID must be specified" );
2067
+ }
2068
+
2069
+ if (wabaID != null && channelID != null ) {
2070
+ throw new IllegalArgumentException ("only supply wabaID or channelID - not both" );
2071
+ }
2072
+ }
2073
+
2074
+ /**
2075
+ * Validates the WABA ID and Channel ID argument pair and returns a valid query parameter string.
2076
+ *
2077
+ * @param wabaID A WABA ID.
2078
+ * @param channelID A channel ID.
2079
+ * @throws IllegalArgumentException if the argument pair is invalid.
2080
+ */
2081
+ private String getWabaIDOrChannelIDQuery (String wabaID , String channelID )
2082
+ throws IllegalArgumentException {
2083
+ validateWABAIDAndChannelIDArguments (wabaID , channelID );
2084
+
2085
+ String query = "" ;
2086
+
2087
+ if (wabaID != null ) {
2088
+ query = String .format ("?wabaId=%s" , wabaID );
2089
+ }
2090
+ if (channelID != null ) {
2091
+ query = String .format ("?channelId=%s" , channelID );
2092
+ }
2093
+
2094
+ return query ;
2095
+ }
2096
+
2097
+ /**
2098
+ * Delete templates of an existing template name.
1990
2099
*
1991
2100
* @param templateName A template name which is created on the MessageBird platform
1992
- * @param language A language which is created on the MessageBird platform
1993
2101
* @throws UnauthorizedException if client is unauthorized
1994
2102
* @throws GeneralException general exception
1995
- * @throws NotFoundException if template name or language are not found
2103
+ * @throws NotFoundException if template name is not found
1996
2104
*/
1997
- public void deleteTemplatesBy (final String templateName , final String language )
2105
+ public void deleteTemplatesBy (final String templateName )
1998
2106
throws UnauthorizedException , GeneralException , NotFoundException {
1999
- if (templateName == null || language == null ) {
2000
- throw new IllegalArgumentException ("Template name and language must be specified." );
2107
+ if (templateName == null ) {
2108
+ throw new IllegalArgumentException ("Template name must be specified." );
2001
2109
}
2002
2110
2003
2111
String url = String .format (
2004
- "%s%s%s/%s/%s " ,
2112
+ "%s%s%s/%s" ,
2005
2113
INTEGRATIONS_BASE_URL_V2 ,
2006
2114
INTEGRATIONS_WHATSAPP_PATH ,
2007
2115
TEMPLATES_PATH ,
2008
- templateName ,
2009
- language
2116
+ templateName
2010
2117
);
2011
2118
messageBirdService .delete (url , null );
2012
2119
}
0 commit comments