Node.js का उपयोग करके आसानी से WhatsApp API द्वारा संदेश कैसे भेजें

परिचय

इस ट्यूटोरियल में, हम Node.js . का उपयोग करके WhatsAppAPI के माध्यम से WhatsApp संदेश भेजने के लिए एक पेज बनाएंगे

स्थापना अनुरोध मॉड्यूल

npm install request

Node.js का उपयोग करते हुए पहला WhatsApp API संदेश

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/chat',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {
    token: 'Instance_token',
    to: '14155552671',
    body: 'WhatsApp API on UltraMsg.com works good',
    priority: '10',
    referenceId: ''
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

छवि भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/image',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {
    token: 'Instance_token',
    to: '14155552671',
    image: 'https://file-example.s3-accelerate.amazonaws.com/images/test.jpg',
    caption: 'image Caption',
    referenceId: ''
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

दस्तावेज़ भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/document',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {
    token: 'Instance_token',
    to: '14155552671',
    filename: 'hello.pdf',
    document: 'https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf',
    referenceId: ''
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

ऑडियो भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/audio',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {token: 'Instance_token', to: '14155552671', audio: 'https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3', referenceId: ''}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

आवाज भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/voice',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {token: 'Instance_token', to: '14155552671', audio: 'https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg', referenceId: ''}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

वीडियो भेजना

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/video',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {token: 'Instance_token', to: '14155552671', video: 'https://file-example.s3-accelerate.amazonaws.com/video/test.mp4', referenceId: ''}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

लिंक भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/link',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {token: 'Instance_token', to: '14155552671', link: 'https://en.wikipedia.org/wiki/COVID-19', referenceId: ''}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

संपर्क भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/contact',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {
    token: 'Instance_token',
    to: '14155552671',
    contact: '[email protected]',
    referenceId: ''
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

स्थान भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/location',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {
    token: 'Instance_token',
    to: '14155552671',
    address: 'ABC company \n Sixth floor , office 38',
    lat: '25.197197',
    lng: '55.2721877',
    referenceId: ''
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

वीकार्ड भेजें

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.ultramsg.com/instance1150/messages/vcard',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  form: {token: 'Instance_token', to: '14155552671', vcard: ' BEGIN:VCARD\nVERSION:3.0\nN:lastname;firstname\nFN:firstname lastname\nTEL;TYPE=CELL;waid=14000000001:14000000002\nNICKNAME:nickname\nBDAY:01.01.1987\nX-GENDER:M\nNOTE:note\nADR;TYPE=home:;;;;;;\nADR;TYPE=work_:;;;;;;\nEND:VCARD', referenceId: ''}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});