Sample Code

📘

النسخة العربية

لعرض النسخة باللغة العربية اضغط هنا

Create a "Loop" with specific values

To Loop Array variable inside the Flow, such as Cities and Countries, modify the following code example

let array = [{"city": "Riyadh", "country": "Saudi Arabia"},{"city": "Dubai", "country": "United Arab Emirates"}];

let arr = array.length;
let currentIndex = "#currentIndex11#";

currentIndex = parseInt(currentIndex) ? currentIndex : 0;

let loop_end = "false";
let city = "";
let country = "";
if (currentIndex < array.length){
  city = array[currentIndex].city;
  country = array[currentIndex].country;
  currentIndex = currentIndex+1;
} else {
  loop_end = "true";
}
setConversationVariables("city", city, "text");
setConversationVariables("country", country, "text");
setConversationVariables("currentIndex", currentIndex, "text");
setConversationVariables("loop_end", loop_end, "text");
setConversationVariables("arrloop",arr, "text");

Check language

To do an "automatic" check to find out if the customer is typing in English or Arabic, use the following code sample.

const content = "#content#";
const firstCharacter = content.charAt(0);
if (firstCharacter.match(/[a-z]/i)) {
    setConversationVariables('isEnglish', "true", "string");
} else if (firstCharacter.match(/[\u0600-\u06FF\u0750-\u077F]/)) {
    setConversationVariables('is Arabic', "true", "string");
} else {
    setConversationVariables('isPhrase', "false", "string");
}