Ready JavaScript Solutions
This section contains JavaScript solutions for HTTP Request block that will help with non-standard tasks
Example Code for File Transfer to Third-Party Server:
var fileUrl = "https://example.com/path/to/file.jpeg";
XMLHttpRequest object
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
var formData = new FormData();
formData.append("file", fileUrl);
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.onload = function() {
if (xhr.status === 200) {
console.log("File successfully sent");
} else {
console.log("File send error");
}
};
xhr.send(formData);
Example Code for Birth Date Calculations
URL for HTTP Request block: https://app.leadteh.ru/api/v1/getMe?api_token=`}
var yearBirth = getContactVariable("Date");
var year = yearBirth.substring(yearBirth.length - 4);
function digit (number) {
var figures = "" + number
var sum = 0
for (var i = 0; i < figures.length; i++)
sum += +figures[i]
return sum
}
year = digit(year);
if(year > 22){
year = digit(year);
}
setContactVariable("Energy", year)
Example Code for Bot with Catalog in Buttons
For first HTTP block
for (i = 1; i <= 100; i++) {
deleteContactVariable("Button "+i);
};
For second HTTP block
var total = response.data.meta.total;
for (i = 1; i <= total; i++) {
var product = response.data.data[i-1].name;
var price = response.data.data[i-1].price;
setContactVariable("Button "+i,
product+" | "+price+" ₽");
};
For third HTTP block
var choice = getContactVariable("choice");
choice = choice.split(" |")[0];
setContactVariable("choice", choice);
In the LEADTEX personal account, 250+ lessons on developing chat bots and MiniApps are already available, as well as the opportunity to join the largest no-code developer community with 6000+ participants - Go to Personal Account.