Skip to content

Instantly share code, notes, and snippets.

@BransonGitomeh
Last active October 16, 2019 14:59
Show Gist options
  • Save BransonGitomeh/5ad34086ea72c27c766fb278c92dbeab to your computer and use it in GitHub Desktop.
Save BransonGitomeh/5ad34086ea72c27c766fb278c92dbeab to your computer and use it in GitHub Desktop.
var request = require("request");
// Require `PhoneNumberFormat`.
const PNF = require('google-libphonenumber').PhoneNumberFormat;
// Get an instance of `PhoneNumberUtil`.
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
function makeid() {
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 4; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
const func = ({ data: { submited, project } }, reply) => {
const number = phoneUtil.parseAndKeepRawInput(submited.__agentPhoneNumber, 'KE');
const coolNumber = phoneUtil.format(number, PNF.E164)
const Body = `test`
// var options = {
// method: 'POST',
// url:
// 'https://api.twilio.com/2010-04-01/Accounts/AC474e88621c6e58239e0628094c4d0f8a/Messages.json',
// headers:
// {
// authorization:
// 'Basic QUM0NzRlODg2M---------------------WVmOWJjZTZhNA==',
// 'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
// },
// formData:
// {
// To: coolNumber,
// From: '+13252214877',
// Body:
// }
// };
const options = {
method: 'POST',
url: 'https://account.mobilesasa.com/api/express-post',
headers:
{
'content-type': 'application/x-www-form-urlencoded',
accept: 'application/json'
},
form:
{
api_key:
'$2y$10$-----------------FzMeut/VxKgZSGR.',
senderID: 'MOBILESASA',
phone: coolNumber,
message: Body,
username: 'branson'
}
}
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(JSON.stringify(JSON.parse(body), null, '\t'))
reply();
});
}
// usage tests
// console.log(makeid())
// func({ data: { password: makeid(), phone: "+254711657108" } }, console.log)
module.exports = func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment