Skip to content

Instantly share code, notes, and snippets.

@glurp
Last active September 15, 2017 11:06
Show Gist options
  • Save glurp/adbc56f90840c12018fbd8c2253f5c03 to your computer and use it in GitHub Desktop.
Save glurp/adbc56f90840c12018fbd8c2253f5c03 to your computer and use it in GitHub Desktop.
SMS relay : droidScript for relaying all sms received to a http GET, and send GET Response to SMS caller
///////////////////////////////////////////////////////////////////////////
/// SMSPROXY
// client sms ===> smsproxy ==> http://xxxx.org?from=number&msg=
// <--- response
// <=====reply
//
///////////////////////////////////////////////////////////////////////////
function OnStart()
{
url = "https://XXXX.com";
path = "/gateway_sms.php";
delta=5*60*1000; // whatchdog
//Create layout that fills the screen.
lay = app.CreateLayout( "Linear", "FillXY,VCenter" );
//Create some text.
th1 = app.CreateText( "SMS PROXY" );
th1.SetTextSize( 22 );
lay.AddChild( th1 );
// ===================================== bar horizontal
layb = app.CreateLayout( "Linear", "Horizontal,FillX" );
layb.SetBackColor( "#ffff000000" );
//Create Send button.
btn = app.CreateButton( "Test Regis", 0.5, 0.1 );
btn.SetOnTouch( btn_OnTouch );
layb.AddChild( btn );
//Create Send button.
btr = app.CreateButton( "Test Lingxi", 0.5, 0.1 );
btr.SetOnTouch( btr_OnTouch );
layb.AddChild( btr );
lay.AddChild( layb );
// ===================================== fin bar horizontal
txt = app.CreateText( "", 0.9, 0.4, "Left,Multiline" );
txt.SetBackColor( "#ff003333" );
txt.SetTextSize( 10 );
lay.AddChild( txt );
lst = app.CreateList( "", 1.0, 0.5, "WhiteGrad" );
lst.SetTextColor1( "#ff555558");
lst.SetTextColor2( "#ff005558" );
lst.SetTextMargins( 0.04, 0, 0, 0 );
lay.AddChild( lst );
bex = app.CreateButton( "Exit", 0.1, 0.1 );
bex.SetOnTouch( bex_OnTouch );
lay.AddChild( bex );
//Add main layout to app.
app.AddLayout( lay );
//Create SMS object and set callbacks.
sms = app.CreateSMS();
sms.SetOnStatus( sms_OnStatus );
sms.SetOnMessage( sms_OnMessage );
_number="";
// Sound
synthBall = app.CreateSynth( "VCA" );
synthBall.SetWaveShape( "Square" );
synthBall.SetVca( 1, 30, 0, 0 );
// watchdog : signe de vie vers serveur si pas d'activite
lastCall = new Date().getTime();
setInterval(Watchdog,10*1000);
}
// Test: message to RegisLingxi
function btn_OnTouch() { sms.Send( "00336XXXXXXXX", "BRN998766574" ); }
function btr_OnTouch() { sms.Send( "00337XXXXXXXX", "Please reply" ); }
//Show SMS send status/progress.
function sms_OnStatus( status ) {
}
//Show in-comming SMS messages.
function sms_OnMessage( number, msg )
{
if ( msg.match( /^RESPONSE=/) ) {
return;
}
synthBall.PlayTone( 4*560, 50 );
//app.Vibrate( "0,100,30,100,50,300" );
var params = "from=" + number + "|msg="+msg+"|dt="+(new Date());
marker();
app.HttpRequest( "get", url, path, params,
function(e,r) {
HandleReply(number,e,r);
});
var t=(new Date().toTimeString()).split(/ /)[0];
lst.AddItem( number + " at " + t );
}
//Handle the servers reply.
function HandleReply(number, error, response )
{
txt.SetText( number +" ==> "+ response );
marker();
setTimeout(function() {
synthBall.PlayTone( 560, 10 );
sms.Send( number, "RESPONSE=\n"+ response );
},3000);
}
////////////////////////////////////////////////////////////
// WatchDog
////////////////////////////////////////////////////////////
function marker() { lastCall =new Date().getTime(); }
function Watchdog() {
var now = new Date().getTime();
if (lastCall+delta > now )
return;
synthBall.PlayTone( 560, 100 );
var params = "from=me|msg=watchdog|dt="+(new Date());
marker();
app.HttpRequest( "get", url, path, params, null );
}
function bex_OnTouch() {
app.Exit() ;
}
@glurp
Copy link
Author

glurp commented Sep 15, 2017

Exactly that , without a web-service :
image
( from Twillo site)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment