Incoming Sms To Database

925 views
Skip to first unread message

Emre Groups

unread,
Apr 15, 2021, 7:16:25 PM4/15/21
to Jasmin SMS Gateway
Hi everyone;

First of all, thank you in advance for your help. I was able to connect via smpp and receive sms. However, I could not find how to write the incoming sms on a database. Can you help me ?

Regards

Emre

Eudorajab

unread,
Apr 24, 2021, 8:10:39 AM4/24/21
to Jasmin SMS Gateway
Hi Emre,

Do you want to write MO's to the database or MT's? Also what database are you using?

John

Bikin Karya

unread,
May 11, 2021, 1:34:42 PM5/11/21
to Jasmin SMS Gateway
Hi John,

If I want to store the MO's to Database, where to start this?

Thanks

Kamui Shiro

unread,
May 13, 2021, 5:19:02 AM5/13/21
to Jasmin SMS Gateway
Incoming  SMS (MO) need a callback URL (HTTP Client connector) more https://docs.jasminsms.com/en/latest/management/jcli/modules.html#http-client-connector-manager. You have to set if jasmin will call this URL using GET or POST method,

As soon as you prepare the URL let's say https://example.com/mo-sms.php you need to create a routing rule to send incoming SMS (all or some of them) to this URL more
https://docs.jasminsms.com/en/latest/management/jcli/modules.html#mo-router-manager. For your test better set a DefaultMORoute so you can send all incoming traffic to a single URL.

Everything is ready now it's time to prepare your mo-sms.php script (of course this can be javascript, python or whatever you like). According to to the manual here are the parameters that jasmin will send back to your URL whenever an incoming SMS arrives https://docs.jasminsms.com/en/latest/apis/ja-http/index.html#http-parameters.

below a sample code

<?php
$id=$_POST["id"];
$from=$_POST["from"];
$to=$_POST["to"];
.....

$conn = mysqli_connect("localhost","root","","json") or die("Error " . mysqli_error($connection));

$sql = "INSERT INTO MO(id,from,to,...) values($id,$from,$to...);

if ($conn->query($sql) === TRUE) {
  echo "data stored successfully";
} else {
  echo "data still not received";
}
?>

Emre SAKA

unread,
Feb 27, 2022, 3:36:01 PM2/27/22
to Jasmin SMS Gateway
Dear kamu..
Thanks for support. Do u have any example or can u support us for MO Sms to Mysql database proc. 

13 Mayıs 2021 Perşembe tarihinde saat 12:19:02 UTC+3 itibarıyla kamu...@gmail.com şunları yazdı:

Kamui Shiro

unread,
Feb 28, 2022, 1:04:57 PM2/28/22
to Jasmin SMS Gateway
Hi there, I think my answer above is really elaborated and I don't understand exactly what kind of help do you need, but let me try once more.

Let's say that you own a webserver with the domain www.mosms.com which supports PHP and also you have your Database. At the root you can create a php file (e.g. mo-sms.php) with my sample code to save the MO SMS to you database (The code needs some kind of string sanitization for the incoming parameters to avoid SQL Injections!!!!)

<?php
$id=$_POST["id"];
$from=$_POST["from"];
$to=$_POST["to"];
.....

$conn = mysqli_connect("localhost","root","","json") or die("Error " . mysqli_error($connection));

$sql = "INSERT INTO MO(id,from,to,...) values($id,$from,$to...);

if ($conn->query($sql) === TRUE) {
  echo "data stored successfully";
} else {
  echo "error occured for SMS ".$id;
}
?>

The above is a SAMPLE CODE and like I said you need to sanitize the string (use prepared statements maybe?) and of course capture most, if not all, the available parameters.

id (unique identifier for the sms), 
from (Sender), 
to (receiver usually a mobile phone number), 
origin-connector (very important! the connector that the message come from), 
priority, 
coding (need to know if the message that arrived is in GSM-7 or UCS2), 
validity, content (the actual message), 
binary (the actual message in HEX, usefull when you have to do with encodings)

Now move to your Jasmin Gateway. You need to create a MO SMS connector. Example follows:

jcli : httpccm -a Adding a new Httpcc: (ok: save, ko: exit) > url https://www.mosms.com/mo-sms.php > method POST > cid myhttpconnector > ok Successfully added Httpcc [HttpConnector] with cid:myhttpconnector


After that you need to create a MOroute to route all SMS from to the above connector. For simplicity I use the DefaultRoute so I will send all the SMS to my previously creted connector, thus to the Database.

jcli : morouter -a Adding a new MO Route: (ok: save, ko: exit) > type DefaultRoute jasmin.routing.Routes.DefaultRoute arguments: connector > connector http( myhttpconnector) > ok Successfully added MORoute [DefaultRoute] with order:0  

Now everytime a MO message arrives the MORoute redirects it to connector "myhttpconnector". Now the connector generates a POST request to your webserver (e.g. https://www.mosms.com/mo-sms.php with body "id=36265862h&from=Sender&to=4429236402&content=This%20is%20a%20test%20message..."). The webserver will grab the information with the help of the php script and save them to DB.

I really cannot explain it more than this. https://docs.jasminsms.com/en/latest/apis/ja-http/index.html#receiving-sms-mo This article is really helpful to understand the logic.

Kamui Shiro

unread,
Mar 1, 2022, 7:03:56 AM3/1/22
to Jasmin SMS Gateway
Hi again ....my fault here, but again check the jasmin's web page. You can find everything you need there. 

https://docs.jasminsms.com/en/latest/programming-examples/index.html#receiving-sms

Check the above link which includes a "better" version for the sample code. As you can see (and this is my mistake sorry) at the end of every finished transaction you have to reply to jasmin server that you received the message properly. You do that by echoing this string  "ACK/Jasmin" (It's the same like getting a DLR receipt).

So let me change my code to

<?php
$id=$_POST["id"];
$from=$_POST["from"];
$to=$_POST["to"];
.....

$conn = mysqli_connect("localhost","root","","json") or die("Error " . mysqli_error($connection));

$sql = "INSERT INTO MO(id,from,to,...) values($id,$from,$to...);

if ($conn->query($sql) === TRUE) {
  echo " ACK/Jasmin";
} else {
  header('HTTP/1.1 500 Internal Server Error');
}
?>

Now if you get a message and properly insert it to DB, you will reply with the Jasmin acknowledgement, if not jasmin will receive a http error 500 and I suppose it will try again to send you the message info. Although better check the link above and follow the example in Jasmin's website.

Reply all
Reply to author
Forward
0 new messages