-
Notifications
You must be signed in to change notification settings - Fork 17
Install Instructions
badlee edited this page Sep 25, 2014
·
1 revision
##How Install and Test scriptbox
Some Instruction for install and test.
How Install
$ git clone git@github.com:badlee/scriptbox.git
$ cd scriptbox
$ npm i .
$ mv settings.conf.dist settings.json
$ node . & # pour demarer ca en tache de fond
$ # go to http://127.0.0.1:13014
Test scriptbox(the SMS gateway)
To test you need to configure first configure the following :
- A connector (for connect to Kannel or to a SMPP Server) in left menu : Connecteur > Ajouter
- A script (un code javascript) in left menu : Script > Ajouter
- A keyword (a keyword that the user not send SMS and will be linked to the script) in left menu : Mots Cles > Ajouter
- Start a connector (if it is not already) in left menu : clique sur Connector > Liste, then choose your connector and click 'Start server'
Start kannel for test
$ bearerbox /path/to/kannel.conf -v 0
$ cd /pah/to/kannel/test/
$ ./fakesmsc -i .1 -m 1 "0000 8080 text echo juste an sms"
A script that returns the SMS sent
/* Echo sms service */
new MSG(sms).sendSMS();
A script that allows you to vote by SMS
Vote for, simply send "[Keyword] [choice]," the choices are A, B, C, D.
To get the results, just send "[Keyword]".
The database used is mongodb, so you need to type npm i mongoose
, if the driver is not already installed.
/*
LIST OF SMS FORMAT
* Vote for a team
KEYWORD[ ]VOTE_FOR
* Obtain the result
KEYWORD
*/
var mongoose = require('mongodb'),
texto = sms.msgdata.split(' '),
match = "",
msg = new MSG(sms),
team = ["a","b","c","d"];
/* check the syntax */
if(!(match = sms.msgdata.match(/^[a-z0-9]+([ ]+([abcd]))?$/i))){
msg.sendSMS("For Vote send : "+texto[0].toUpperCase()+" YOUR CHOICE\nPossible choice are :"+(team.join(', ').toUpperCase()));
}else{
sms.msgdata = new Buffer(sms.msgdata).toString();
// connect to vote database
var db = mongoose('mongodb://localhost/'+texto[0]);
db.on('error',function(){
msg.sendSMS('Error when vote retry later!');
});
db.once('open',function(){
/* create vote schema */
var Vote = db.model('votes',{
phone_number : String,
voted_for : String
});
switch(typeof match[2]){
case 'string': // it's a vote
new Vote({
phone_number : new Buffer(sms.sender).toString(),
voted_for : match[2].toUpperCase()
}).save(function(err){
db.close(); // !important you must close connection
msg.sendSMS(err ? 'Error when vote retry!' : 'Votre registred vote again for your team...');
});
break;
default : //obtain the result
var result = {};
team.map(function(e){ result[e.toUpperCase()] = 0; });
Vote.find({},function(err,res){
db.close();// !important you must close connection
res.map(function(e){ result[e.voted_for] += 1; });
res = [];
for(var i in result) res.push({_id:i,value : result[i]});
var ret = [];
res.sort(function(a,b){ return a.value < b.value}).map(function(a){ ret.push(" "+a._id+" : "+a.value); })
msg.sendSMS("Vote result : "+ret.join(", "));
})
}
})
}
My setup kannel
group = core
admin-port = 14000
smsbox-port = 14001
admin-password = bar
log-level = 0
log-file = /tmp/kannel.log
group = smsbox
bearerbox-host = "127.0.0.1"
sendsms-port = 14014
global-sender = 14014
log-file = smsbox.log
smsbox-id = LoveIsMyReligion
group = smsc
smsc = fake
smsc-id = fakesmsc
host = localhost
port = 10000
group = smsbox-route
smsbox-id = LoveIsMyReligion
smsc-id = fakesmsc
group = sendsms-user
username = tester
password = foobar
group = sms-service
keyword = default
text = "No service specified"