FusionPBX SMS Integration with Bandwidth

Status
Not open for further replies.
Jan 9, 2018
152
16
18
54
@Jonathan Black Thanks for the info. Right know I am not trying to implement the Broadcast. I saw the option so got curious how it will work.
As I said previously, there is no Broadcast option related to SMS. The Applications->Call Broadcast page is for phone call broadcasts, not SMS.

We've looked into PlaySMS (playsms.org) as a dedicated SMS broadcast and interactive SMS application platform.
 

mak_make

Member
Aug 27, 2018
53
0
6
42
Hi, @Jonathan Black I am working on the MMS thing with Bandwidth and when I send MMS then I was able to get partial URL from Bandwidth on Access.log. And I get an SMS like MMS message received, see email for attachment.

The Email I receive is blank. below is the sms_hook_Bandwith.php I have in the server:

PHP:
<?php

include "../root.php";

require_once "resources/require.php";
require_once "../sms_hook_common.php";

if ($debug) {
    error_log('[SMS] REQUEST: ' .  print_r($_SERVER, true));
}

if (check_acl()) {
    if  ($_SERVER['CONTENT_TYPE'] == 'application/json; charset=utf-8') {
        $data = json_decode(file_get_contents("php://input"));
        if ($debug) {
            error_log('[SMS] REQUEST: ' .  print_r($data, true));
        }
        route_and_send_sms($data[0]->message->from, $data[0]->to, $data[0]->message->text, $data[0]->message->media);
   
    } else {
        error_log('[SMS] REQUEST: No SMS Data Received');
        die("no");
    }
} else {
    error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
    die("access denied");
}
?>

Below is the error.log
PHP message: [SMS] REQUEST: Array
(
[0] => stdClass Object
(
[time] => 2021-08-24T18:50:35.315Z
[type] => message-received
[to] => receiver number
[description] => Incoming message received
[message] => stdClass Object
(
[id] => fa31054b-7477-4557-bedc-998f2dcf12fb
[owner] => receiver number
[applicationId] => XXXXXXXXXXXXXXXXXXX
[time] => 2021-08-24T18:50:34.412Z
[segmentCount] => 1
[direction] => in
[to] => Array
(
[0] => receiver number
)

[from] => +sender number
[text] =>
[media] => Array
(
[0] => https://messaging.bandwi

Is there anything I need to change in sms_email.php to get the URL for MMS?
 
Jan 9, 2018
152
16
18
54
Hi, @Jonathan Black I am working on the MMS thing with Bandwidth and when I send MMS then I was able to get partial URL from Bandwidth on Access.log. And I get an SMS like MMS message received, see email for attachment.

The Email I receive is blank. below is the sms_hook_Bandwith.php I have in the server:

<snip>

Is there anything I need to change in sms_email.php to get the URL for MMS?
Ok, so the URL for the attachment is probably coming through intact. It's just getting truncated in the log. There is a buffer length problem with the logging, and I've just never had the motivation to go solve it. But you can probably add the following line to the if ($debug) block in your sms_hook_bandwitdth.php, to see that part of the request from Bandwidth:
PHP:
error_log('[SMS] REQUEST-MEDIA: ' .  print_r($data[0]->message->media, true));
(If it is still truncating, temporarily comment out the other "error_log" line.)
That should let you see the media array contents, including the URL.

Now, to actually do something with it: You are correct. In sms_email.php, you will need to add a section to process the MMS attachment for your carrier. I added MMS handling for the one carrier that I am using (Telnyx), but you'll need to add a block to handle it for Bandwidth.

If you look in sms_email.php, you'll see a block starting with
PHP:
if ($carrier == "telnyx") {
There are about 50 lines of code in this block. So go down to just before
Code:
        else {
            $email_message .= "--{$mime_boundary}--\n";
        }
and insert an
PHP:
elseif ($carrier == "bandwidth") {

Then copy that block of code from the Telnyx section into this. And then you'll need to edit it to match the layout of Bandwidth's media array.

Note that in the Telnyx section, I'm actually downloading the file from the URL, saving out to a specific folder on the server, and THEN attaching it to the email. This may not be the best way to do it, but it does work. So if you use this method, you'll need to make sure that the folder exists on the server.
 

mak_make

Member
Aug 27, 2018
53
0
6
42
Hi @Jonathan Black,

My mistake, I have commented out the error_log and now I can see the URL in the error.log, but I get an empty email I guess I have to play around with sms_email.php to get it downloaded and forwarded to an email.
 
Status
Not open for further replies.