Created
April 12, 2017 23:25
-
-
Save ThomasG77/8790e35ad5a220d3d327e201a3f27580 to your computer and use it in GitHub Desktop.
Essai d'envoi de SMS uniquement avec Node et un abonnement Free.fr (adaptée à 90% de http://blog.nicolasc.eu/utiliser-api-de-notification-sms-free-mobile-depuis-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
const https = require('https'); | |
const querystring = require('querystring'); | |
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; | |
function sendSms (message) { | |
var qs = querystring.stringify({ | |
user: process.env.free_fr_user_account, | |
pass: process.env.free_fr_sms_key, | |
msg: message | |
}); | |
var apiUrl = 'https://smsapi.free-mobile.fr/sendmsg' + '?' + qs; | |
https.get(apiUrl, function (res) { | |
if (res.statusCode !== 200) { | |
// You can use alternate option here (mail,...) | |
console.log('Not 200', res); | |
} | |
res.resume(); | |
}).on('error', function (e) { | |
console.error(e); | |
}); | |
} | |
if (!process.env.free_fr_user_account && !process.env.free_fr_sms_key) { | |
console.log('You need to set both environment variables'); | |
} else { | |
sendSms("Il était un petit navire Il était un petit navire Qui n'avait ja-ja-jamais navigué Qui n'avait ja-ja-jamais navigué Ohé, ohé…"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment