-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9371a0
commit f8ea468
Showing
2 changed files
with
139 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,152 @@ | ||
# Bandwidth Java SDK | ||
|
||
Bandwidth's API docs can be found at https://dev.bandwidth.com | ||
|
||
Java specific docs can be found at https://dev.bandwidth.com/sdks/java.html | ||
## Getting Started | ||
|
||
## Download & Install | ||
### Installation | ||
|
||
Maven: | ||
Add the following dependency to your `pom.xml` file | ||
|
||
```xml | ||
``` | ||
<!-- https://mvnrepository.com/artifact/com.bandwidth.sdk/bandwidth-sdk --> | ||
<dependency> | ||
<groupId>com.bandwidth.sdk</groupId> | ||
<artifactId>bandwidth-sdk</artifactId> | ||
<version>1.0.0</version> | ||
<version>{version}</version> | ||
</dependency> | ||
``` | ||
|
||
## Initialize Bandwidth Client | ||
|
||
```java | ||
### Initialize | ||
|
||
//Set the voice client configuration with credentials | ||
``` | ||
BandwidthClient client = new BandwidthClient.Builder() | ||
.messagingBasicAuthCredentials("MESSAGING_API_TOKEN", "MESSAGING_API_SECRET") | ||
.voiceBasicAuthCredentials("VOICE_API_USERNAME", "VOICE_API_PASSWORD") | ||
.environment(Environment.PRODUCTION) | ||
.messagingBasicAuthCredentials("username", "password") | ||
.voiceBasicAuthCredentials("username", "password") | ||
.twoFactorAuthBasicAuthCredentials("username", "password") | ||
.webRtcBasicAuthCredentials("username", "password") | ||
.build(); | ||
String accountId = "12345"; | ||
``` | ||
|
||
### Create A Phone Call | ||
|
||
//Fully qualified name to remove confilicts | ||
com.bandwidth.messaging.controllers.APIController messagingController = client.getMessagingClient().getAPIController(); | ||
``` | ||
com.bandwidth.voice.controllers.APIController voiceController = client.getVoiceClient().getAPIController(); | ||
String to = "+15554443333"; | ||
String from = "+15553334444"; | ||
String applicationId = "3-a-b-c"; | ||
String answerUrl = "https://sample.com"; | ||
ApiCreateCallRequest body = new ApiCreateCallRequest(); | ||
body.setTo(to); | ||
body.setFrom(from); | ||
body.setApplicationId(applicationId); | ||
body.setAnswerUrl(answerUrl); | ||
ApiResponse<ApiCallResponse> createCallResponse = voiceController.createCall(accountId, body); | ||
System.out.println(createCallResponse.getResult().getCallId()); | ||
``` | ||
|
||
## Create Phone Call | ||
### Send A Text Message | ||
|
||
```java | ||
import com.bandwidth.voice.models.ApiCreateCallRequest; | ||
``` | ||
String to = "+15554443333"; | ||
ArrayList<String> toNumbers = new ArrayList<String>(); | ||
toNumbers.add(to); | ||
String from = "+15553334444"; | ||
String applicationId = "3-a-b-d"; | ||
String text = "Hello from Java"; | ||
MessageRequest body = new MessageRequest(); | ||
body.setTo(toNumbers); | ||
body.setFrom(from); | ||
body.setText(text); | ||
body.setApplicationId(applicationId); | ||
ApiResponse<BandwidthMessage> createMessageResponse = messagingController.createMessage(accountId, body); | ||
System.out.println(createMessageResponse.getResult().getMessageId()); | ||
``` | ||
|
||
//Create the ApiCreateCallRequst object and populate. | ||
ApiCreateCallRequest callRequest = new ApiCreateCallRequest(); | ||
### Create BXML | ||
|
||
callRequest.setApplicationId("application.Id"); | ||
callRequest.setTo("+19999999999"); | ||
callRequest.setAnswerUrl("https://test.com"); | ||
callRequest.setFrom("+17777777777"); | ||
``` | ||
SpeakSentence speakSentence = SpeakSentence.builder() | ||
.text("Hello world") | ||
.voice("susan") | ||
.gender("female") | ||
.locale("en_US") | ||
.build(); | ||
String response = new Response() | ||
.add(speakSentence) | ||
.toBXML(); | ||
System.out.println(response); | ||
``` | ||
|
||
//The voice client createCall can throw these exceptions. | ||
try { | ||
ApiResponse<ApiCallResponse> response = voiceController.createCall("account.id", callRequest); | ||
System.out.println(response.getResult().getCallId()); | ||
} catch (IOException | ApiException e) { | ||
//Handle | ||
} | ||
### Create A MFA Request | ||
|
||
``` | ||
String to = "+15554443333"; | ||
String from = "+15553334444"; | ||
String applicationId = "3-a-c-b"); | ||
String scope = "scope"; | ||
int digits = 6; | ||
String message = "Your temporary {NAME} {SCOPE} code is {CODE}"; | ||
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema(); | ||
body.setTo(to); | ||
body.setFrom(from); | ||
body.setApplicationId(applicationId); | ||
body.setScope(scope); | ||
body.setDigits(digits); | ||
body.setMessage(message); | ||
mfaController.createVoiceTwoFactor(accountId, body); | ||
String code = "123456"; //this is the user code to verify | ||
int expirationTimeInMinutes = 3; | ||
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema(); | ||
body.setTo(to); | ||
body.setApplicationId(applicationId); | ||
body.setScope(scope); | ||
body.setCode(code); | ||
body.setExpirationTimeInMinutes(expirationTimeInMinutes); | ||
ApiResponse<TwoFactorVerifyCodeResponse> response = mfaController.createVerifyTwoFactor(accountId, body); | ||
System.out.println(response.getResult().getValid()); | ||
``` | ||
|
||
## Generate BXML | ||
### WebRtc Participant & Session Management | ||
|
||
```java | ||
import com.bandwidth.sdk.voice.models.verbs.*; | ||
``` | ||
Session createSessionBody = new Session(); | ||
createSessionBody.setTag("new-session"); | ||
//Create a Bandwidth XML (BXML) SpeakSentence Verb. Supply the sentence to be spoken. | ||
SpeakSentence speakSentence = SpeakSentence.builder() | ||
.text("Hello World") | ||
.build(); | ||
ApiResponse<Session> createSessionResponse = webrtcController.createSession(accountId, createSessionBody); | ||
String sessionId = createSessionResponse.getResult().getId(); | ||
//Create the response object and add the speakSentence verb to the response. | ||
Response response = Response.builder().build().add(speakSentence); | ||
Participant createParticipantBody = new Participant(); | ||
createParticipantBody.setCallbackUrl("https://sample.com"); | ||
ArrayList<PublishPermissionEnum> publishPermissions = new ArrayList<PublishPermissionEnum>(); | ||
publishPermissions.add(PublishPermissionEnum.AUDIO); | ||
publishPermissions.add(PublishPermissionEnum.VIDEO); | ||
//view the BXML | ||
System.out.println( response.toXml() ) | ||
ApiResponse<AccountsParticipantsResponse> createParticipantResponse = webrtcController.createParticipant(accountId, createParticipantBody); | ||
String participantId = createParticipantResponse.getResult().getParticipant().getId(); | ||
webrtcController.addParticipantToSession(accountId, sessionId, participantId, null); | ||
``` | ||
|
||
## Send Text Message | ||
## Supported Java Versions | ||
|
||
```java | ||
import com.bandwidth.messaging.models.MessageRequest; | ||
This package can be used with Java >= 1.8 | ||
|
||
MessageRequest messageRequest = new MessageRequest(); | ||
## Documentation | ||
|
||
List<String> toNumbers = new ArrayList<>(); | ||
Documentation for this package can be found at https://dev.bandwidth.com/sdks/java.html | ||
|
||
toNumbers.add("+12345678902"); | ||
## Credentials | ||
|
||
messageRequest.setApplicationId(MSG_APPLICATION_ID); | ||
messageRequest.setText("Hey, check this out!"); | ||
messageRequest.setFrom("+12345678901"); | ||
messageRequest.setTo( toNumbers ); | ||
messageRequest.setTag("test tag"); | ||
Information for credentials for this package can be found at https://dev.bandwidth.com/guides/accountCredentials.html | ||
|
||
try { | ||
ApiResponse<BandwidthMessage> response = messagingController.createMessage(accountId, messageRequest); | ||
System.out.println(response.getResult().getId()); | ||
} catch (ApiException | IOException e){ | ||
//Handle | ||
} | ||
``` |
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