Skip to content

Instantly share code, notes, and snippets.

@jeznag
Created September 17, 2024 01:25
Show Gist options
  • Save jeznag/6d4ad4a7aa066f50adc3c1ab7c7b1bc6 to your computer and use it in GitHub Desktop.
Save jeznag/6d4ad4a7aa066f50adc3c1ab7c7b1bc6 to your computer and use it in GitHub Desktop.
Sending meeting reminder SMS
meeting_record = zoho.crm.getRecordById("Events", meeting_id);
appointment_time = meeting_record.get("Start_DateTime");
// refer to https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for list of timezones
timezone = "America/New_York";
info appointment_time;
// feel free to tweak the format
// example output is "03:00 PM Eastern Time on Sep 05"
// refer to https://www.zoho.com/deluge/help/functions/common/totime.html for symbols
DATE_TIME_FORMAT = "hh:mm a 'Eastern Time on' MMM dd";
appointment_time_in_correct_timezone = appointment_time.toDateTime("yyyy-MM-dd'T'HH:mm:ss").toString(DATE_TIME_FORMAT, timezone);
invitee_name = "";
if (meeting_record.get("Participants") != null && meeting_record.get("Participants").size() > 0) {
invitee_name = meeting_record.get("Participants").get(0).get("name");
} else if (meeting_record.get("Who_Id") != null) {
invitee_name = meeting_record.get("Who_Id").get("name");
} else if (meeting_record.get("What_Id") != null) {
invitee_name = meeting_record.get("What_Id").get("name");
}
message_name = "Appointment reminder SMS for " + meeting_record.get("Event_Title");
info meeting_record;
message_to_send = "Hi " + invitee_name + ", reminder that your meeting " + meeting_record.get("Event_Title") + " starts in 2hrs at " + appointment_time_in_correct_timezone + ". Cheers, " + meeting_record.get("Owner").get("name");
new_sms_record_resp = zoho.crm.createRecord("twiliosmsextension0__Sent_SMS",
{
"Name": message_name,
"twiliosmsextension0__Activity_ID": meeting_id.toString(),
"twiliosmsextension0__Activity_Type": "Meeting",
"Message": message_to_send
},
{
"trigger": {"workflow" }
}
);
@quangkhuat1995
Copy link

We also need to know the To number of the Who_Id or What_Id. Seems like Zoho doesn't support those nested merge fields so we need to update the code to get them:

if (meeting_record.get("Who_Id") != null) {
record_id = meeting_record.get("Who_Id").get("id");
} else if (meeting_record.get("What_Id") != null) {
record_id = meeting_record.get("What_Id").get("id");
}

module_name = meeting_record.get("$se_module");
record_data = zoho.crm.getRecordById(module_name, record_id);

record_phone = record_data.get("Phone");

new_sms_record_resp = zoho.crm.createRecord("twiliosmsextension0__Sent_SMS",
{
"Name": message_name,
"twiliosmsextension0__Activity_ID": meeting_id.toString(),
"twiliosmsextension0__Activity_Type": "Events", // Events, not Meetings
"From": "+61", // hard code?
"To": record_phone,
"Message": message_to_send
},
{
"trigger": {"workflow" }
}
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment