Send WhatsApp Messages Using Chat API In jQuery - Ajax

  • 09-09-2022
  • 2350
  • Jquery
  • Haresh Chauhan

Send WhatsApp messages send using jQuery with the help of chat API; We will send WhatsApp messages using chat API in jQuery but before that, we need to generate the install number and token no from the chat API. For that, you need to create an account in the chat API, after which they will provide the token no and instance number for sending a message to WhatsApp.

Using chat API we will send WhatsApp messages, for that, we will create an account, click on the given link and create an account Create Account

See below the given image, from there you will find your credentials.

image

Integrate In jQuery

Once you generate your token and instance number from there, paste in the given variable $token & $instanceId, then after adding your mobile number to the data array define the template name as well as the namespace and language also.

Now run your jQuery script and you will receive a message from the register number in the account.

// URL FOR REQUEST POST /MESSAGE
const token = '83763g87x';
const instanceId = '777';

const url = `https://api.chat-api.com/instance${instanceId}/sendTemplate?token=${token}`;

let data = {
     phone: '91XXXXXXXXXX', // RECEIVERS PHONE
     template: "template_name",
     namespace : "namespace_of_template",
     language: {
          code: "en",
          policy: "deterministic"
     }
};

// SEND A REQUEST
$.ajax(url, {
     data : JSON.stringify(data),
     contentType : 'application/json',
     type : 'POST'
});

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :