Skip to content

Commit

Permalink
Code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VSydor committed Dec 13, 2022
1 parent 11fa2b6 commit ddddff8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public Response proxyVoice(
@Path("/webhook/message/onMessageAdded") // TODO: replace with the correct url
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_XML) //TODO: define what type to return
@Produces(MediaType.APPLICATION_JSON)
public Response onMessageAddedWebhook(
@FormParam("EventType") String eventType,
@FormParam("ConversationSid") String conversationSid,
Expand All @@ -336,7 +336,7 @@ public Response onMessageAddedWebhook(
addMessage(crmTask, messageSid);
upsertCrmTask(env, crmTask);

return Response.ok().build(); // TODO: what to return?
return Response.ok().build();
}

private CrmTask getOrCreateCrmTask(Environment env, String conversationId) throws Exception {
Expand All @@ -355,6 +355,7 @@ private CrmTask getOrCreateCrmTask(Environment env, String conversationId) throw
crmTask = new CrmTask();
crmTask.subject = subject;
crmTask.assignTo = assignTo;
crmTask.type = CrmTask.Type.CALL;
crmTask.status = CrmTask.Status.TO_DO;
crmTask.priority = CrmTask.Priority.MEDIUM;
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/impactupgrade/nucleus/model/CrmTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class CrmTask {
public String assignTo; // User ID
public String subject;
public String description;
public Type type;
public Status status;
public Priority priority;
public Calendar dueDate;
Expand All @@ -17,16 +18,25 @@ public CrmTask() {
}

public CrmTask(String targetId, String assignTo, String subject, String description,
Status status, Priority priority, Calendar dueDate) {
Type type, Status status, Priority priority, Calendar dueDate) {
this.targetId = targetId;
this.assignTo = assignTo;
this.subject = subject;
this.description = description;
this.type = type;
this.status = status;
this.priority = priority;
this.dueDate = dueDate;
}

public enum Type {
TASK,
EMAIL,
LIST_EMAIL,
CADENCE,
CALL
}

public enum Status {
TO_DO,
IN_PROGRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void createCrmTask(String subject, String body, String targetId, Envir
crmService.insertTask(new CrmTask(
targetId, assignTo,
subject, body,
CrmTask.Status.TO_DO, CrmTask.Priority.MEDIUM, dueDate
CrmTask.Type.TASK, CrmTask.Status.TO_DO, CrmTask.Priority.MEDIUM, dueDate
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,24 @@ protected CrmTask toCrmTask(SObject sObject) {
sObject.getField("Description").toString(),
null,
null,
null,
null);

switch (sObject.getField("Status").toString()) {
switch (sObject.getField("TaskSubType") + "") {
case "Task" -> crmTask.type = CrmTask.Type.TASK;
case "Email" -> crmTask.type = CrmTask.Type.EMAIL;
case "List Email" -> crmTask.type = CrmTask.Type.LIST_EMAIL;
case "Cadence" -> crmTask.type = CrmTask.Type.CADENCE;
default -> crmTask.type = CrmTask.Type.CALL;
}

switch (sObject.getField("Status") + "") {
case "In Progress" -> crmTask.status = CrmTask.Status.IN_PROGRESS;
case "Completed" -> crmTask.status = CrmTask.Status.DONE;
default -> crmTask.status = CrmTask.Status.TO_DO;
}

switch (sObject.getField("Priority").toString()) {
switch (sObject.getField("Priority") + "") {
case "Low" -> crmTask.priority = CrmTask.Priority.LOW;
case "High" -> crmTask.priority = CrmTask.Priority.HIGH;
default -> crmTask.priority = CrmTask.Priority.MEDIUM;
Expand Down Expand Up @@ -296,14 +305,22 @@ public EnvironmentConfig.CRMFieldDefinitions getFieldDefinitions() {
}

protected void setTaskFields(SObject task, CrmTask crmTask) {
if (crmTask != null) {
if (crmTask.id != null) {
task.setField("Id", crmTask.id);
}
task.setField("WhoId", crmTask.targetId);
task.setField("OwnerId", crmTask.assignTo);
task.setField("Subject", crmTask.subject);
task.setField("Description", crmTask.description);

switch (crmTask.type) {
case TASK -> task.setField("TaskSubType", "Task");
case EMAIL -> task.setField("TaskSubType", "Email");
case LIST_EMAIL -> task.setField("TaskSubType", "List Email");
case CADENCE -> task.setField("TaskSubType", "Cadence");
default -> task.setField("TaskSubType", "Call");
}

switch (crmTask.status) {
case IN_PROGRESS -> task.setField("Status", "In Progress");
case DONE -> task.setField("Status", "Completed");
Expand Down

0 comments on commit ddddff8

Please sign in to comment.