Skip to content

Commit bfa4071

Browse files
author
Dan Gurgui
authored
Merge pull request #64 from messagebird/feature/grow-1086-call-flow-examples
Feature/grow 1086 call flow examples
2 parents 7f9f332 + 38fb517 commit bfa4071

20 files changed

+973
-6
lines changed

api/src/main/java/com/messagebird/MessageBirdClient.java

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import com.messagebird.objects.*;
77
import com.messagebird.objects.conversations.*;
88
import com.messagebird.objects.voicecalls.*;
9-
import com.messagebird.objects.voicecalls.VoiceCallLeg;
10-
import com.messagebird.objects.voicecalls.VoiceCallLegResponse;
119

1210
import java.io.UnsupportedEncodingException;
1311
import java.math.BigInteger;
@@ -64,6 +62,7 @@ public class MessageBirdClient {
6462
static final String RECORDINGPATH = "/recordings";
6563
static final String TRANSCRIPTIONPATH = "/transcriptions";
6664
static final String WEBHOOKS = "/webhooks";
65+
static final String VOICECALLFLOWPATH = "/call-flows";
6766
private static final String VOICELEGS_SUFFIX_PATH = "/legs";
6867

6968
private MessageBirdService messageBirdService;
@@ -534,6 +533,97 @@ public LookupHlr viewLookupHlr(final BigInteger phoneNumber) throws Unauthorized
534533
return this.viewLookupHlr(lookupHlr);
535534
}
536535

536+
/**
537+
* Convenient function to list all call flows
538+
*
539+
* @param offset
540+
* @param limit
541+
* @return VoiceCallFlowList
542+
* @throws UnauthorizedException if client is unauthorized
543+
* @throws GeneralException general exception
544+
*/
545+
public VoiceCallFlowList listVoiceCallFlows(final Integer offset, final Integer limit)
546+
throws UnauthorizedException, GeneralException {
547+
if (offset != null && offset < 0) {
548+
throw new IllegalArgumentException("Offset must be > 0");
549+
}
550+
if (limit != null && limit < 0) {
551+
throw new IllegalArgumentException("Limit must be > 0");
552+
}
553+
String url = String.format("%s%s", VOICE_CALLS_BASE_URL, VOICECALLFLOWPATH);
554+
555+
return messageBirdService.requestList(url, offset, limit, VoiceCallFlowList.class);
556+
}
557+
558+
/**
559+
* Retrieves the information of an existing Call Flow. You only need to supply
560+
* the unique call flow ID that was returned upon creation or receiving.
561+
* @param id String
562+
* @return VoiceCallFlowResponse
563+
* @throws NotFoundException
564+
* @throws GeneralException
565+
* @throws UnauthorizedException
566+
*/
567+
public VoiceCallFlowResponse viewVoiceCallFlow(final String id) throws NotFoundException, GeneralException, UnauthorizedException {
568+
if (id == null) {
569+
throw new IllegalArgumentException("Call Flow ID must be specified.");
570+
}
571+
String url = String.format("%s%s", VOICE_CALLS_BASE_URL, VOICECALLFLOWPATH);
572+
573+
return messageBirdService.requestByID(url, id, VoiceCallFlowResponse.class);
574+
}
575+
576+
/**
577+
* Convenient function to create a call flow
578+
*
579+
* @param voiceCallFlowRequest VoiceCallFlowRequest
580+
* @return VoiceCallFlowResponse
581+
* @throws UnauthorizedException if client is unauthorized
582+
* @throws GeneralException general exception
583+
*/
584+
public VoiceCallFlowResponse sendVoiceCallFlow(final VoiceCallFlowRequest voiceCallFlowRequest)
585+
throws UnauthorizedException, GeneralException {
586+
String url = String.format("%s%s", VOICE_CALLS_BASE_URL, VOICECALLFLOWPATH);
587+
588+
return messageBirdService.sendPayLoad(url, voiceCallFlowRequest, VoiceCallFlowResponse.class);
589+
}
590+
591+
/**
592+
* Updates an existing Call Flow. You only need to supply the unique id that
593+
* was returned upon creation.
594+
* @param id String
595+
* @param voiceCallFlowRequest VoiceCallFlowRequest
596+
* @return VoiceCallFlowResponse
597+
* @throws UnauthorizedException
598+
* @throws GeneralException
599+
*/
600+
public VoiceCallFlowResponse updateVoiceCallFlow(String id, VoiceCallFlowRequest voiceCallFlowRequest)
601+
throws UnauthorizedException, GeneralException {
602+
if (id == null) {
603+
throw new IllegalArgumentException("Call Flow ID must be specified.");
604+
}
605+
String url = String.format("%s%s", VOICE_CALLS_BASE_URL, VOICECALLFLOWPATH);
606+
String request = url + "/" + id;
607+
608+
return messageBirdService.sendPayLoad("PUT", request, voiceCallFlowRequest, VoiceCallFlowResponse.class);
609+
}
610+
611+
/**
612+
* Convenient function to delete call flow
613+
*
614+
* @param id String
615+
* @return void
616+
* @throws UnauthorizedException if client is unauthorized
617+
* @throws GeneralException general exception
618+
*/
619+
public void deleteVoiceCallFlow(final String id) throws NotFoundException, GeneralException, UnauthorizedException {
620+
if (id == null) {
621+
throw new IllegalArgumentException("Voice Call Flow ID must be specified.");
622+
}
623+
String url = String.format("%s%s", VOICE_CALLS_BASE_URL, VOICECALLFLOWPATH);
624+
messageBirdService.deleteByID(url, id);
625+
}
626+
537627
/**
538628
* Deletes an existing contact. You only need to supply the unique id that
539629
* was returned upon creation.

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public class MessageBirdServiceImpl implements MessageBirdService {
4242
private static final String METHOD_GET = "GET";
4343
private static final String METHOD_PATCH = "PATCH";
4444
private static final String METHOD_POST = "POST";
45+
private static final String METHOD_PUT = "PUT";
4546

46-
private static final List<String> REQUEST_METHODS = Arrays.asList(METHOD_DELETE, METHOD_GET, METHOD_PATCH, METHOD_POST);
47-
private static final List<String> REQUEST_METHODS_WITH_PAYLOAD = Arrays.asList(METHOD_PATCH, METHOD_POST);
47+
private static final List<String> REQUEST_METHODS = Arrays.asList(METHOD_DELETE, METHOD_GET, METHOD_PATCH, METHOD_POST, METHOD_PUT);
48+
private static final List<String> REQUEST_METHODS_WITH_PAYLOAD = Arrays.asList(METHOD_PATCH, METHOD_POST, METHOD_PUT);
4849
private static final String[] PROTOCOL_LISTS = new String[]{"http://", "https://"};
4950
private static final List<String> PROTOCOLS = Arrays.asList(PROTOCOL_LISTS);
5051

@@ -302,6 +303,7 @@ private static String[] getAllowedMethods(String[] existingMethods) {
302303

303304
allowedMethods.addAll(Arrays.asList(existingMethods));
304305
allowedMethods.add(METHOD_PATCH);
306+
allowedMethods.add(METHOD_PUT);
305307

306308
return allowedMethods.toArray(new String[0]);
307309
}

api/src/main/java/com/messagebird/objects/VoiceStepOption.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class VoiceStepOption implements Serializable {
2323
private String ifMachine;
2424
private int machineTimeout;
2525
private String onFinish;
26+
private boolean mask;
2627

2728
public String getDestination() {
2829
return destination;
@@ -160,6 +161,14 @@ public void setOnFinish(String onFinish) {
160161
this.onFinish = onFinish;
161162
}
162163

164+
public boolean isMask() {
165+
return mask;
166+
}
167+
168+
public void setMask(boolean mask) {
169+
this.mask = mask;
170+
}
171+
163172
@Override
164173
public String toString() {
165174
return "VoiceStepOption{" +
@@ -180,6 +189,7 @@ public String toString() {
180189
", ifMachine='" + ifMachine + '\'' +
181190
", machineTimeout=" + machineTimeout +
182191
", onFinish='" + onFinish + '\'' +
192+
", mask='" + mask + '\'' +
183193
'}';
184194
}
185195
}

api/src/main/java/com/messagebird/objects/voicecalls/VoiceCallFlow.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.messagebird.objects.voicecalls;
22

33
import com.messagebird.objects.VoiceStep;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
45

56
import java.io.Serializable;
67
import java.util.Date;
78
import java.util.List;
9+
import java.util.Map;
810

911
public class VoiceCallFlow implements Serializable {
1012

@@ -14,10 +16,19 @@ public class VoiceCallFlow implements Serializable {
1416
private String title;
1517
private boolean record;
1618
private List<VoiceStep> steps;
19+
20+
/*
21+
* default is reserved name in JAVA so we use alternate name
22+
*/
23+
@JsonProperty("default")
1724
private boolean defaultCall;
25+
1826
private Date createdAt;
1927
private Date updatedAt;
2028

29+
@JsonProperty("_links")
30+
private Map<String, String> links;
31+
2132
public String getId() {
2233
return id;
2334
}
@@ -81,7 +92,7 @@ public String toString() {
8192
", title='" + title + '\'' +
8293
", record=" + record +
8394
", steps=" + steps +
84-
", defaultCall=" + defaultCall +
95+
", default=" + defaultCall +
8596
", createdAt=" + createdAt +
8697
", updatedAt=" + updatedAt +
8798
'}';
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.messagebird.objects.voicecalls;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
import java.util.Map;
6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
/**
10+
* Represents a listing of VoiceCallFlow objects, along with pagination details.
11+
* @TODO needs a little polishing (reorganise methods, rename properties, add
12+
* missing properties)
13+
*/
14+
public class VoiceCallFlowList implements Serializable {
15+
16+
private Integer offset;
17+
private Integer limit;
18+
private Integer totalCount;
19+
20+
@JsonProperty("_links")
21+
private Map<String, String> links;
22+
23+
private Pagination pagination;
24+
25+
private List<VoiceCallFlow> items;
26+
27+
@JsonCreator
28+
public VoiceCallFlowList(@JsonProperty("data") List<VoiceCallFlow> data) {
29+
this.items = data;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "ListBase{" +
35+
"offset=" + offset +
36+
", limit=" + limit +
37+
", totalCount=" + totalCount +
38+
", items=" + items +
39+
'}';
40+
}
41+
42+
public void setPagination(Pagination pagination) {
43+
this.pagination = pagination;
44+
}
45+
46+
public Integer getTotalCount() {
47+
return this.pagination.getTotalCount();
48+
}
49+
50+
public Integer getPageCount() {
51+
return this.pagination.getPageCount();
52+
}
53+
54+
public Integer getCurrentPage() {
55+
return this.pagination.getCurrentPage();
56+
}
57+
58+
public Integer getPerPage() {
59+
return this.pagination.getPerPage();
60+
}
61+
62+
63+
public List<VoiceCallFlow> getItems() {
64+
return items;
65+
}
66+
67+
public void setItems(List<VoiceCallFlow> items) {
68+
this.items = items;
69+
}
70+
}
71+
72+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.messagebird.objects.voicecalls;
2+
3+
import java.util.List;
4+
import java.util.Date;
5+
import com.messagebird.objects.*;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
/**
9+
* Contains writable values for VoiceCallFlow objects.
10+
*/
11+
public class VoiceCallFlowRequest {
12+
13+
14+
private String id;
15+
private String title;
16+
private boolean record;
17+
private List<VoiceStep> steps;
18+
19+
@JsonProperty("default")
20+
private boolean defaultCall;
21+
22+
public VoiceCallFlowRequest(String id)
23+
{
24+
this.id = id;
25+
}
26+
27+
public VoiceCallFlowRequest()
28+
{
29+
}
30+
31+
public String getId() {
32+
return id;
33+
}
34+
35+
public void setId(String id) {
36+
this.id = id;
37+
}
38+
39+
public String getTitle() {
40+
return title;
41+
}
42+
43+
public void setTitle(String title) {
44+
this.title = title;
45+
}
46+
47+
public boolean isRecord() {
48+
return record;
49+
}
50+
51+
public void setRecord(boolean record) {
52+
this.record = record;
53+
}
54+
55+
public List<VoiceStep> getSteps() {
56+
return steps;
57+
}
58+
59+
public void setSteps(List<VoiceStep> steps) {
60+
this.steps = steps;
61+
}
62+
63+
public boolean isDefaultCall() {
64+
return defaultCall;
65+
}
66+
67+
public void setDefaultCall(boolean defaultCall) {
68+
this.defaultCall = defaultCall;
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "VoiceCallFlowRequest{" +
74+
"title='" + title + '\'' +
75+
", record=" + record +
76+
", steps=" + steps +
77+
", default=" + defaultCall +
78+
'}';
79+
}
80+
}

0 commit comments

Comments
 (0)