I am quite not much familiar with javascript and want to create a function for sending SMS, generally a normal function I can able to create but chunk function with I am not able to run. I also read the other threads available on Google but it was not helpful. Please help I want when I call this function then API will run.
How do I achieve the goal…
const options = {
"method": "POST",
"hostname": "api.msg91.com",
"port": null,
"path": "/api/v5/flow/",
"headers": {
"authkey": "1234567890",
"content-type": "application/JSON"
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write("{\n \"flow_id\": \"EnterflowID\",\n \"sender\": \"EnterSenderID\",\n \"short_url\": \"1 (On) or 0 (Off)\",\n \"mobiles\": \"919XXXXXXXXX\",\n \"VAR1\": \"VALUE 1\",\n \"VAR2\": \"VALUE 2\"\n}");
req.end();```
Want to create this function
sendSMS(myflowid, mysenderid, myshorturl, mymobileno, myvar1, myvar2);
if(sendSMS ==1) {
return res.json({msg:"MSG Sent"});
} else {
return res.json({msg:"MSG Not Sent"});
}