Halea
Well-Known Member
- Joined
- Aug 12, 2016
- Messages
- 1,132
- Reaction score
- 874
I've just finished testing the php script shown below. It works quite well. It basically takes an incoming sms message and sends it out to a forwarding number.
There are some limitations that you should be aware of:
1) It only works on BulkVS DIDs which are SMS enabled.
2) The forwarded message shows the original target phone number as BulkVS doesn't allow spoofing the original source sms phone number during the re-transmission.
This is a significant annoyance if the forwarded SMS needs to be replied to with the intention of reaching the original sender, but not so much of a problem if it's mostly used for two factor authentication codes etc. which do not require a reply.
Then you need to configure your BulkVS DID which needs to be forwarded to the 11 digit phone number entered in the script. For that you would login into your BulkVS panel and go to Messaging > Message Webhooks. There, you can create a new hook in which you will use a URL like http://<yourPBXserver.com>/sms-rx-json-fwding.php assuming that you called your script file as suggested earlier. (You should also adjust your server name, adjust the TCP port number if it's different from 80, use https instead of http if you're using SSL on your server, etc.)
Oh! also, at that stage make sure that Delivery Receipt for that particular webhook is set to False.
Finally you would go to Inbound > DIDs - Manage and pick the DID that you want to configure, and set its Messaging Webhook value to the entry that you've just created in the previous step.
The php script gets triggered every time a message is sent via the URL defined in the webhook. So there is no need to run a periodic process starter like cron etc.
Please note that the forwarded message will include the original source phone number (Fr), the original target phone number (To) and the forwarding phone number (Fw) so that there is no doubt about the whereabouts of the message.
Regarding the phone number spoofing issue I'll contact BulkVS tomorrow morning and see if there is anything that can be done. Meanwhile if anyone here has any suggestions please let me know.
Update 8/30/2021 : There is an enhanced version of this script which can do both sms emailing and forwarding to another phone number simultaneously. The new script called sms-rx-jef.php can be found here.
There are some limitations that you should be aware of:
1) It only works on BulkVS DIDs which are SMS enabled.
2) The forwarded message shows the original target phone number as BulkVS doesn't allow spoofing the original source sms phone number during the re-transmission.
This is a significant annoyance if the forwarded SMS needs to be replied to with the intention of reaching the original sender, but not so much of a problem if it's mostly used for two factor authentication codes etc. which do not require a reply.
To make this work on your PBX you simply need to put the above script in a text file under /var/www/html that you could name sms-rx-json-fwding.php assuming that you already have curl and php5-curl installed and enabled. Obviously you would need to enter the proper values for XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY and <YOUR_11_DIGIT_PHONE_NUMBER_FOR_FORWARDING_HERE>.<?php
/*
This is sms-rx-json-fwding.php, a tiny script from Halea, for the purpose of forwarding SMS messages
received on a BulkVS DID to another phone number through BulkVS' sms transmission service.
This script makes use of BulkVS' new JSON type incoming SMS payload (received with a POST URL),
which has the following components:
{
"From" : "(FROM NUMBER)",
"To" : [ "(TO NUMBER)" ],
"Message" : "(UPTO-160-CHARACTER-MESSAGE)"
}
Note that this script will only work if curl and php5-curl are both installed and enabled with the following:
sudo apt-get install curl
sudo apt-get install php5-curl
sudo php5enmod curl
sudo service apache2 restart
*/
# === PRIVATE DATA SECTION ==========================================
# BulkVS SMS Transmission Service Personal Parameters:
$BulkvsSmsTransmitterUrl = "https://portal.bulkvs.com/sendSMS";
$BulkvsPersonalApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$BulkvsPersonalApiSecret = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
# Forwarding phone number definition:
$fwd_to_phone = "<YOUR_11_DIGIT_PHONE_NUMBER_FOR_FORWARDING_HERE>";
# === END OF PRIVATE DATA SECTION ====================================
// Let's take the raw data from the request, aka POST URL:
$json = file_get_contents('php://input');
// Let's convert it into a PHP object:
$data = json_decode($json);
// Let's feed the JSON data into our variables:
$ori_fr_phone = $data->From;
$ori_to_phone = $data->To[0];
# curl command execution via curl php - works well:
$ch = curl_init( $BulkvsSmsTransmitterUrl );
# Let's determine payload for the outgoing sms:
$sms_text = "(Fr:".$ori_fr_phone."/To:".$ori_to_phone."/Fw:".$fwd_to_phone.") ".urldecode($data->Message);
$payload = json_encode( array( "apikey" => $BulkvsPersonalApiKey,
"apisecret" => $BulkvsPersonalApiSecret,
"from" => $ori_to_phone,
"to" => $fwd_to_phone,
"message" => $sms_text,
) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
# The following feedback is per BulkVS SMS gateway expectations and should not be removed,
# otherwise there is a risk that the same incoming sms would be transmitted again.
echo "OK";
?>
Then you need to configure your BulkVS DID which needs to be forwarded to the 11 digit phone number entered in the script. For that you would login into your BulkVS panel and go to Messaging > Message Webhooks. There, you can create a new hook in which you will use a URL like http://<yourPBXserver.com>/sms-rx-json-fwding.php assuming that you called your script file as suggested earlier. (You should also adjust your server name, adjust the TCP port number if it's different from 80, use https instead of http if you're using SSL on your server, etc.)
Oh! also, at that stage make sure that Delivery Receipt for that particular webhook is set to False.
Finally you would go to Inbound > DIDs - Manage and pick the DID that you want to configure, and set its Messaging Webhook value to the entry that you've just created in the previous step.
The php script gets triggered every time a message is sent via the URL defined in the webhook. So there is no need to run a periodic process starter like cron etc.
Please note that the forwarded message will include the original source phone number (Fr), the original target phone number (To) and the forwarding phone number (Fw) so that there is no doubt about the whereabouts of the message.
Regarding the phone number spoofing issue I'll contact BulkVS tomorrow morning and see if there is anything that can be done. Meanwhile if anyone here has any suggestions please let me know.
Update 8/30/2021 : There is an enhanced version of this script which can do both sms emailing and forwarding to another phone number simultaneously. The new script called sms-rx-jef.php can be found here.
Last edited:

