getrecords = zoho.crm.getRecordById("Contacts",contactID);
contactfirst = ifnull(getrecords.get("First_Name"),"");
api_token = "3124|RFo1pgE8Pe29cJzoouqsOXbWnPsXn7VDXtNdsS1S";
param1 = Map();
convoName = ifnull(getrecords.get("Last_Name"),"") + contactID;
param1.put("name",convoName);
response1 = invokeurl
[
url :"https://app.customgpt.ai/api/v1/projects/32012/conversations"
type :POST
parameters:param1
headers:{"accept":"*/*","Authorization":"Bearer " + api_token,"Cache-Control":"no-cache"}
];
session = ifnull(response1.getJSON("data").getJSON("session_id"),"");
lang = {"EN":"English","FR":"French","DE":"Deutsch","NL":"Dutch"};
field_list = List();
if(isNull(getrecords.get("Email")))
{
field_list.add("Email");
}
if(isNull(getrecords.get("Job_Function")))
{
field_list.add("Job Function");
}
if(isNull(getrecords.get("Industry_a")))
{
field_list.add("Industry");
}
if(isNull(getrecords.get("Language")))
{
field_list.add("Language");
}
words_trimer = {"DE":"Sehr","EN":"Dear","NL":"Beste","FR":"Cher"};
if(field_list.size() == 0)
{
lg_val = ifnull(lang.get(getrecords.get("Language")),"");
urlList = list();
if(getrecords.get("Link_Site") != "" && getrecords.get("Link_Site") != null)
{
urlList.add(getrecords.get("Link_Site"));
}
if(getrecords.get("Site_Map_URL2") != "" && getrecords.get("Site_Map_URL2") != null)
{
urlList.add(getrecords.get("Site_Map_URL2"));
}
if(getrecords.get("Site_Map_URL3") != "" && getrecords.get("Site_Map_URL3") != null)
{
urlList.add(getrecords.get("Site_Map_URL3"));
}
str = urlList.toString(",");
prompt_msg = "Draft a compelling business themed email along with the subject line: Explore our premium Ingredients and Enhance your product line - Get in touch with us now(translate) in " + ifnull(lg_val,"English") + " language encompassing a professional tone on behalf of 1-2-Taste Europe for a follow-up to a customer who is browsing products such as " + ifnull(str.removeLastOccurence(","),"") + " related to " + getrecords.get("Industry_a") + " industry, aimed at " + ifnull(getrecords.get("Job_Function"),"") + " persona in " + ifnull(lg_val,"English") + " language. Briefly describe the main utility of the product and provide a short description focusing on benefits and the value proposition. Craft a personalized email that addresses the specific needs or pain points of the target audience. Highlight the products individually with link(including hyperlinks). Inquire if there are any specific (technical or other) questions we can help with. Include a clear call to action(do not use call to action as a part of the sentence) that encourages recipients to take the desired step, such as requesting for a sample purchase or requesting more information(but do not create a hyperlink for CTA) from 1-2-Taste Europe. Ensure the email is engaging, and visually appealing. Insert ?siq_email=" + ifnull(getrecords.get("Email"),"") + " at the end of all URLs but do not show it bare. Start the email(without changing any words) with a greeting: " + words_trimer.get(getrecords.get("Language")) + " " + contactfirst + ", End the email with the below by translating the following in" + ifnull(lg_val,"English") + "language: Call us on +31 6 3452 4720 / +31 6 3462 7970 / +1 67296 50906 or email sales-eu@12taste.com for more information. \n\n Translate the following in" + ifnull(lg_val,"English") + "language: Would it be an inconvenient time to connect with you by phone tomorrow to discuss the needs you have? Let us know! \n\n Translate the following in" + ifnull(lg_val,"English") + "language - Email: " + ifnull(getrecords.get("Owner").get("email"),"") + " Phone: +31 6 3452 4720 / +31 6 3462 7970 WhatsApp: 31850027748. Kind regards," + ifnull(getrecords.get("Owner").get("name"),"") + "";
api_token = "3124|RFo1pgE8Pe29cJzoouqsOXbWnPsXn7VDXtNdsS1S";
param = Map();
param.put("response_source","default");
param.put("prompt",prompt_msg);
try
{
response = invokeurl
[
url :"https://app.customgpt.ai/api/v1/projects/32012/conversations/" + session + "/messages"
type :POST
parameters:param
headers:{"accept":"*/*","Authorization":"Bearer " + api_token,"Cache-Control":"no-cache"}
];
info response;
sub = ifnull(response.getJSON("data").get("openai_response"),"");
info sub;
info "words_trimer :" + words_trimer.get(getrecords.get("Language"));
final_sub = ifnull(sub.getprefix(words_trimer.get(getrecords.get("Language"))),"");
sub_b = ifnull(sub.getsuffix(words_trimer.get(getrecords.get("Language"))),"");
Subject_txt = final_sub.remove("Subject:");
Body_txt = words_trimer.get(getrecords.get("Language")) + sub_b.remove("**");
mp = Map();
mp.put("Subject",Subject_txt);
//mp.put("Promt_Message",prompt_msg);
mp.put("Body1",Body_txt);
up = zoho.crm.updateRecord("Contacts",contactID,mp);
upid = up.getJSON("id");
res = zoho.crm.getRecordById("Contacts",upid.toLong());
if(Subject_txt != "" && Subject_txt != null && Body_txt != "" && Body_txt != null)
{
sendmail
[
from :zoho.loginuserid
to :"teste12-test@yopmail.com"
subject :"GPT Payload"
message :mp
]
template_data = {"id":3568812000414892061};
//email_payload = {"data":{{"from":{"user_name":"sales","email":"sales-eu@12taste.com"},"to":{{"email":"teste12-test@yopmail.com"}},"bcc":{{"email":"arunava.basak@yopmail.com"}},"org_email":true,"mail_format":"html","template":template_data}}};
//email_payload = {"data":{{"from":{"user_name":"sales","email":"sales-eu@12taste.com"},"to":{{"email":contact_email}},"bcc":{{"email":"arjan.koudijs@12taste.com"},{"email":"vigneshvar.priyan@12taste.com"}},"org_email":true,"mail_format":"html","template":template_data}}};
//send_mail_resp = invokeurl
//[
// url :"https://www.zohoapis.com/crm/v3/Contacts/" + contactID + "/actions/send_mail"
// type :POST
// parameters:email_payload.toString()
// connection:"crm_email"
// ];
//info send_mail_resp;
dateMap = Map();
dateMap.put("Visitor_Mail_Sent_Date",zoho.currentdate);
up = zoho.crm.updateRecord("Contacts",contactID,dateMap);
}
}
catch (e)
{
info e;
}
info "Email subject and body are prepared, Now you can send an email";
}
else
{
info "Following fields are mandatory, please recheck and fill them with proper values:" + field_list;
}