-
-
Save yonisetiawan/850ff54495bcdcd1e1f7c1d8f681984e to your computer and use it in GitHub Desktop.
Sending a WhatsApp message in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
I wanna do this for the sake of automation