I have set up sms command with keyword balance. But playsms doesn’t seem to see the keyword on the second sms…Below is my log
- - 2015-12-02 16:49:45 PID565f2104547f4 - L3 recvsmsd # id:32 dt:2015-12-02 16:49:44 sender:+254702163459 m:Balance 10 receiver:+254702163459 smsc:
- - 2015-12-02 16:49:45 PID565f2104547f4 - L3 recvsms_process # dt:2015-12-02 16:49:44 sender:+254702163459 m:Balance 10 receiver:+254702163459 smsc:
- - 2015-12-02 16:49:45 PID565f2104547f4 - L3 sms__command # command_exec:/var/lib/playsms/sms_command/1/mpesa_topup.sh 'Balance 10'
- - 2015-12-02 16:49:45 PID565f2104547f4 - L3 sms__command # command_output is empty
- - 2015-12-02 16:49:45 PID565f2104547f4 - L3 recvsms_process # feature:sms_command datetime:2015-12-02 16:49:44 sender:+254702163459 receiver:+254702163459 keyword:BALANCE message:10 raw:Balance 10 smsc:
10.5.11.164 10.5.1.4 2015-12-02 16:50:20 PID565f214c18542 - L3 sms_sync__sync # saving uid:1 dt:2015-12-02 16:50:20 ts:1449075015000 message_id:b7e20c9f-5e3d-4882-8d8b-5b8882fb971f s:+254702163459 m:JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00 r:+254702163459
10.5.11.164 10.5.1.4 2015-12-02 16:50:20 PID565f214c18542 - L3 sms_sync__sync # forwarded to inbox uid:1 message_id:b7e20c9f-5e3d-4882-8d8b-5b8882fb971f
10.5.11.164 10.5.1.4 2015-12-02 16:50:20 PID565f214c18542 - L3 recvsms # isrecvsmsd:1 dt:2015-12-02 16:50:20 sender:+254702163459 m:@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00 receiver:+254702163459 smsc:
10.5.11.164 10.5.1.4 2015-12-02 16:50:20 PID565f214c18542 - L3 sms_sync__sync # saved uid:1 message_id:b7e20c9f-5e3d-4882-8d8b-5b8882fb971f recvsms_id:33
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 recvsmsd # id:33 dt:2015-12-02 16:50:20 sender:+254702163459 m:@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00 receiver:+254702163459 smsc:
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 incoming__recvsms_intercept # recvsms_intercept dt:2015-12-02 16:50:20 s:+254702163459 r:+254702163459 m:@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 incoming__recvsms_intercept # pv u:admin uid:1 dt:2015-12-02 16:50:20 s:+254702163459 r:+254702163459 m:[@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00] reference_id:
- - 2015-12-02 16:50:20 PID565f2104547f4 - L2 recvsms_inbox_add # saving sender:+254702163459 receiver:+254702163459 target:admin reference_id:
- - 2015-12-02 16:50:20 PID565f2104547f4 - L2 recvsms_inbox_add # saved id:9 sender:+254702163459 receiver:+254702163459 target:admin
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 incoming__recvsms_intercept # pv end
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 recvsms_process # dt:2015-12-02 16:50:20 sender:+254702163459 m:@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00 receiver:+254702163459 smsc:
- - 2015-12-02 16:50:20 PID565f2104547f4 - L3 recvsms_process # intercepted datetime:2015-12-02 16:50:20 sender:+254702163459 receiver:+254702163459 message:@admin JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00
From what I can tell playSMS only reads the first word as a keyword. Trying to come up with a solution. So this is what I did
Change sms_command keyword to - mpesa
Route incoming sms >
: Pre Rules
Then sms_command picks up keyword and forwards the sandbox payload to script
./mpesa_topup.sh {CUSTOMRAW}
My script content
curl --data “receipt=$1&username=$9” http://127.0.0.1/topup/process.php
Example from above received sms
curl --data “receipt=JJA88QHC2I&username=254712345678” http://127.0.0.1/topup/process.php
But I just discovered sandbox payload sends alot of data so the bash script can’t extract the data.
Help Anton
anton
December 3, 2015, 12:19am
3
It ran that command, what do you mean by 2nd SMS ?
anton
anton
December 3, 2015, 12:25am
4
See this:
// sandbox forward to URL
if ($url = trim($post_rules['forward_to_url'])) {
$payload = array(
'datetime' => core_get_datetime(),
'sms_datetime' => $sms_datetime,
'sms_sender' => $sms_sender,
'message' => $message,
'sms_receiver' => $sms_receiver,
'smsc' => $smsc
);
$json = json_encode($payload);
$url = str_replace('{SANDBOX_PAYLOAD}', urlencode($json), $url);
$url = str_replace('{SANDBOX_DATETIME}', urlencode($sms_datetime), $url);
$url = str_replace('{SANDBOX_SENDER}', urlencode($sms_sender), $url);
$url = str_replace('{SANDBOX_MESSAGE}', urlencode($message), $url);
$url = str_replace('{SANDBOX_RECEIVER}', urlencode($sms_receiver), $url);
$url = str_replace('{SANDBOX_SMSC}', urlencode($smsc), $url);
_log("sandbox forward to URL start url:[" . $url . "]", 3, 'incoming recvsms_intercept_after');
$response = @file_get_contents($url);
_log("sandbox forward to URL end response:[" . $response . "]", 3, 'incoming recvsms_intercept_after');
This file has been truncated. show original
You can use other specific parameter like {SANDBOX_MESSAGE}
if you want to, not just {SANDBOX_PAYLOAD}
.
{SANDBOX_PAYLOAD}
is json of all other sanbox’s parameters.
Btw, its {SANDBOX_PAYLOAD}
not {SANDBOXPAYLOAD}
.
anton
Second message on the log near the bottom
JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00
Thaats the kind of message that will be coming in
anton
December 3, 2015, 6:35am
6
sorry man its too cryptic for me to read, can you re-post what exactly the problem, separate them correctly
anton
This is the type of message I will be receiving in that exact format
JJA88QHC2I Confirmed.on 10/10/15 at 9:49 PMKsh25.00 received from 25412345678 SOME BODY.New Account balance is Ksh25.00
I want playsms to to read one of the words like a keyword then forward to sms_command.
My bash script reads the first word (receipt number) and ninth word (payee phone number) and fowards them to the php script. But playsms is not retrieving keywords from the text ( balance ) . So I’m asking can playsms pick up a keyword from the middle of the sentence or does it have to be at the beginning
anton
December 3, 2015, 6:46am
8
ic so thats the question.
no, keyword is always the first word of SMS.
anton
So my solution is working but only half way. I used {CUSTOMPARAM} so that only the message after the keyword was forwared to the script, but i noticed playsms adds single quotes to sms.
‘mesage’ instead of just message
So now my simple script reacts the entire message as only one positional parameter. Is it possible to remove the quotes so I get the following;
./mpesa_topup.sh JJA88QHC22 Confirmed.on 101015 at 9:49 PMKsh25.00 received from 254712345678 SOME BODY.New Account balance is Ksh25.00
Instead of
./mpesa_topup.sh ‘JJA88QHC22 Confirmed.on 101015 at 9:49 PMKsh25.00 received from 254712345678 SOMW BODY.New Account balance is Ksh25.00’
anton
December 3, 2015, 2:52pm
10
no its not possible, but you should not worry about that too, I’m sure theres a way to handle that on bash script.
btw, why not just directly forward to mpesa_topup.php for example ? instead of passing back to playSMS and enter sms command
anton
mymanga
December 3, 2015, 2:57pm
11
I am not a programmer just using google to get me by… Don’t know how to write php code to do that…even my bash script is very simplistic.
!/bin/bash
curl --request POST ‘http://127.0.0.1/user//topup/process.php ’ --data “receipt=$1” --data “username=$9”
anton
December 3, 2015, 3:05pm
12
ok, is there any reason why not just forward to process.php
from route incoming sms (sandbox) ?
anton
mymanga
December 3, 2015, 3:09pm
13
I’m using an existing sytem…that process.php only looks for two fields from post data. receipt and username . Thats why i was using bash, I can separate the SMS with positional parameters to forward the data