Routing based upon originator number

Routing based upon originator number SearchSearch
Author Message
Neil Stamps
Frequent Contributor
Username: Neil

Post Number: 52
Registered: 12-2009
Posted on Tuesday, July 27, 2010 - 04:25 pm:   

I would like to be able to route inbound messages to a user based upon the originating number (not the recipient number) - is this possible?

Thanks
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 2370
Registered: 08-2008
Posted on Tuesday, July 27, 2010 - 09:47 pm:   

Hi Neil,

There is no option to facilitate this for inbound messages.

I've been trying to think of work-arounds, but there is nothing easy. It would be possible to route messages to a 2-way command script instead of a local user, and then have that 2-way script resubmit the message to NowSMS as an inbound message directed to a specific local user account. However, doing this is a not a trivial task.

If you want more information, I can provide general guidance, but not complete scripts.

--
Des
NowSMS Support
Neil Stamps
Frequent Contributor
Username: Neil

Post Number: 53
Registered: 12-2009
Posted on Wednesday, July 28, 2010 - 09:09 am:   

Hi Des - yes I'd be interested in how this would be possible.

What I am trying to understand is how I can manage routing traffic to and from multiple back end systems to real devices. For example we will have up to maybe 10 systems that will need to be sending and receiving SMS and MMS messages. Outbound would seem not to be a problem (although how does NowSMS know where to send the delivery acknowledgement - is it based on the submitting user account?) - but I am unsure about inbound routing.

Routing based upon originator number would seem to be one way forward - if you can suggest another I am open to suggestions.

Is this a restriction in the lite, and if we upgraded to the full version we would have more flexibility? It would be a little impractical for us to have a dedicated modem/sim card for each back end system - as these are likely to fluctuate in number based upon our development requirements.

thanks for any assistance you can provide.
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 2376
Registered: 08-2008
Posted on Wednesday, July 28, 2010 - 10:34 pm:   

Hi Neil,

The delivery reports do get routed back based upon the submitting user account.

I need a little bit of time to think about this.

The solution that I'm thinking of is definitely a kludge, but I think it would be workable. It would just require a relatively simple PHP script running on a separate web server.

An alternative solution would involve us adding the ability for an accounting callback to control inbound message routing, similar to the interface that allows accounting callbacks to control outbound message routing. This would be a good idea for us to add, but for your purposes, there's no real benefit to this alternative as you'd still need a PHP (or similar) script.

Give me a day or two more to think about it. I probably just need to find an hour to cut & paste between some existing PHP scripts ... unless I think of a better idea.

--
Des
NowSMS Support
Neil Stamps
Frequent Contributor
Username: Neil

Post Number: 55
Registered: 12-2009
Posted on Thursday, July 29, 2010 - 12:41 pm:   

Thanks.

Would this mechanism also be able to do some mapping of outgoing messages (for example changing the sending number - so that each user account thinks it is sending from a different number, but this is actually mapped at the gateway itself)
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 2386
Registered: 08-2008
Posted on Thursday, July 29, 2010 - 08:41 pm:   

I'm not sure that I understand the outbound scenario that you are describing. (When sending via a GSM modem, any sender address applied by the client will be lost.)

For the original inbound message routing scenario, I've created a simple 2-way PHP script that you can use.

Change the settings for the modem in the SMSC list so that it does not automatically route received messages to a local user account. Received messages will then be routed to the 2-way commands.

Define a command with an SMS command prefix of *, and a URL of:

http://server/routein.php?phonenumber=@@RECIP@@&sender=@@SENDER@@&text=@@FULLSMS@@&udh=@@UDH@@&pid=@@PID@@&dcs=@@DCS@@&binary=@@BINARY@@

(Modify the server address and path to the script as necessary when you put the script on your web server. Note that the discussion board software has likely added an extra space in the URL that does not belong.)

Here is routein.php ...

Note that you will need to make edits in the script in two places to add your logic for filtering which messages go to which user account, and for setting the parameters for connecting back to your NowSMS server.

text/plainroutein.php
routein-php.txt (3.2 k)


<?php
/* Note: This is a 2-way script that parses received messages to selectively route messages to different local user accounts

The following 2-way command URL should be used:

http://server/routein.php?phonenumber=@@RECIP@@&sender=@@SENDER@@&text=@@FULLSMS@@&udh=@@UDH@@&pid=@@PID@@&dcs=@@DCS@@&binary=@@BINARY@@

Look for "TODO" references below to see where this script should be edited.

*/

function SimpleHTTPGet ($host, $port, $username, $password, $urlString) {

/* Parameters:
$host - IP address or host name of the NowSMS server
$port - Port number for the web interface" of the NowSMS Server
$username - "SMS Users" account on the NowSMS server
$password - Password defined for the "SMS Users" account on the NowSMS Server
$urlString - URL string to be sent to the NowSMS server (start with /")
*/

$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
echo "errno: $errno \n";
echo "errstr: $errstr\n";
return $result;
}

fwrite($fp, "GET " . $urlString . " HTTP/1.0\n");
if ($username != "") {
$auth = $username . ":" . $password;
$auth = base64_encode($auth);
fwrite($fp, "Authorization: Basic " . $auth . "\n");
}
fwrite($fp, "\n");

$res = "";

while(!feof($fp)) {
$res .= fread($fp,1);
}
fclose($fp);


return $res;
}

function AddURLParameter ($urlString, $parmName, $parmValue) {

if (is_null($urlString)) {
$urlString = "/?";
}
else {
$urlString = $urlString . "&";
}

$urlString = $urlString . $parmName . "=" . rawurlencode($parmValue);

return $urlString;

}


header ("Content-Type: text/plain");

$urlString = NULL;

/* Test binary value to determine message format */

$binary = false;

if (isset($_REQUEST['binary'])) {
if ($_REQUEST['binary'] == "1") {
$binary = true;
}
}

if (isset($_REQUEST['phonenumber'])) {
$urlString = AddURLParameter ($urlString, "PhoneNumber", $_REQUEST['phonenumber']);
}
if (isset($_REQUEST['sender'])) {
$urlString = AddURLParameter ($urlString, "Sender", $_REQUEST['sender']);
}
if (isset($_REQUEST['text'])) {
if ($binary) {
$urlString = AddURLParameter ($urlString, "Data", $_REQUEST['text']);
}
else {
$urlString = AddURLParameter ($urlString, "Text", $_REQUEST['text']);
}
}
if (isset($_REQUEST['pid'])) {
$urlString = AddURLParameter ($urlString, "pid", $_REQUEST['pid']);
}
if (isset($_REQUEST['dcs'])) {
$urlString = AddURLParameter ($urlString, "dcs", $_REQUEST['dcs']);
}

/* TODO: This is where your program logic needs to set which user account the message should be routed to */

if ($sender == "1234") {
$localuser = "user1234";
}
else {
$localuser = "test";
}

$urlString = AddURLParameter ($urlString, "InboundMessage", "Yes");

$urlString = AddURLParameter ($urlString, "LocalUser", $localuser);

/* TODO: Modify the parameters below to point to your NowSMS server with a valid user account and password */

SimpleHTTPGet ("192.168.0.160", 8800, "testuser", "testpass", $urlString);


?>

--
Des
NowSMS Support