Skip to content

Instantly share code, notes, and snippets.

@yonisetiawan
Forked from whatsmate/send-whatsapp.js
Created March 29, 2018 00:58
Show Gist options
  • Save yonisetiawan/850ff54495bcdcd1e1f7c1d8f681984e to your computer and use it in GitHub Desktop.
Save yonisetiawan/850ff54495bcdcd1e1f7c1d8f681984e to your computer and use it in GitHub Desktop.
Sending a WhatsApp message in Node.js
#!/usr/bin/env node
var http = require('http');
var instanceId = "YOUR_INSTANCE_ID_HERE"; // TODO: Replace it with your gateway instance ID here
var clientId = "YOUR_CLIENT_ID_HERE"; // TODO: Replace it with your Forever Green client ID here
var clientSecret = "YOUR_CLIENT_SECRET_HERE"; // TODO: Replace it with your Forever Green client secret here
var jsonPayload = JSON.stringify({
number: "12025550108", // TODO: Specify the recipient's number here. NOT the gateway number
message: "Howdy, isn't this exciting?"
});
var options = {
hostname: "api.whatsmate.net",
port: 80,
path: "/v3/whatsapp/single/text/message/" + instanceId,
method: "POST",
headers: {
"Content-Type": "application/json",
"X-WM-CLIENT-ID": clientId,
"X-WM-CLIENT-SECRET": clientSecret,
"Content-Length": Buffer.byteLength(jsonPayload)
}
};
var request = new http.ClientRequest(options);
request.end(jsonPayload);
request.on('response', function (response) {
console.log('Heard back from the WhatsMate WA Gateway:\n');
console.log('Status code: ' + response.statusCode);
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log(chunk);
});
});
Copy link

ghost commented Sep 30, 2020

Hi. I wanna create a class in javascript. The logic of my class must be like this:

first of all, I wanna get an AccessToken.
after that, the real process starts.
supposition:

  1. I wanna get all posts. therefore I send a GET request to the HTTP://localhost:3000/api/v1/posts
  2. The AccessToken is not valid
  3. Previous request locked.
  4. New request send with RefreshToken to a new AccessToken
  5. Locked request send again with new AccessToken.

I wanna do this for the sake of automation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment