Skip to content

Instantly share code, notes, and snippets.

@jeznag
Created October 25, 2024 03:09
Show Gist options
  • Save jeznag/d365aa146091bf601fe9e19383114297 to your computer and use it in GitHub Desktop.
Save jeznag/d365aa146091bf601fe9e19383114297 to your computer and use it in GitHub Desktop.
autoresponder_via_deluge
// This should be linked to a workflow rule that is triggered by creation of Smooth Message record
// With condition that Message Type starts with "in"
// pass sms_record_id into the function
inbound_message_record = twiliosmsextension0.safely_get_record_by_id_v2({"module_name":"twiliosmsextension0__Sent_SMS","record_id":sms_record_id.toLong()});
inbound_message = inbound_message_record.get("Message").trim();
last_outbound_message_record = twiliosmsextension0.get_last_outbound_message_to_number({
"from": inbound_message_record.get("From"),
"to": inbound_message_record.get("To"),
"default_international_prefix": "+1"
});
info last_outbound_message_record;
last_outbound_message = last_outbound_message_record.get("Message");
contact_id = inbound_message_record.get("ContactName").get("id");
contact_record = twiliosmsextension0.safely_get_record_by_id_v2({"module_name":"Contacts","record_id":contact_id.toLong()});
message_to_send = null;
if (inbound_message == "C" && last_outbound_message.contains("Reply C to cancel")) {
cancel_link = contact_record.get("Cancel_Link");
message_to_send = "Here is your cancellation link: " + cancel_link;
} else if (inbound_message == "R" && last_outbound_message.contains("Reply C to cancel")) {
reschedule_link = contact_record.get("Reschedule_Link");
message_to_send = "Here is your reschedule link: " + reschedule_link;
} else {
info "No reschedule" + inbound_message + "..." + last_outbound_message;
}
if (message_to_send != null) {
new_sms_record_resp = zoho.crm.createRecord("twiliosmsextension0__Sent_SMS",
{
"Name": "Send Cancel or Reschedule link",
"ContactName": contact_id,
"Message": message_to_send,
"To": inbound_message_record.get("From"),
"From": inbound_message_record.get("To")
},
{
"trigger": {"workflow" }
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment