Advertisement
patrickjust3k

Parsing showing time emails

Jan 2nd, 2023 (edited)
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. void parse_showingtime_data(int message_id)
  2. {
  3. //decode mail body
  4. message_details = zoho.mail.getMessage(message_id,"zoho_flow_to_mail");
  5. //info message_details;
  6. mail_subject = message_details.get("SUBJECT");
  7. if(!mail_subject.isNull() && mail_subject.containsIgnoreCase("YOUR"))
  8. {
  9. showing_type = "buyer";
  10. }
  11. else
  12. {
  13. info "mail subject:" + mail_subject;
  14. HTML_text = message_details.get("CONTENT");
  15. if(input.HTML_text != "")
  16. {
  17. Output = HTML_text.replaceAll("  ","");
  18. Output = Output.replaceAll(" ","");
  19. Output = Output.replaceAll("<li","");
  20. Output = Output.replaceAll("<br>","");
  21. Output = Output.replaceAll("</p>","");
  22. Output = Output.replaceAll("<(.|\n)*?>","");
  23. Output = Output.replaceAll("\r\n","");
  24. Output = Output.replaceAll("\n","");
  25. Output = Output.replaceAll("\t","");
  26. Output = Output.getSuffix("Showing Confirmed");
  27. mail_body = Output.getPrefix("div.zm");
  28. //info mail_body;
  29. }
  30. // find MLS ID
  31. MLS_ID = mail_body.getSuffix("ID# ");
  32. MLS_ID = MLS_ID.substring(0,7);
  33. info "MLS #: " + MLS_ID;
  34. //find crm record associated with that MLS number
  35. query = "(MLS_Num:equals:" + MLS_ID + ")";
  36. deal_search = zoho.crm.searchRecords("Deals",query);
  37. number_of_deals = deal_search.size();
  38. info "matching # of deals: " + number_of_deals;
  39. //find the id of deal record if there is one matching
  40. for each deal in deal_search
  41. {
  42. deal_id = deal_search.getJSON("id");
  43. info "deal_id: " + deal_id;
  44. }
  45. //enter Patrick for deal owner if no deal id
  46. deal_owner_id = "4933226000000350001";
  47. //else search for deal owner id and use for inquiry owner
  48. if(!deal_id.isNull())
  49. {
  50. deal_details = zoho.crm.getRecordById("Deals",deal_id);
  51. deal_owner_name = deal_details.getJSON("Owner").get("name");
  52. deal_owner_id = deal_details.getJSON("Owner").get("id");
  53. info "deal owner id: " + deal_owner_id;
  54. }
  55. //find date
  56. date = mail_body.getSuffixIgnoreCase("Appointment Details");
  57. date = date.getSuffixIgnoreCase("Showing");
  58. date = date.getPrefixIgnoreCase("-");
  59. date = date.toString();
  60. date = date.getSuffixIgnoreCase(",");
  61. //convert date to correct format
  62. date = replaceAll(date,"January","01,");
  63. date = replaceAll(date,"Februaru","02,");
  64. date = replaceAll(date,"March","03,");
  65. date = replaceAll(date,"April","04,");
  66. date = replaceAll(date,"May","05,");
  67. date = replaceAll(date,"June","06,");
  68. date = replaceAll(date,"July","07,");
  69. date = replaceAll(date,"August","08,");
  70. date = replaceAll(date,"September","09,");
  71. date = replaceAll(date,"October","10,");
  72. date = replaceAll(date,"November","11,");
  73. date = replaceAll(date,"December","12,");
  74. date = replaceAll(date,"PM","");
  75. date = replaceAll(date,"AM","");
  76. date = date.subString(0,14);
  77. showing_date = toDate(date,"MM,dd,yyyy");
  78. info "converted date : " + showing_date;
  79. //get buyer agent info
  80. buyer_agent_section = mail_body.getSuffix("Buyer's Agent Details");
  81. buyer_agent_section = buyer_agent_section.trim();
  82. buyer_agent_name = buyer_agent_section.subString(0,24);
  83. buyer_agent_name = buyer_agent_name.trim();
  84. info "buyer agent name: " + buyer_agent_name;
  85. //get buyer agent phone
  86. buyer_agent_phone = buyer_agent_section.getSuffix("(");
  87. buyer_agent_phone = buyer_agent_phone.removeFirstOccurence(")");
  88. buyer_agent_phone = buyer_agent_phone.replaceAllIgnoreCase(" ","-");
  89. buyer_agent_phone = buyer_agent_phone.subString(0,12);
  90. info "buyer agent phone: " + buyer_agent_phone;
  91. //get buyer agent email
  92. buyer_agent_email = buyer_agent_section.getSuffixIgnoreCase("(Office Main Line)");
  93. buyer_agent_email = buyer_agent_email.trim();
  94. info "buyer agent email: " + buyer_agent_email;
  95. //build map and create inquiry
  96. inquiry_map = Map();
  97. inquiry_map.put("Name",buyer_agent_name);
  98. inquiry_map.put("Date_1",showing_date);
  99. inquiry_map.put("Inquired_on",{"id":deal_id});
  100. inquiry_map.put("Source","ShowingTime");
  101. inquiry_map.put("Owner",{"id":deal_owner_id});
  102. inquiry_map.put("Status","Showed");
  103. inquiry_map.put("Phone_1",buyer_agent_phone);
  104. inquiry_map.put("Email",buyer_agent_email);
  105. create_inquiry = zoho.crm.createRecord("Inquiry",inquiry_map);
  106. info create_inquiry;
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement