أتمتة رسائل WhatsApp باستخدام دالة في Zoho CRM

"أتمتة رسائل WhatsApp باستخدام دالة في قاعدة سير العمل

Warning
قبل البدء في البرمجة، نوصي باستخدام الطريقة التالية:  https://support.woztell.com/portal/en/kb/articles/whatsapp-workflows-inside-zoho-crm


في Zoho CRM يمكننا إنشاء وظائف لتنفيذ API. بالإضافة إلى ذلك، يمكن استخدام هذه الوظائف مع قواعد سير العمل لأتمتة الإجراءات. في هذه المقالة، سنرى كيف يمكننا استخدام وظائف Zoho CRM و API الخاص بـ WOZTELL لإرسال رسائل WhatsApp. للقيام بذلك، نحن نقوم بـ:
  1. إنشاء رمز وصول
  2. بناء الوظيفة

إنشاء رمز وصول

تحتاج API الخاصة بـ WOZTELL إلى رمز وصول للتحقق من هوية المستخدم. لذلك، قبل البدء في استخدام API الخاصة بنا يجب علينا إنشاء رمز وصول. للقيام بذلك، يمكننا استخدام الوثائق الخاصة بالمنصة لإنشاء الرمز.

تنبيه
تذكر أن API الخاصة بإرسال الرسائل تستخدم النطاقات: bot:sendResponses, bot:admin

انقر هنا للانتقال مباشرة إلى المقالة لإنشاء الرموز.

بناء الوظيفة

في Zoho CRM، يمكننا إنشاء وظائف لقاعدة سير العمل الخاصة بنا من خلال اتباع هذه الخطوات:

1. تسجيل الدخول إلى حسابك في Zoho CRM

2. انتقل إلى الإعدادات


3. في قسم الأتمتة، انقر على قواعد سير العمل (Workflow Rules)



4. قم بإنشاء قاعدة سير العمل جديدة من خلال النقر على زر + إنشاء قاعدة :


5. اختر الوحدة التي سيتم ربط القاعدة بها، اكتب اسم القاعدة ووصفها:


6. بمجرد تحديد شروط القاعدة، يمكنك اختيار الإجراء الذي تريد أن يتم تفعيله:


بمجرد أن تقوم بإنشاء الوظيفة، ستتمكن من إضافة الشيفرة التالية:
ملاحظات
// Standard parameters
token = "your-WOZTELL-token";
phone = "your-destination-phone";
channelId = "your-WOZTELL-channel-id";
templateName = "your-whatsapp-template-name";
templateLanguage = "your-whatsapp-language-code";

if(phone.startsWith("00")){
      phone = phone.removeFirstOccurence("00");
}else if(phone.startsWith("+")){
      phone = phone.removeFirstOccurence("+");
}

// Function tag is used in the Zoho CRM logs and Zoho Cliq integration
// It is saved in the Woztell Logs Module and Zoho Cliq message
function_tag = "your-function-tag";

// You can decide if you want to post the message in Zoho Cliq or not.
// Set true to publish or false to not publish it
// post_in_zoho_cliq = true;
// or
// post_in_zoho_cliq = false;
post_in_zoho_cliq = false;

// Body template parameters
// Don't remove bodyParameterList = List();
bodyParameterList = List();
// Comment this code if the template doesn't have parameters
bodyParameter1 = Map();
bodyParameter1.put("type","text");
bodyParameter1.put("text","parameter-1-value");
bodyParameterList.add(bodyParameter1);

// DON'T MODIFY THE FOLLOWING CODE !!
postMessage = Map();
postMessage.put("channelId",channelId);
postMessage.put("recipientId",phone);
responseMap = Map();
responseMap.put("type","TEMPLATE");
responseMap.put("elementName",templateName);
responseMap.put("languageCode",templateLanguage);
componentsList = list();

if(!bodyParameterList.isEmpty())
{
      bodyComponent = Map();
      bodyComponent.put("type","body");
      bodyComponent.put("parameters",bodyParameterList);
      componentsList.add(bodyComponent);
}

responseMap.put("components",componentsList);
responseList = List();
responseList.add(responseMap);
postMessage.put("response",responseList);
message_meta = Map();
message_meta_zoho = Map();
message_meta_zoho.put("user",function_tag);
message_meta_zoho.put("cliq",post_in_zoho_cliq);
// module: Leads or Contacts
message_meta_zoho.put("record",{"id":"XXXXX".toString(),"name": "XXXX","module":"Leads"});
message_meta.put("zoho",message_meta_zoho);
postMessage.put("meta",message_meta);

response = invokeurl
[
      url :PostURL
      type :POST
      parameters:postMessage.toString()
];

info response;

هذا الكود يتيح لك تعديله بحيث يمكنك أتمتة الإرسال. الآن نشرح الأجزاء التي يمكن تعديلها:

  1. token = "your-WOZTELL-token";
      كما هو موضح في أعلى هذه المقالة، يجب عليك إنشاء الرمز من منصة Woztell.

  1. بالنسبة إلى متغير phone ، يمكنك حذفه وإضافة معلمة كما هو موضح هنا:


لإضافة المعلمة بحيث يمكن أن يكون لها قيمة ديناميكية بناءً على كل عميل، يمكننا استخدام # واختيار الوحدة التي نريدها (على سبيل المثال، #Leads أو #Contacts). بمجرد اختيار الوحدة ذات الصلة، يمكننا اختيار الحقل الذي سنربطه. في هذه الحالة، نحن نستخدم حقل Phone من وحدة Leads.



  1. بالنسبة إلى متغير channelId ، يمكننا الحصول عليه من خلال اتباع الخطوات في هذه المقالة. لاحظ أن كل رقم هاتف WhatsApp مفعل في قناة على منصة Woztell سيكون له channelId مختلف.

  1. المتغيرات templateName و templateLanguage تشير إلى اسم القالب الذي نريد إرساله واللغة الخاصة به، حيث يمكن إنشاء كل قالب بلغات مختلفة. يمكن الحصول على هذه المعلومات من منصة Woztell، في قسم القنوات عن طريق النقر على زر Edit والانتقال إلى Platform.
 
  1. المتغير function_tag يُستخدم لكي تتمكن من تحديد من الذي أرسل الرسالة. على سبيل المثال، يمكنك كتابة اسم القاعدة حتى تعرف أي قاعدة تفعّل الرسالة. سيزودنا هذا بمعلومات يمكننا التحقق منها من خلال Zoho Cliq وأيضًا من خلال وحدة "سجلات Woztell" في Zoho CRM.
  2. المتغير post_in_zoho_cliq يُستخدم لتحديد ما إذا كنت ترغب في نشر الرسالة في Zoho Cliq أم لا. إذا كنت تريد أن يتم نشر الرسالة في Zoho Cliq، يمكنك تحديده كـ true. خلاف ذلك، حدد false.
تذكر أنه إذا كان القالب لا يحتوي على معلمات، يجب عليك تعليق الأسطر التالية بإضافة //
ملاحظات
bodyParameter1 = Map();
bodyParameter1.put("type","text");
bodyParameter1.put("text","parameter-1-value");
bodyParameterList.add(bodyParameter1);

من ناحية أخرى، إذا كان القالب يحتوي على أكثر من معلمة واحدة، يجب عليك تكرار هذا الجزء بقدر المعلمات التي لديك. 
ملاحظات
bodyParameter1 = Map();
bodyParameter1.put("type","text");
bodyParameter1.put("text","parameter-1-value");
bodyParameterList.add(bodyParameter1);

bodyParameter2 = Map();
bodyParameter2.put("type","text");
bodyParameter2.put("text","parameter-2-value");
bodyParameterList.add(bodyParameter2);
...

بمجرد تكوين جميع المتغيرات، يجب عليك عدم تعديل باقي الكود.

نحن نقدم لك مثالًا عن الكود باستخدام قالب WhatsApp مع مستند في الرأس ومعلمة في الجسم:
Info

// Standard parameters
token = "your-WOZTELL-token";
phone = "your-destination-phone";
channelId = "your-WOZTELL-channel-id";
templateName = "template-name";
templateLanguage = "template-language";

if(phone.startsWith("00")){
      phone = phone.removeFirstOccurence("00");
}else if(phone.startsWith("+")){
      phone = phone.removeFirstOccurence("+");
}

// Function tag is used in the Zoho CRM logs and Zoho Cliq integration
// It is saved in the Woztell Logs Module and Zoho Cliq message
function_tag = "automated message sample";

// You can decide if you want to post the message in Zoho Cliq or not.
// Put true to publish or false to not publish
// post_in_zoho_cliq = true;
// or
// post_in_zoho_cliq = false;
post_in_zoho_cliq = true;
//
// Header file
// Don't remove headerParameterList = List();
headerParameterList = List();
// If the template has a file (document, image, video) in the header
// Comment this code if the template doesn't have header or header is text
headerParameter1 = Map();
headerParameter1.put("type","document");
headerParameter1.put("document", {"link":"url of the file"});
headerParameterList.add(headerParameter1);
//
// Body template parameters
// Don't remove bodyParameterList = List();
bodyParameterList = List();
// Comment this code if the template doesn't have parameters
bodyParameter1 = Map();
bodyParameter1.put("type","text");
bodyParameter1.put("text","test Woztell");
bodyParameterList.add(bodyParameter1);

//
//
//
// DON'T MODIFY THE FOLLOWING CODE !!
postMessage = Map();
postMessage.put("channelId",channelId);
postMessage.put("recipientId",phone);
responseMap = Map();
responseMap.put("type","TEMPLATE");
responseMap.put("elementName",templateName);
responseMap.put("languageCode",templateLanguage);
componentsList = list();

if(!headerParameterList.isEmpty())
{
headerComponent = Map();
headerComponent.put("type","header");
headerComponent.put("parameters",headerParameterList);
componentsList.add(headerComponent);
}

if(!bodyParameterList.isEmpty())
{
bodyComponent = Map();
bodyComponent.put("type","body");
bodyComponent.put("parameters",bodyParameterList);
componentsList.add(bodyComponent);
}

responseMap.put("components",componentsList);
responseList = List();
responseList.add(responseMap);
postMessage.put("response",responseList);
message_meta = Map();
message_meta_zoho = Map();
message_meta_zoho.put("user",function_tag);
message_meta_zoho.put("cliq",post_in_zoho_cliq);
// module: Leads or Contacts
message_meta_zoho.put("record",{"id":"XXXXX".toString(),"name": "XXX","module":"Leads"});
message_meta.put("zoho",message_meta_zoho);
postMessage.put("meta",message_meta);

response = invokeurl
[
url :PostURL
type :POST
parameters:postMessage.toString()
];

info response;