Custom Function - Searching Keywords in Latest Email Reply from Customer

Custom Function - Searching Keywords in Latest Email Reply from Customer

Hi All,

I got provided from ZoHo Support the below sample custom function to use for ZoHo Desk.

This function is supposed to search for specific keywords within a customer's most recent email reply to a ZoHo Desk ticket and then send out an email alert (if it finds those keywords).

code shown below:

orgId = XXXXXX; // replace orgId
//add the required keywords 
keywordsList = {"Complaint","Issue","Problem","Faulty","Defect","Expensive","Overpriced","Unresponsive","Poor service","Outdated","Complicated","Difficult","Unreliable","Inconsistent","Disappointed","Never","Not again","Refund","Contract","Switch","Switching","Move","Moving on","Better options","Latency","Outage","Unstable","Difficult setup","Hard to use","Poor integration","Incompatible","Overpriced","Limited features","Poor support","Slow response","Better options","Switching providers","Cancel","Termination","Expensive upgrades","Outdated software","No improvement","Unreliable","Connectivity issues","Refund","Disconnect","Lack of customization"};
//===================================================================
logs = Collection();
doesThreadContainRequiredKeywords = false;
latestThreadData = invokeurl
[
url :deskURL + "/api/v1/tickets/" + ticketId + "/latestThread"
type :GET
connection:"zohosupport"
];
logs.insert("latestThreadData":latestThreadData);
threadContent = latestThreadData.get("content");
for each  currKeyword in keywordsList
{
if(threadContent.containsIgnoreCase(currKeyword))
{
doesThreadContainRequiredKeywords = true;
break;
}
}
logs.insert("doesThreadContainRequiredKeywords":doesThreadContainRequiredKeywords);
if(doesThreadContainRequiredKeywords == true)
{
templateId = "3337XXXXXXXX"; // replace templateId
Template = invokeurl
[
url :"https://support.zoho.com/api/v1/templates/" + templateId + "/render?entityId=" + ticketId
type :POST
connection:"zohosupport"
];
sendmail
[
from :zoho.adminuserid
subject :Template.getJSON("subject")
message :Template.getJSON("body")
]
}
info "Logs:" + logs;


I setup the above custom function and enabled it for a workflow

I set it to execute on:

create & customer reply




However, I started getting email alerts if a keyword was used in an earlier email reply to the ticket.

e.g.

ticket #12345

A customer's most recent reply (2/21/2024) to ticket #12345 would not have any of the keywords listed in keywordsList. But I still got an email alert.

But when I looked at previous customer emails to that same ticket, I did see that keyword in a previous email the customer sent (2/10/2024).



Looking at the code it seems like the logic is to search the entire thread, rather than the most recent one. Wondering if it can be modified to search for the most recent thread (aka customer reply).


Best,
Chris

      • Sticky Posts

      • Live Webinar - Work smarter with Zoho Desk and Zoho Workplace integration

        Hello customers! Zoho Desk and Zoho Workplace are coming together for a webinar on 14th May, 2024. Zoho Workplace is a suite of productivity apps for email, chat, docs, calls, and more at one single place. Zoho Desk is closely integrated with a few tools
      • Apple iOS 17 and iPadOS 17 updates for Zoho Desk users

        Hello Zoho Desk users! Apple recently announced the release of iOS 17 and iPad OS 17. These latest OS updates will help you stay productive and efficient, through interactive and seamless user experiences. Zoho Desk has incorporated the updates to help
      • Zoho Desk Partners with Microsoft's M365 Copilot for seamless customer service experiences

        Hello Zoho Desk users, We are happy to announce that Zoho Desk has partnered with Microsoft's M365 to empower customer service teams with enhanced capabilities and seamless experiences for agents. Microsoft announced their partnership during their keynote
      • Zoho Desk Cheat Sheet For The Year-End

        Check out these Zoho Desk best practices to end this year on a high and have a great one ahead! #1 Set Business (Holiday) Hours - If you have limited working hours, please make sure you restrict your business hours or set them as holidays for the coming days. Let your customers know when you will, and won't, be available. #2 Update the Annual Holiday List - Check the holidays for the new year and update the holiday schedule. Usually, holidays from the current year will be carried over for the next
      • Deprecation of older versions of ASAP Mobile SDK | Zoho Desk

        Hello, everyone.    Greetings from Zoho Desk ASAP!   In order to continue to deliver the best and most secure experience to our mobile SDK users. On account of the recent enhancements and updates to the mobile SDKs, we have planned to mark the older versions