Last active
October 14, 2018 06:26
-
-
Save essivision/d94fbf5d5f53ebd0d04ff5ac456de1e4 to your computer and use it in GitHub Desktop.
Script for send SMS by SDP
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
npm install request --save |
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
// insert this command in custom trigger action | |
cmd c node run.js $COMPLETE_JSON_FILE $DIFF_JSON |
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
var fs = require('fs'); | |
var httpRequest = require('request'); // http client | |
var data = ''; | |
var diff =''; | |
var obj = {}; | |
var template = ''; | |
console.log('aaaaaaaaaaaaaa'); | |
// read $COMPLETE_JSON_FILE path | |
var readStream = fs.createReadStream(process.argv[2], 'utf8'); | |
readStream.on('data', function(chunk) { | |
data += chunk; | |
}).on('end', function() { | |
// JSON File for debug | |
fs.writeFile("json.txt", data, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("JSON file saved!"); | |
}); | |
// convert json to object | |
obj = JSON.parse(data); | |
// condition for detect edit mode | |
if(obj.diff !== undefined){ | |
// make template for request that edited | |
template = 'درخواست major با عنوان '+obj.request.SUBJECT+' از طرف '+obj.request.REQUESTER+' ایجاد شد'; | |
} else { | |
// make template to requets that created | |
template = 'درخواست major با عنوان '+obj.request.SUBJECT+' از طرف '+obj.request.REQUESTER+' ایجاد شد'; | |
}; | |
// write last template on file to debug | |
fs.writeFile("output.txt", template, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("The file was saved!"); | |
}); | |
/** | |
* Send SMS by API | |
**/ | |
var options = { | |
method: 'POST', | |
url: 'http://api.smsapp.ir/v2/sms/send/simple', | |
headers: { | |
apikey: 'ues4bEbGQdrJu6BPbwVhB2UUEEJdxs6S/PvJYtIw5Gk' | |
}, | |
form: { | |
message: template, | |
sender: '30005006001374', | |
Receptor: '09353071171' | |
} | |
}; | |
httpRequest(options, function (error, response, body) { | |
if (error) throw new Error(error); | |
console.log(body); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment