كيفية إرسال WhatsApp API باستخدام Java

مقدمة

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

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("name", "hello_world")
			.add("language", "en_us")
			.add("header", "")
			.add("body", "")
			.add("buttons", "")
			.add("priority", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/template")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("body", "WhatsApp API on alvochat.com works good")
			.add("priority", "")
			.add("preview_url", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/chat")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

إرسال صورة

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("image", "https://alvochat-example.s3-accelerate.amazonaws.com/image/1.jpeg")
			.add("caption", "image caption")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/image")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

إرسال الصوت

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("audio", "https://alvochat-example.s3-accelerate.amazonaws.com/audio/1.mp3")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/audio")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("video", "https://alvochat-example.s3-accelerate.amazonaws.com/video/1.mp4")
			.add("caption", "video caption")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/video")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("document", "https://alvochat-example.s3-accelerate.amazonaws.com/document/1.pdf")
			.add("filename", "")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/document")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("sticker", "https://alvochat-example.s3-accelerate.amazonaws.com/sticker/1.webp")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/sticker")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("contact", "")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/contact")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

إرسال موقع

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("lat", "37.484296")
			.add("lng", "-122.148703")
			.add("address", "Menlo Park, California, United States")
			.add("name", "Meta Headquarters")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/location")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("header", "header")
			.add("body", " please select one of the following options")
			.add("footer", "footer")
			.add("button", "options")
			.add("sections", "option_1,option_2,option_3")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/list")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("header", "header")
			.add("body", " please select one of the following options")
			.add("footer", "footer")
			.add("buttons", "option_1,option_2,option_3")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/button")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

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

OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder() 
			.add("token", "YourToken")
			.add("to", "16315555555")
			.add("header", "header")
			.add("body", "Hi , check out our new products")
			.add("footer", "footer")
			.add("catalog_id", "")
			.add("product", "")
			.add("priority", "")
			.add("message_id", "")


            .build();

Request request = new Request.Builder()
  .url("https://api.alvochat.com/instance1199/messages/product")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();
 
 System.out.println(response.body().string());

الرموز أعلاه تستخدم Java معOkHttp مكتبة ، إذا كنت تريد إرسال WhatsApp API باستخدام Java باستخدام وUnirest مكتبة ، يمكنك عرض الرموز من هنا .

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