أرسل WhatsApp API باستخدام JavaScript

مقدمة

في مقتطف الشفرة هذا ، تتعلم كيفية إرسال WhatsApp API باستخدام JavaScript ، لإرسال رسالة نصية ، قوالب WhatsApp ، وسائط ، أزرار تفاعلية ، قوائم ، منتجات … إلخ ، حساب Alvochat مطلوب لتشغيل الرموز التالية. قم بإنشاء حساب إذا لم يكن لديك حساب.

أرسل نموذجًا باستخدام WhatsApp API و JavaScript

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("name","hello_world");
urlencoded.append("language","en_us");
urlencoded.append("header","");
urlencoded.append("body","");
urlencoded.append("buttons","");
urlencoded.append("priority","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/template", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

أرسل رسالة نصية باستخدام WhatsApp API و JavaScript

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("body","WhatsApp API on alvochat.com works good");
urlencoded.append("priority","");
urlencoded.append("preview_url","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/chat", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال صورة

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("image","https://alvochat-example.s3-accelerate.amazonaws.com/image/1.jpeg");
urlencoded.append("caption","image caption");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/image", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال الصوت

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("audio","https://alvochat-example.s3-accelerate.amazonaws.com/audio/1.mp3");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/audio", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

ارسل مقطع فيديو

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("video","https://alvochat-example.s3-accelerate.amazonaws.com/video/1.mp4");
urlencoded.append("caption","video caption");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/video", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال المستندات

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("document","https://alvochat-example.s3-accelerate.amazonaws.com/document/1.pdf");
urlencoded.append("filename","");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/document", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال الستيكر

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("sticker","https://alvochat-example.s3-accelerate.amazonaws.com/sticker/1.webp");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/sticker", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال جهة اتصال

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("contact","");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/contact", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال موقع

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("lat","37.484296");
urlencoded.append("lng","-122.148703");
urlencoded.append("address","Menlo Park, California, United States");
urlencoded.append("name","Meta Headquarters");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/location", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال القوائم

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("header","header");
urlencoded.append("body"," please select one of the following options");
urlencoded.append("footer","footer");
urlencoded.append("button","options");
urlencoded.append("sections","option_1,option_2,option_3");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/list", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال أزرار الواتس اب التفاعليه

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("header","header");
urlencoded.append("body"," please select one of the following options");
urlencoded.append("footer","footer");
urlencoded.append("buttons","option_1,option_2,option_3");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/button", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

إرسال المنتجات

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("token","YourToken");
urlencoded.append("to","16315555555");
urlencoded.append("header","header");
urlencoded.append("body","Hi , check out our new products");
urlencoded.append("footer","footer");
urlencoded.append("catalog_id","");
urlencoded.append("product","");
urlencoded.append("priority","");
urlencoded.append("message_id","");


var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://api.alvochat.com/instance1199/messages/product", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

الرموز أعلاه تستخدم جافا سكريبت باستخدام fetch ، إذا كنت تريد إرسال WhatsApp API مع Javascript باستخدام ملفXMLHttpRequest يمكنك مشاهدة الأكواد من هنا .

يمكنك الاطلاع على وثائق Whatsapp API الكاملة هنا .