@@ -41,7 +41,9 @@ public class MessageBirdClient {
41
41
* can, however, override this behaviour by providing absolute URLs
42
42
* ourselves.
43
43
*/
44
- private static final String CONVERSATIONS_BASE_URL = "https://conversations.messagebird.com/v1" ;
44
+ private static final String BASE_URL_CONVERSATIONS = "https://conversations.messagebird.com/v1" ;
45
+ private static final String BASE_URL_CONVERSATIONS_WHATSAPP_SANDBOX = "https://whatsapp-sandbox.messagebird.com/v1" ;
46
+
45
47
static final String VOICE_CALLS_BASE_URL = "https://voice.messagebird.com" ;
46
48
private static String [] supportedLanguages = {"de-DE" , "en-AU" , "en-UK" , "en-US" , "es-ES" , "es-LA" , "fr-FR" , "it-IT" , "nl-NL" , "pt-BR" };
47
49
@@ -66,11 +68,23 @@ public class MessageBirdClient {
66
68
private static final String VOICELEGS_SUFFIX_PATH = "/legs" ;
67
69
68
70
private MessageBirdService messageBirdService ;
71
+ private String conversationsBaseUrl ;
72
+
73
+ public enum Feature {
74
+ ENABLE_CONVERSATION_API_WHATSAPP_SANDBOX
75
+ }
69
76
70
77
public MessageBirdClient (final MessageBirdService messageBirdService ) {
71
78
this .messageBirdService = messageBirdService ;
79
+ this .conversationsBaseUrl = BASE_URL_CONVERSATIONS ;
72
80
}
73
81
82
+ public MessageBirdClient (final MessageBirdService messageBirdService , List <Feature > features ) {
83
+ this (messageBirdService );
84
+ if (features .indexOf (Feature .ENABLE_CONVERSATION_API_WHATSAPP_SANDBOX ) >= 0 ) {
85
+ this .conversationsBaseUrl = BASE_URL_CONVERSATIONS_WHATSAPP_SANDBOX ;
86
+ }
87
+ }
74
88
/****************************************************************************************************/
75
89
/** Balance and HRL methods **/
76
90
/****************************************************************************************************/
@@ -800,7 +814,7 @@ public Conversation viewConversation(final String id) throws NotFoundException,
800
814
if (id == null ) {
801
815
throw new IllegalArgumentException ("Id must be specified" );
802
816
}
803
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_PATH ;
817
+ String url = this . conversationsBaseUrl + CONVERSATION_PATH ;
804
818
return messageBirdService .requestByID (url , id , Conversation .class );
805
819
}
806
820
@@ -816,7 +830,7 @@ public Conversation updateConversation(final String id, final ConversationStatus
816
830
if (id == null ) {
817
831
throw new IllegalArgumentException ("Id must be specified." );
818
832
}
819
- String url = String .format ("%s%s/%s" , CONVERSATIONS_BASE_URL , CONVERSATION_PATH , id );
833
+ String url = String .format ("%s%s/%s" , this . conversationsBaseUrl , CONVERSATION_PATH , id );
820
834
return messageBirdService .sendPayLoad ("PATCH" , url , status , Conversation .class );
821
835
}
822
836
@@ -829,7 +843,7 @@ public Conversation updateConversation(final String id, final ConversationStatus
829
843
*/
830
844
public ConversationList listConversations (final int offset , final int limit )
831
845
throws UnauthorizedException , GeneralException {
832
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_PATH ;
846
+ String url = this . conversationsBaseUrl + CONVERSATION_PATH ;
833
847
return messageBirdService .requestList (url , offset , limit , ConversationList .class );
834
848
}
835
849
@@ -853,7 +867,7 @@ public ConversationList listConversations() throws UnauthorizedException, Genera
853
867
*/
854
868
public Conversation startConversation (ConversationStartRequest request )
855
869
throws UnauthorizedException , GeneralException {
856
- String url = String .format ("%s%s/start" , CONVERSATIONS_BASE_URL , CONVERSATION_PATH );
870
+ String url = String .format ("%s%s/start" , this . conversationsBaseUrl , CONVERSATION_PATH );
857
871
return messageBirdService .sendPayLoad (url , request , Conversation .class );
858
872
}
859
873
@@ -872,7 +886,7 @@ public ConversationMessageList listConversationMessages(
872
886
) throws UnauthorizedException , GeneralException {
873
887
String url = String .format (
874
888
"%s%s/%s%s" ,
875
- CONVERSATIONS_BASE_URL ,
889
+ this . conversationsBaseUrl ,
876
890
CONVERSATION_PATH ,
877
891
conversationId ,
878
892
CONVERSATION_MESSAGE_PATH
@@ -903,7 +917,7 @@ public ConversationMessageList listConversationMessages(
903
917
*/
904
918
public ConversationMessage viewConversationMessage (final String messageId )
905
919
throws NotFoundException , GeneralException , UnauthorizedException {
906
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_MESSAGE_PATH ;
920
+ String url = this . conversationsBaseUrl + CONVERSATION_MESSAGE_PATH ;
907
921
return messageBirdService .requestByID (url , messageId , ConversationMessage .class );
908
922
}
909
923
@@ -920,7 +934,7 @@ public ConversationMessage sendConversationMessage(
920
934
) throws UnauthorizedException , GeneralException {
921
935
String url = String .format (
922
936
"%s%s/%s%s" ,
923
- CONVERSATIONS_BASE_URL ,
937
+ this . conversationsBaseUrl ,
924
938
CONVERSATION_PATH ,
925
939
conversationId ,
926
940
CONVERSATION_MESSAGE_PATH
@@ -935,7 +949,7 @@ public ConversationMessage sendConversationMessage(
935
949
*/
936
950
public void deleteConversationWebhook (final String webhookId )
937
951
throws NotFoundException , GeneralException , UnauthorizedException {
938
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH ;
952
+ String url = this . conversationsBaseUrl + CONVERSATION_WEBHOOK_PATH ;
939
953
messageBirdService .deleteByID (url , webhookId );
940
954
}
941
955
@@ -947,7 +961,7 @@ public void deleteConversationWebhook(final String webhookId)
947
961
*/
948
962
public ConversationWebhook sendConversationWebhook (final ConversationWebhookCreateRequest request )
949
963
throws UnauthorizedException , GeneralException {
950
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH ;
964
+ String url = this . conversationsBaseUrl + CONVERSATION_WEBHOOK_PATH ;
951
965
return messageBirdService .sendPayLoad (url , request , ConversationWebhook .class );
952
966
}
953
967
@@ -962,7 +976,7 @@ public ConversationWebhook updateConversationWebhook(final String id, final Conv
962
976
throw new IllegalArgumentException ("Conversation webhook ID must be specified." );
963
977
}
964
978
965
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH + "/" + id ;
979
+ String url = this . conversationsBaseUrl + CONVERSATION_WEBHOOK_PATH + "/" + id ;
966
980
return messageBirdService .sendPayLoad ("PATCH" , url , request , ConversationWebhook .class );
967
981
}
968
982
@@ -973,7 +987,7 @@ public ConversationWebhook updateConversationWebhook(final String id, final Conv
973
987
* @return The retrieved webhook.
974
988
*/
975
989
public ConversationWebhook viewConversationWebhook (final String webhookId ) throws NotFoundException , GeneralException , UnauthorizedException {
976
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH ;
990
+ String url = this . conversationsBaseUrl + CONVERSATION_WEBHOOK_PATH ;
977
991
return messageBirdService .requestByID (url , webhookId , ConversationWebhook .class );
978
992
}
979
993
@@ -986,7 +1000,7 @@ public ConversationWebhook viewConversationWebhook(final String webhookId) throw
986
1000
*/
987
1001
ConversationWebhookList listConversationWebhooks (final int offset , final int limit )
988
1002
throws UnauthorizedException , GeneralException {
989
- String url = CONVERSATIONS_BASE_URL + CONVERSATION_WEBHOOK_PATH ;
1003
+ String url = this . conversationsBaseUrl + CONVERSATION_WEBHOOK_PATH ;
990
1004
return messageBirdService .requestList (url , offset , limit , ConversationWebhookList .class );
991
1005
}
992
1006
0 commit comments