Skip to content

Commit

Permalink
tags in xmessage
Browse files Browse the repository at this point in the history
  • Loading branch information
surabhi-mahawar committed Aug 30, 2022
1 parent 71f143a commit 1789808
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 106 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/uci/inbound/incoming/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Campaign {
@RequestMapping(value = "/start", method = RequestMethod.GET)
public void startCampaign(@RequestParam("campaignId") String campaignId) throws JsonProcessingException, JAXBException {
botService.getBotNodeFromId(campaignId).subscribe(data -> {
SenderReceiverInfo from = new SenderReceiverInfo().builder().userID("7597185708").deviceType(DeviceType.PHONE).build();
SenderReceiverInfo from = new SenderReceiverInfo().builder().userID("9876543210").deviceType(DeviceType.PHONE).build();
SenderReceiverInfo to = new SenderReceiverInfo().builder().userID("admin").build();
MessageId msgId = new MessageId().builder().channelMessageId(UUID.randomUUID().toString()).replyId("7597185708").build();
XMessagePayload payload = new XMessagePayload().builder().text(BotUtil.getBotNodeData(data, "startingMessage")).build();
Expand Down Expand Up @@ -82,6 +82,7 @@ public void startCampaign(@RequestParam("campaignId") String campaignId) throws
.providerURI(adapter.path("provider").asText())
.channelURI(adapter.path("channel").asText())
.timestamp(timestamp.getTime())
.tags(BotUtil.getBotNodeTags(data))
.build();

XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/com/uci/inbound/utils/XMsgProcessingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void process() throws JsonProcessingException {
log.info("Process bot message");
processBotMessage(xmsg, result.get("appName").toString(),
result.get("sessionId"), result.get("ownerOrgId"),
result.get("ownerId"), result.get("adapterId"), result.get("botUuid"));
result.get("ownerId"), result.get("adapterId"), result.get("botUuid"),
result.get("tags"));
} else {
/* Bot is not valid */
/**
Expand All @@ -99,7 +100,8 @@ public void process() throws JsonProcessingException {
log.info("Process bot message after validation.");
processBotMessage(xmsg, res.get("appName").toString(),
res.get("sessionId"), res.get("ownerOrgId"),
res.get("ownerId"), res.get("adapterId"), res.get("botUuid"));
res.get("ownerId"), res.get("adapterId"), res.get("botUuid"),
res.get("tags"));
} else {
log.info("Bot is invalid after validation");
processInvalidBotMessage(xmsg, (ObjectNode) res.get("botNode"), res.get("errorMsg").toString());
Expand Down Expand Up @@ -135,6 +137,7 @@ public void process() throws JsonProcessingException {
xmsg.setOwnerOrgId(xMessageLast.getOwnerOrgId());
xmsg.setOwnerId(xMessageLast.getOwnerId());
xmsg.setBotId(xMessageLast.getBotUuid());
xmsg.setTags(xMessageLast.getTags());
XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
xMsgRepo.insert(currentMessageToBeInserted)
.doOnError(genericError("Error in inserting current message"))
Expand Down Expand Up @@ -177,6 +180,7 @@ private void processInvalidBotMessage(XMessage xmsg, ObjectNode botNode, String
xmsg.setOwnerOrgId(BotUtil.getBotNodeData(botNode, "ownerOrgID"));
xmsg.setSessionId(BotUtil.newConversationSessionId());
xmsg.setAdapterId(BotUtil.getBotNodeAdapterId(botNode));
xmsg.setTags(BotUtil.getBotNodeTags(botNode));
}

XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
Expand All @@ -202,7 +206,9 @@ private void processInvalidBotMessage(XMessage xmsg, ObjectNode botNode, String
* @param xmsg
* @param appName
*/
private void processBotMessage(XMessage xmsg, String appName, Object sessionId, Object ownerOrgId, Object ownerId, Object adapterId, Object botUuid) {
private void processBotMessage(XMessage xmsg, String appName, Object sessionId, Object ownerOrgId,
Object ownerId, Object adapterId, Object botUuid,
Object tags) {
xmsg.setApp(appName);
if(sessionId != null && !sessionId.toString().isEmpty()) {
xmsg.setSessionId(UUID.fromString(sessionId.toString()));
Expand All @@ -219,6 +225,13 @@ private void processBotMessage(XMessage xmsg, String appName, Object sessionId,
if(botUuid != null && !botUuid.toString().isEmpty()) {
xmsg.setBotId(UUID.fromString(botUuid.toString()));
}
if(tags != null) {
try{
xmsg.setTags((List<String>) tags);
} catch(Exception ex) {
log.error("Exception in processBotMessage while converting tags: "+ex.getMessage());
}
}
XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
if (isCurrentMessageNotAReply(xmsg)) {
String whatsappId = xmsg.getMessageId().getChannelMessageId();
Expand Down Expand Up @@ -282,6 +295,7 @@ public Mono<Map<String, Object>> apply(JsonNode botNode) {
dataMap.put("ownerId", BotUtil.getBotNodeData(botNode, "ownerID"));
dataMap.put("adapterId", BotUtil.getBotNodeAdapterId(botNode));
dataMap.put("botUuid", BotUtil.getBotNodeData(botNode, "id"));
dataMap.put("tags", BotUtil.getBotNodeTags(botNode));
return Mono.just(dataMap);
}
} else {
Expand Down Expand Up @@ -545,6 +559,7 @@ private Map<String, Object> createExistingConversationData(XMessageDAO xMessageL
dataMap.put("ownerOrgId", getXMessageOwnerOrgId(xMessageLast));
dataMap.put("ownerId", getXMessageOwnerId(xMessageLast));
dataMap.put("botUuid", getXMessageBotUuid(xMessageLast));
dataMap.put("tags", getXMessageTags(xMessageLast));

return dataMap;
}
Expand All @@ -565,7 +580,8 @@ private Map<String, Object> createNewConversationData(JsonNode botNode) {
dataMap.put("ownerId", BotUtil.getBotNodeData(botNode,"ownerID"));
dataMap.put("adapterId", BotUtil.getBotNodeAdapterId(botNode));
dataMap.put("botUuid", BotUtil.getBotNodeData(botNode,"id"));
return dataMap;
dataMap.put("tags", BotUtil.getBotNodeTags(botNode));
return dataMap;
}

/**
Expand Down Expand Up @@ -612,4 +628,13 @@ private String getXMessageOwnerId(XMessageDAO xMessageDAO) {
private String getXMessageOwnerOrgId(XMessageDAO xMessageDAO) {
return xMessageDAO.getOwnerOrgId() != null ? xMessageDAO.getOwnerOrgId() : "";
}

/**
* Get Owner UUID as string from XMessage Dao
* @param xMessageDAO
* @return
*/
private List<String> getXMessageTags(XMessageDAO xMessageDAO) {
return xMessageDAO.getTags() != null ? xMessageDAO.getTags() : null;
}
}
Loading

0 comments on commit 1789808

Please sign in to comment.