Working SMS Integration

Status
Not open for further replies.

codemonkey76

New Member
May 14, 2020
22
1
3
47
Does this work for integrating with Plivo, I installed the app, but I see that in the settings there is a plivo_api_url but no plivo_auth_id or plivo_auth_token
 
Jan 9, 2018
140
12
18
54
Does this work for integrating with Plivo, I installed the app, but I see that in the settings there is a plivo_api_url but no plivo_auth_id or plivo_auth_token
Disclaimer: I do not use that carrier and didn't write that section of code that handles Plivo, so I can't vouch for it.

It looks like you could manually add a default setting for plivo_access_key and plivo_secret_key (category=sms, type=text), and populate them with the auth ID and auth token in those two, respectively. (I suspect that the person who added that carrier just failed to have those two settings built in the code.)

If you don't want to do this, you could edit the /app/sms/index.lua (mine is in /usr/share/freeswitch/scripts/app/sms/) and hard-code those in the plivo section. But I really would recommend the first option.
 

afshin

New Member
Oct 29, 2018
24
3
3
Hello, I have installed sms app , created a new file sms_hook_telephonica.php . added new career in default setting . I can receive inbound sms but
to consider the message accepted, I must emit an HTTP “200 OK” reply with a text/html document that consists of the string “ok” . This completes the message handoff.
How can I reply with OK message after receiving inbound sms ? Where I have to add the code ?
This is my sms hook and I appreciate any feedback :

<?php

include "../root.php";

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

if(check_acl()) {
if ($debug) {
error_log('[SMS] REQUEST: ' . print_r($_REQUEST, true));
}
route_and_send_sms($_POST['from'], $_POST['to'], $_POST['msg']);
} else {
error_log('ACCESS DENIED [SMS]: ' . print_r($_SERVER['REMOTE_ADDR'], true));
die("access denied");
}
?>
 
Jan 9, 2018
140
12
18
54
Check your nginx logs, but it's probably already replying with a HTTP 200 code. If so, maybe add an
PHP:
echo "ok";
before the "route_and_send_sms"?

If it's not replying with a HTTP 200, have a look here for info on that.
 
  • Like
Reactions: afshin

afshin

New Member
Oct 29, 2018
24
3
3
Thank you@Jonathan Black , yes echo "ok"; after or before "route_and_send_sms" does the job for me , I really appreciate your help !
 

mak_make

Member
Aug 27, 2018
50
0
6
41
Hi,

I am working on the SMS integration with bandwidth and I am having issues with inbound messaging. I have crated separate tread on it and below is the like for the tread:


If you people had any suggestion to fix my issue would be lot helpful to me.
 

taptech

Member
Mar 6, 2017
50
10
8
Has anyone gotten this to work using thinQ? I'm mostly concerned with inbound SMS and having difficulty.
 
Jan 9, 2018
140
12
18
54
Has anyone gotten this to work using thinQ? I'm mostly concerned with inbound SMS and having difficulty.
Might be best to start a new thread and just link to it here. If you do, please include details on what you have tried, and what exactly is or is not happening (Does thinQ show the receipt of the message? Do they show errors? Does the message get delivered to the endpoint but doesn't look right? etc.) It also helps to include (sanitized) log results from your /var/log/nginx/error.log.
In general, while I do not use thinQ, someone added it to the integration several years ago and theoretically it worked at that time. It'll just be a matter of debugging.
 

taptech

Member
Mar 6, 2017
50
10
8
Might be best to start a new thread and just link to it here. If you do, please include details on what you have tried, and what exactly is or is not happening (Does thinQ show the receipt of the message? Do they show errors? Does the message get delivered to the endpoint but doesn't look right? etc.) It also helps to include (sanitized) log results from your /var/log/nginx/error.log.
In general, while I do not use thinQ, someone added it to the integration several years ago and theoretically it worked at that time. It'll just be a matter of debugging.
Great, I will do just that!
 

taptech

Member
Mar 6, 2017
50
10
8
I made the post, and feel silly. As I was typing it I tailed the log that you posted, and it was pretty obvious that the sending IP was not in the ACL! It works now! THANK YOU!!
 

Deezer

New Member
Aug 6, 2021
8
1
3
36
I am trying to get MMS working. However whenever the email is sent it seems the headers are being sent in the body and I am receiving what I believe is the base64 encoded data for the attachment. This is what comes through in my email, followed by the base64 data. Any ideas on where I can look or what to change?

Msg: MMS Message received, see attachment--
==Multipart_Boundary_x33841fa48df5ecbc2f23291f4780c374x
Content-Type: image/jpeg;
name = "0035894183d467fde82b2795989375c5ad1fa17538a3b0388f15b76c1a7cf968.jpeg"
Content-Disposition: inline;
filename = "0035894183d467fde82b2795989375c5ad1fa17538a3b0388f15b76c1a7cf968.jpeg"
Content-Transfer-Encoding:base64
 
Jan 9, 2018
140
12
18
54
I am trying to get MMS working. However whenever the email is sent it seems the headers are being sent in the body and I am receiving what I believe is the base64 encoded data for the attachment. This is what comes through in my email, followed by the base64 data. Any ideas on where I can look or what to change?
I'm assuming this is not for Telnyx, since that is fully tested? I'm not sure how much I can help, but here goes:

It sound like you have something not quite right in file sms_email.php, in the "if ($carrier == "<your_carrier_name>") block.

I would look closely at the way you are setting the $email_message value. I suspect you are missing this line, towards the top of that block and before the "for" loop:
PHP:
                $email_message = "This is a multi-part message in MIME format.\n\n" .
                    "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                    "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";

In this same file, close to the top of the send_sms_to_email function, you can also put in a "$debug = true;". Then check your nginx error log to see the output from the $email_message and make sure it has everything in it should. It will probably truncate output, which is why I usually leave $debug = false;.
 

Deezer

New Member
Aug 6, 2021
8
1
3
36
I'm assuming this is not for Telnyx, since that is fully tested? I'm not sure how much I can help, but here goes:

It sound like you have something not quite right in file sms_email.php, in the "if ($carrier == "<your_carrier_name>") block.

I would look closely at the way you are setting the $email_message value. I suspect you are missing this line, towards the top of that block and before the "for" loop:
PHP:
                $email_message = "This is a multi-part message in MIME format.\n\n" .
                    "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                    "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";

In this same file, close to the top of the send_sms_to_email function, you can also put in a "$debug = true;". Then check your nginx error log to see the output from the $email_message and make sure it has everything in it should. It will probably truncate output, which is why I usually leave $debug = false;.
Thank you for the insight. It is for Telnyx. I will double check the email_value and test tonight when I have a chance, however I have not made any edits after following the GitHub install instructions.
 

Deezer

New Member
Aug 6, 2021
8
1
3
36
This is the code block I have after your suggested edit, it was $email_message = "" . $email_txt . "";.

This is what I receive in the body of the email, followed by the base64 encoded data. Also, the attachment is Untitled.html. I tried adding $debug=true before and after global $db, $debug, $domain_uuid, $domain_name, $carrier; but nothing showed up in the NGINX logs.

This is a multi-part message in MIME format.

--==Multipart_Boundary_x33c05de0b6444c2db86b899d0dc8c512x
Content-Type:text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 7bit

To: 9XXXXXXXXMsg: MMS Message received, see attachment

--==Multipart_Boundary_x33c05de0b6444c2db86b899d0dc8c512x
Content-Type: image/jpeg;
name = "0035894183d467fde82b2795989375c5ad1fa17538a3b0388f15b76c1a7cf968.jpeg"
Content-Disposition: inline;
filename = "0035894183d467fde82b2795989375c5ad1fa17538a3b0388f15b76c1a7cf968.jpeg"
Content-Transfer-Encoding:base64

PHP:
if ($carrier == "telnyx") {
            if (gettype($media)=="array") {
                $email_txt = 'To: ' . $to . '<br>Msg: ' . $body . '<br>MMS Message received, see attachment';

                $email_message = "This is a multi-part message in MIME format.\n\n" .
                                "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                                "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";
                //process MMS attachment
                foreach ($media as $attachment) {
                    $url = $attachment->url;
                    $start = strrpos($url, '/') == -1 ? strrpos($url, '//') : strrpos($url, '/')+1;
                    $fileatt_name = substr($url, $start, strlen($url)); // Filename that will be used for the file as the attachment
                    if (!empty($_SESSION['sms']['mms_attachment_temp_path']['text'])) {
                        $fileatt = $_SESSION['sms']['mms_attachment_temp_path']['text'];
                        if (substr($fileatt, -1) != '/') {
                            $fileatt .= '/';
                        }
                        $fileatt .= $fileatt_name;
                    }
                    else {
                        $fileatt = '/var/www/fusionpbx/app/sms/tmp/' . $fileatt_name; // Path to the file
                    }

                    // download attachment
                    file_put_contents($fileatt, fopen($url, 'r'));

                    //$fileatt_type = "application/octet-stream"; // File Type
                    $fileatt_type = $attachment->content_type; // File Type

                    //$start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;

                    $file = fopen($fileatt,'rb');
                    $attdata = fread($file,filesize($fileatt));
                    fclose($file);


                    $attdata = chunk_split(base64_encode($attdata));

                    $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" .
                        " name = \"{$fileatt_name}\"\n" . "Content-Disposition: inline;\n" . " filename = \"{$fileatt_name}\"\n" .
                        "Content-Transfer-Encoding:base64\n\n" . $attdata . "\n\n" . "--{$mime_boundary}--\n";
                    error_log("email_message: " . $email_message);
                    unlink($fileatt); // delete a file after attachment sent.
                }
            }
        }
 
Jan 9, 2018
140
12
18
54
This is the code block I have after your suggested edit, it was $email_message = "" . $email_txt . "";.

This is what I receive in the body of the email, followed by the base64 encoded data. Also, the attachment is Untitled.html. I tried adding $debug=true before and after global $db, $debug, $domain_uuid, $domain_name, $carrier; but nothing showed up in the NGINX logs.



PHP:
if ($carrier == "telnyx") {
            if (gettype($media)=="array") {
                $email_txt = 'To: ' . $to . '<br>Msg: ' . $body . '<br>MMS Message received, see attachment';

                $email_message = "This is a multi-part message in MIME format.\n\n" .
                                "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                                "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";
                //process MMS attachment
                foreach ($media as $attachment) {
                    $url = $attachment->url;
                    $start = strrpos($url, '/') == -1 ? strrpos($url, '//') : strrpos($url, '/')+1;
                    $fileatt_name = substr($url, $start, strlen($url)); // Filename that will be used for the file as the attachment
                    if (!empty($_SESSION['sms']['mms_attachment_temp_path']['text'])) {
                        $fileatt = $_SESSION['sms']['mms_attachment_temp_path']['text'];
                        if (substr($fileatt, -1) != '/') {
                            $fileatt .= '/';
                        }
                        $fileatt .= $fileatt_name;
                    }
                    else {
                        $fileatt = '/var/www/fusionpbx/app/sms/tmp/' . $fileatt_name; // Path to the file
                    }

                    // download attachment
                    file_put_contents($fileatt, fopen($url, 'r'));

                    //$fileatt_type = "application/octet-stream"; // File Type
                    $fileatt_type = $attachment->content_type; // File Type

                    //$start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;

                    $file = fopen($fileatt,'rb');
                    $attdata = fread($file,filesize($fileatt));
                    fclose($file);


                    $attdata = chunk_split(base64_encode($attdata));

                    $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" .
                        " name = \"{$fileatt_name}\"\n" . "Content-Disposition: inline;\n" . " filename = \"{$fileatt_name}\"\n" .
                        "Content-Transfer-Encoding:base64\n\n" . $attdata . "\n\n" . "--{$mime_boundary}--\n";
                    error_log("email_message: " . $email_message);
                    unlink($fileatt); // delete a file after attachment sent.
                }
            }
        }
Looks like you are missing a line at the bottom. It's the "$email_message .=" line.
PHP:
...
                    unlink($fileatt); // delete a file after attachment sent.
                }
                $email_message .= "--{$mime_boundary}--\n";
            }
        }
...
 

hamagid

Member
Dec 14, 2020
71
6
8
33
This is the code block I have after your suggested edit, it was $email_message = "" . $email_txt . "";.

This is what I receive in the body of the email, followed by the base64 encoded data. Also, the attachment is Untitled.html. I tried adding $debug=true before and after global $db, $debug, $domain_uuid, $domain_name, $carrier; but nothing showed up in the NGINX logs.



PHP:
if ($carrier == "telnyx") {
            if (gettype($media)=="array") {
                $email_txt = 'To: ' . $to . '<br>Msg: ' . $body . '<br>MMS Message received, see attachment';

                $email_message = "This is a multi-part message in MIME format.\n\n" .
                                "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                                "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";
                //process MMS attachment
                foreach ($media as $attachment) {
                    $url = $attachment->url;
                    $start = strrpos($url, '/') == -1 ? strrpos($url, '//') : strrpos($url, '/')+1;
                    $fileatt_name = substr($url, $start, strlen($url)); // Filename that will be used for the file as the attachment
                    if (!empty($_SESSION['sms']['mms_attachment_temp_path']['text'])) {
                        $fileatt = $_SESSION['sms']['mms_attachment_temp_path']['text'];
                        if (substr($fileatt, -1) != '/') {
                            $fileatt .= '/';
                        }
                        $fileatt .= $fileatt_name;
                    }
                    else {
                        $fileatt = '/var/www/fusionpbx/app/sms/tmp/' . $fileatt_name; // Path to the file
                    }

                    // download attachment
                    file_put_contents($fileatt, fopen($url, 'r'));

                    //$fileatt_type = "application/octet-stream"; // File Type
                    $fileatt_type = $attachment->content_type; // File Type

                    //$start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;

                    $file = fopen($fileatt,'rb');
                    $attdata = fread($file,filesize($fileatt));
                    fclose($file);


                    $attdata = chunk_split(base64_encode($attdata));

                    $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" .
                        " name = \"{$fileatt_name}\"\n" . "Content-Disposition: inline;\n" . " filename = \"{$fileatt_name}\"\n" .
                        "Content-Transfer-Encoding:base64\n\n" . $attdata . "\n\n" . "--{$mime_boundary}--\n";
                    error_log("email_message: " . $email_message);
                    unlink($fileatt); // delete a file after attachment sent.
                }
            }
        }
Have you got it to work?

I have the same issue, everything is fine, i'm just getting the email as base64 text rather than that attachment.

I have tried to edit sms_email.php as suggested here, but i'm still not getting the attachments.
 
Jan 9, 2018
140
12
18
54
Here is the entire Telnyx block from the sms_email.php file. This one is currently working:

PHP:
        if ($carrier == "telnyx") {
            if (gettype($media)=="array" && count($media)>0) {
                $email_txt = 'To: ' . $to . '<br>Msg: ' . $body . '<br>MMS Message received, see attachment';

                $email_message = "This is a multi-part message in MIME format.\n\n" .
                    "--{$mime_boundary}\n" . "Content-Type:text/html; charset = \"iso-8859-1\"\n" .
                    "Content-Transfer-Encoding: 7bit\n\n" .    $email_txt . "\n\n";
                //process MMS attachment
                for ($x = 0; $x < count($media); $x++) {
                    $url = $media[$x]->url;
                    $start = strrpos($url, '/') == -1 ? strrpos($url, '//') : strrpos($url, '/')+1;
                    $fileatt_name = substr($url, $start, strlen($url)); // Filename that will be used for the file as the attachment
                    if (!empty($_SESSION['sms']['mms_attachment_temp_path']['text'])) {
                        $fileatt = $_SESSION['sms']['mms_attachment_temp_path']['text'];
                        if (substr($fileatt, -1) != '/') {
                            $fileatt .= '/';
                        }
                        $fileatt .= $fileatt_name;
                    }
                    else {
                        $fileatt = '/var/www/fusionpbx/app/sms/tmp/' . $fileatt_name; // Path to the file
                    }
                    if ($debug) {
                        error_log("fileatt path: " . $fileatt);
                    }

                    // download attachment
                    file_put_contents($fileatt, fopen($url, 'r'));

                    $fileatt_type = $media[$x]->content_type; // File Type


                    $file = fopen($fileatt,'rb');
                    $attdata = fread($file,filesize($fileatt));
                    fclose($file);


                    $attdata = chunk_split(base64_encode($attdata));

                    $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" .
                        " name = \"{$fileatt_name}\"\n" . "Content-Disposition: inline;\n" . " filename = \"{$fileatt_name}\"\n" .
                        "Content-Transfer-Encoding:base64\n\n" . $attdata . "\n\n" ;
                    //error_log("email_message: " . $email_message);
                    unlink($fileatt); // delete a file after attachment sent.
                }
                $email_message .= "--{$mime_boundary}--\n";
            }
        }

Note that I've had some requests from customers for an option that will only send email when there is an attachment. This would be easy enough to change globally, but when I get time, I'd like to pursue a toggle to set this, probably at the SMS destination (phone number) level.
 
Status
Not open for further replies.