Working SMS Integration

Status
Not open for further replies.
Jan 9, 2018
152
16
18
54
We started attempting to add SMS support to our FusionPBX configuration a couple of months ago and found conflicting information online. This link started me down the right path, but gives some bad information--such as, I found that the information given by Caleb was outdated. And the comments by Yukon on that original one are outdated as well. I don't know this for sure, but it appears that sometime in the past, someone has worked to implement some of the Flowroute code into the SMS app and make it work in general for multiple carriers.

I just followed the directions at https://github.com/fusionpbx/fusionpbx-apps/tree/master/sms. Unfortunately, it wouldn't work. I stuck with it, found and fixed some bugs and here's the result:

First, we're on version 4.2.4, so not the newest version, but still newer than what some of those links were talking about.
Second, I just downloaded the Github code on 8/23/2018, so it is current as of this writing. If you find this later and it has been updated after that time, these instructions may not apply.
Third, what is on Github is broken. I am brand new to Github, but I have submitted the changes below back to the project. I'm including them below, along with an explanation, in case I've done something wrong and they do not get accepted.
Fourth, contrary to what is mentioned in some of the comments in that first link above, the SMS app code above from Github, with the relatively minor fixes I'll detail below, will give you SIP SIMPLE to SMS gateway integration. There are a few caveats, but I'll spell it out: it works to send from SIP-registered extension to Freeswitch which passes it via FusionPBX script to carrier to cell phone and then the reverse. Kudos to all the contributors!

Here are the caveats:
  1. From what I can tell, sending media beyond text (pictures, sound, video) is not supported. So no MMS.
  2. Zoiper seems to have a problem with sending. Like really bad! When I tried sending from Zoiper to a cell phone, it duplicated the message over 130 times. I haven't tracked down this problem yet. An older version of Linphone (3.x) seems to have a similar problem.
However, it works fine and we've tested it on:
  • Groundwire iOS
  • Grandstream Wave iOs/Android
  • X-Lite (desktop)
  • Yealink/Grandstream desk phones
  • Linphone (4.1.1 Win32)

How to make SMS app work:

  1. Follow the installation steps from https://github.com/fusionpbx/fusionpbx-apps/tree/master/sms.
  2. I also had to manually copy the /sms folder from my install folder (which happens to be /var/www/html/app/sms/resources/install/scripts/app, into /usr/share/freeswitch/scripts/app, and set appropriate permissions as needed (same as other folders/files in that structure).
  3. In the SMS Lua script (ours is at /usr/share/freeswitch/scripts/app/sms/index.lua), search for //Get User_name and replace with --Get User_name. This should be in the carrier=="thinq" section. This is the big one that kept it from running at all.
If for some reason, you are still seeing something like
[ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/app.lua:48: attempt to call a nil value stack traceback: /usr/share/freeswitch/scripts/app.lua:48: in main chunk
Try running the following command from the fs_cli:
luarun /usr/share/freeswitch/scripts/app/sms/index.lua
This can give you some insight into any remaining errors or typos.

Remaining changes are to fix problems on specific carriers, to add carriers or for specific softphone support. They are optional.


How to make SMS work with Twilio - Please note that we used Twilio only as a test. I did get it working, but in order to do so, I had to remove the ACL check in the web hook for receiving messages. This is because they are now sending messages back from AWS and so they can come from IP addresses all over the place--you can't whitelist them all! In order to properly secure this, you would need to add the signature checking as detailed here. It's not something we're going to use. Good luck! However, I will detail the other item you'll need to change to make Twilio work:
  • In the SMS Lua script, look for -- Can be either +1NANNNNXXXX or NANNNNXXXX") then. This should be about line 244, and is in the Twilio-specific section. Immediately after this line and before the line that starts "cmd =...", put this line of code in:
api_url = string.gsub(api_url, "{ACCOUNTSID}", access_key);
This simply makes it so you only need to enter the access key once in your default settings. The code then inserts it into the api_url. This just makes it cleaner. (It kind of dawned on me after the fact that I could just edit the api_url and hard-code the access key into it, so you can do it either way. However, I'm not sure why this wasn't just written with variable replacements from the start.)​
  • In the "sms_hook_twilio.php" file (ours is at /var/www/html/app/sms/hook), you will need to add the signature checking mentioned above. If you want to temporarily get this working for test purposes, as we did, you can disable the IP checking as follows. I do NOT recommend this in production!
Replace: if (check_acl()) {if (1==1){ , with:
//if (check_acl()) { if (1==1){

How to make SMS work with Telnyx - We added support for this carrier. Unless you need to use this carrier, there is no reason you'll need to add this to your installation.
  • In the SMS Lua script, look for: cmd = "curl -X POST '" .. api_url .."' -H \"Content-Type:multipart/form-data\" Immediately after this line (and before the outdented "end" line, paste in the following (this should be at about line 278 in the original file):
Code:
        elseif (carrier == "telnyx") then
            if to:len() < 11 then
                to = "1" .. to;
            end
            if outbound_caller_id_number:len() < 11 then
                outbound_caller_id_number = "1" .. outbound_caller_id_number;
            end
            --Get delivery_status_webhook_url
            sql = "SELECT default_setting_value FROM v_default_settings ";
            sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = '" .. carrier .. "_delivery_status_webhook_url' and default_setting_enabled = 'true'";
            if (debug["sql"]) then
                freeswitch.consoleLog("notice", "[sms] SQL: "..sql.."; params:" .. json.encode(params) .. "\n");
            end
            status = dbh:query(sql, function(rows)
                delivery_status_webhook_url = rows["default_setting_value"];
            end);
            cmd ="curl -X POST \"" .. api_url .."\" -H \"Content-Type: application/json\"  -H \"x-profile-secret: " .. secret_key .. "\" -d '{\"from\": \"+" .. outbound_caller_id_number .. "\", \"to\": \"+" .. to .. "\", \"body\": \"" .. body .. "\", \"delivery_status_webhook_url\": \"" .. delivery_status_webhook_url .. "\"}'";
  • You'll need to add a "sms_hook_telnyx.php" file (ours is at /var/www/html/app/sms/hook), making sure it has appropriate permissions. Here are the contents:
PHP:
<?php

include "../root.php";

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

if (check_acl()) {
    if  ($_SERVER['CONTENT_TYPE'] == 'application/json') {
        $data = json_decode(file_get_contents("php://input"));
        if ($debug) {
            error_log('[SMS] REQUEST: ' .  print_r($data, true));
        }
        $to = intval(preg_replace('/(^[\+][1])/','', $data->to));
        route_and_send_sms($data->from, $to, $data->body);
    } else {
      die("no");
    }
} else {
    error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
    die("access denied");
}
?>

  • You'll need to add these new settings to Advanced/Default Settings. In the Sms section (Category: sms):
    • Subcategory: carriers, Type: array, Value: telnyx
    • Subcategory: telnyx_access_key, Type: text, Value: <blank> (actually, this one stays blank--it isn't used. Just adding it for consistency with the other carriers.)
    • Subcategory: telnyx_api_url, Type: text, Value: https://sms.telnyx.com/messages
    • Subcategory: telnyx_delivery_status_webhook_url, Type: text, Value: <see below>
    • Subcategory: telnyx_secret_key, Type: text, Value: <profile secret generated from Telnyx messaging account>
  • Of course, don't forget to add their IPs to the ACL under Advanced/Access Controls. I had to try a test, have it fail, look up the failure in ssl_error_log and see what address they were sending from.
  • You'll also need to add your webhook URL on Telnyx's site under the appropriate messaging profile. For Telnyx it should be: https://YOURDOMAIN/app/sms/hook/sms_hook_telnyx.php. And of course, make sure to assign the messaging profile to the phone number you are wanting to use.
The "telnyx_delivery_status_webhook_url" is where Telnyx will send any updates about delivery status of a message. Unless I'm missing something, there isn't any support in Fusion/Freeswitch for this, but in theory, you could create a second sms_hook_telnyx.php file to receive these. I just don't know what you would do with the info. I've included it for future reference/use. Here's info from Telnyx about what these contain.


Fixing formatting on sending from Groundwire - We noticed a sending problem on messages sent from the Groundwire softphone. It is inserting some extra headers into the body of the message. Here's some code to clean up formatting. I'm interested in knowing if anyone else has issues with Groundwire in this way. It's always been solid for us. Please note that the misspelling of "lenght" in the code is intentional--that's how it comes through in the header, at least on IOS. YMMV.

Two caveats: 1. There may be better ways to do this that I haven't thought of/don't know about--I'm pretty new to Lua programming. 2. There may be situations where this conflicts with something else. I did try to account for this with the checks in the code, but that's part of the reason I'm putting it out for more eyes on it.

  • In the SMS Lua script, look for body = message:getBody();, then skip the end line and insert the following before the if (debug["info"]) then line:
Code:
        --Clean body up for Groundwire send
        smsraw = body;
        smstempst, smstempend = string.find(smsraw, 'Content%-lenght:');
        if (smstempend == nil) then
            body = smsraw;
        else
            smst2st, smst2end = string.find(smsraw, '\r\n\r\n', smstempend);
            if (smst2end == nil) then
                body = smsraw;
            else
                body = string.sub(smsraw, smst2end + 1);
            end
        end

Additions to app_config.php:
If you are adding this to an existing installation, you may simply follow the directions above. However, the following additions will need to be made to the app_config.php to automate installations to include Telnyx.
PHP:
        $apps[$x]['default_settings'][$y]['default_setting_uuid'] = '9b36edac-eeac-4a3e-b8d4-664962e3f78c';
        $apps[$x]['default_settings'][$y]['default_setting_category'] = 'sms';
        $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'carriers';
        $apps[$x]['default_settings'][$y]['default_setting_name'] = 'array';
        $apps[$x]['default_settings'][$y]['default_setting_value'] = 'telnyx';
        $apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'true';
        $apps[$x]['default_settings'][$y]['default_setting_description'] = '';
        $y++;
        $apps[$x]['default_settings'][$y]['default_setting_uuid'] = '2f246db7-eb07-4c2c-a752-e81466276c89';
        $apps[$x]['default_settings'][$y]['default_setting_category'] = 'sms';
        $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'telnyx_api_url';
        $apps[$x]['default_settings'][$y]['default_setting_name'] = 'text';
        $apps[$x]['default_settings'][$y]['default_setting_value'] = 'https://sms.telnyx.com/messages';
        $apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'false';
        $apps[$x]['default_settings'][$y]['default_setting_description'] = '';   
        $y++;   
        $apps[$x]['default_settings'][$y]['default_setting_uuid'] = '604c1f7c-e830-441d-9596-31c8d091f8c2';
        $apps[$x]['default_settings'][$y]['default_setting_category'] = 'sms';
        $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'telnyx_access_key';
        $apps[$x]['default_settings'][$y]['default_setting_name'] = 'text';
        $apps[$x]['default_settings'][$y]['default_setting_value'] = '';
        $apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'false';
        $apps[$x]['default_settings'][$y]['default_setting_description'] = '';       
        $y++;
        $apps[$x]['default_settings'][$y]['default_setting_uuid'] = 'abcd3f80-71c2-4b58-ae9d-3a37cb503faf';
        $apps[$x]['default_settings'][$y]['default_setting_category'] = 'sms';
        $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'telnyx_secret_key';
        $apps[$x]['default_settings'][$y]['default_setting_name'] = 'text';
        $apps[$x]['default_settings'][$y]['default_setting_value'] = '';
        $apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'false';
        $apps[$x]['default_settings'][$y]['default_setting_description'] = '';       
        $y++;
 

yukon

Member
Oct 3, 2016
138
14
18
Wow. Thanks for this! I'm the original author of the SMS app and was going to start doing some more development on it.. I want to add DIDWW as a carrier and fix some of the confusing setup. I'll try to work these things into it.

It is true you cannot send MMS, this is a limitation of most carriers. I thought about adding MMS to email support for the ones that do support MMS but never got around to it.
 
Jan 9, 2018
152
16
18
54
Wow. Thanks for this! I'm the original author of the SMS app and was going to start doing some more development on it.. I want to add DIDWW as a carrier and fix some of the confusing setup. I'll try to work these things into it.

It is true you cannot send MMS, this is a limitation of most carriers. I thought about adding MMS to email support for the ones that do support MMS but never got around to it.
Then we have you, in particular, to thank for the app! It's working well, and we have at least one other idea in mind as an enhancement.

FYI, my edits were accepted into the project on Github, so the above information is now mostly a reference/documentation for that pull request/commit. This is my first contribution to an open source project, so I was not aware of how it worked, whether it would be accepted, the time frame, and so on.
 

MTR

Member
Oct 25, 2017
181
9
18
45
i am on the master branch

i was able to install the SMS app

when i try to add a new destination number and hit save, nothing ha-pends i dont get an error the page just reloads it self
 

MTR

Member
Oct 25, 2017
181
9
18
45
i can see in access log that the site is loading all the right pages

i see nothing in the error log

any ideas where i can see any error ?
 
Jan 9, 2018
152
16
18
54
Sorry, I have been extremely busy, so I have not been able to keep up with submitting fixes that I have found for this code. Under your FusionPBX install in the SMS folder (ours is at /var/www/html/app/sms/) change the following:
In sms.php, along about line 84, look for an "else {" block.
change:
PHP:
    else {
        $order_text = "extension asc";
    }
to:
PHP:
    else {
        //$order_text = "extension asc"; //extension doesn't exist in this table 8/23/2018/jblack
        $order_text = "destination asc";
    }

This should get you going. Basically, what's happening is that it is getting added, but is just not showing on the page.


I have additional changes made, adding the separation of inbound routing for DIDs for SMS messages from the voice routing (basically, so that we can route SMS messages some place different from where voice calls route), but that requires some database changes and some changes in the lua script as well. It's not real "pretty" on the FusionPBX GUI, but it works.

Unfortunately, we're experiencing some very intermittent, but serious, overall problems with the FS SMS module that I'm trying to track down right now, so I haven't had time to package up these changes and submit them.
 

markjcrane

Active Member
Staff member
Jul 22, 2018
499
177
43
49
I couldn't get the app/sms working... well I could have if I was more motivated to but it was missing multiple things I wanted in an SMS app. Another thing I didn't want to take over the one by its original author. Seemed it would be nicer to let that persons continue development of what they created. I also didn't want the name to conflict. So it is called Messages and currently in the Master Branch. The development on it is still moving forward. FusionPBX will have a multiple options for SMS.
 

MTR

Member
Oct 25, 2017
181
9
18
45
I couldn't get the app/sms working... well I could have if I was more motivated to but it was missing multiple things I wanted in an SMS app. Another thing I didn't want to take over the one by its original author. Seemed it would be nicer to let that persons continue development of what they created. I also didn't want the name to conflict. So it is called Messages and currently in the Master Branch. The development on it is still moving forward. FusionPBX will have a multiple options for SMS.
You say it was missing multiple things that you want it to see
What are does missing things
 

MTR

Member
Oct 25, 2017
181
9
18
45
Sorry, I have been extremely busy, so I have not been able to keep up with submitting fixes that I have found for this code. Under your FusionPBX install in the SMS folder (ours is at /var/www/html/app/sms/) change the following:
In sms.php, along about line 84, look for an "else {" block.
change:
PHP:
    else {
        $order_text = "extension asc";
    }
to:
PHP:
    else {
        //$order_text = "extension asc"; //extension doesn't exist in this table 8/23/2018/jblack
        $order_text = "destination asc";
    }

This should get you going. Basically, what's happening is that it is getting added, but is just not showing on the page.


I have additional changes made, adding the separation of inbound routing for DIDs for SMS messages from the voice routing (basically, so that we can route SMS messages some place different from where voice calls route), but that requires some database changes and some changes in the lua script as well. It's not real "pretty" on the FusionPBX GUI, but it works.

Unfortunately, we're experiencing some very intermittent, but serious, overall problems with the FS SMS module that I'm trying to track down right now, so I haven't had time to package up these changes and submit them.
I changed the code and I still have the problem it did not resolve it
 

MTR

Member
Oct 25, 2017
181
9
18
45
I changed the code and I still have the problem it did not resolve it
Ok I did install it now on a 4.2 and it’s working I can add a DID will do full testing a report back

Also I wouldn’t Mind helping out on getting this to work on the master branch if you just give me a hint ?

I was not able to find any table named v_sms_
 
Jan 9, 2018
152
16
18
54
I'm currently running 4.2.4. Haven't tried on anything newer, so I don't know what any issues might be. The /app/sms/app_config.php contains the schema definition information to build the v_sms_* tables. This is what happens in the installation step when you do the "Upgrade -> Schema". It checks this file and compares it to your database and creates any missing schema elements.
 

MTR

Member
Oct 25, 2017
181
9
18
45
I'm currently running 4.2.4. Haven't tried on anything newer, so I don't know what any issues might be. The /app/sms/app_config.php contains the schema definition information to build the v_sms_* tables. This is what happens in the installation step when you do the "Upgrade -> Schema". It checks this file and compares it to your database and creates any missing schema elements.
thanks for the info i will review it and post back if when i find the bug
 

MTR

Member
Oct 25, 2017
181
9
18
45
Ok I did install it now on a 4.2 and it’s working I can add a DID will do full testing a report back

Also I wouldn’t Mind helping out on getting this to work on the master branch if you just give me a hint ?

I was not able to find any table named v_sms_
i was able to get this working on 4.2.4
i am still having 2 problems that i am trying to figure out

1. for a main number that the destination is set to an IVR how can we route the sms to an Ext?

2. every time we send a text we are getting a reply with XML data that the msg was delivered, why is that there? can we remove that auto responds .
 
Jan 9, 2018
152
16
18
54
1. The default implementation limits your inbound routing--your DID routing has to be to an extension or ring group and this is shared by both voice routing and SMS routing. We didn't like this limitation, so we built our own routing (I think I referenced this earlier) that splits out inbound routing for SMS. This allows you to route voice inbound one place (like IVR) and SMS to another (like extension or group).
2. This likely depends on your receiving client to handle it properly rather than display it incorrectly. I've done quite a bit of testing with about 6 or 8 softphone client apps and found that so far, only one of them displays it incorrectly. Most either ignore it, while a few change a status indicator on the message. So far, only Zoiper for iOS displays the XML content. (Even Zoiper for Android doesn't do this.) I've sent in a bug report to them, so we'll see what happens. If you have found another client app that also does this, you might do the same (and I would be interested to know about it).
FYI, we've successfully tested Grandstream Wave iOS/Android, Groundwire iOS/Android, Zoiper Android, Linphone, and then Grandstream and Yealink deskphones as well as some webRTC implementations both between each other as well as to cell phone.

Directly answering your question: can you filter out the auto-response? Maybe, but it would be dicey. Because (I believe) the issue is really a problem with the client app, much better to address it there. The issue is this: if it's happening between cell/SMS and softphone, then you MIGHT be able to catch it in the lua script, but I found it happening just between two softphone extensions. That's directly handled by the Freeswitch SMS module. The lua script isn't involved.
 

MTR

Member
Oct 25, 2017
181
9
18
45
1. The default implementation limits your inbound routing--your DID routing has to be to an extension or ring group and this is shared by both voice routing and SMS routing. We didn't like this limitation, so we built our own routing (I think I referenced this earlier) that splits out inbound routing for SMS. This allows you to route voice inbound one place (like IVR) and SMS to another (like extension or group).
2. This likely depends on your receiving client to handle it properly rather than display it incorrectly. I've done quite a bit of testing with about 6 or 8 softphone client apps and found that so far, only one of them displays it incorrectly. Most either ignore it, while a few change a status indicator on the message. So far, only Zoiper for iOS displays the XML content. (Even Zoiper for Android doesn't do this.) I've sent in a bug report to them, so we'll see what happens. If you have found another client app that also does this, you might do the same (and I would be interested to know about it).
FYI, we've successfully tested Grandstream Wave iOS/Android, Groundwire iOS/Android, Zoiper Android, Linphone, and then Grandstream and Yealink deskphones as well as some webRTC implementations both between each other as well as to cell phone.

Directly answering your question: can you filter out the auto-response? Maybe, but it would be dicey. Because (I believe) the issue is really a problem with the client app, much better to address it there. The issue is this: if it's happening between cell/SMS and softphone, then you MIGHT be able to catch it in the lua script, but I found it happening just between two softphone extensions. That's directly handled by the Freeswitch SMS module. The lua script isn't involved.
Can you share the code that will allow me to set an sms destination?

Also with the app I am fine, the problem is when an outside user sends sms rom him iPhone cell phone they will get the sms reply with xml data
 
Jan 9, 2018
152
16
18
54
Here are instructions on adding the separate routing for SMS. As I mentioned, I haven't had time to get back to this and make it as "pretty" as I'd like to. And fair warning, there are several changes to make! (Also, we are on 4.2.4. No guarantees on compatibility with future version until I have a chance to do testing.)


In /app/sms/app_config.php, at the very bottom, change:
PHP:
        $apps[$x]['db'][$y]['fields'][$z]['name'] = "description";
        $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
        $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
        $z++;

?>
To:
PHP:
        $apps[$x]['db'][$y]['fields'][$z]['name'] = "description";
        $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
        $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
        $z++;
        $apps[$x]['db'][$y]['fields'][$z]['name'] = "chatplan_detail_data";
        $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
        $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
        $z++;

?>

Run "Advanced ->Upgrade ->Schema". It would probably be good at this point to verify that it added the "chatplan_detail_data" field to your v_sms_destinations table.

There are several changes that need to be made to the sms_hook_common.php:
From (about line 56):
PHP:
                $from = intval($from);
                if ($debug) {
To:
PHP:
                $from = intval($from);
                $body = preg_replace('([\'])', '\\\'', $body); // escape apostrophes
                if ($debug) {

From (about line 62):
PHP:
                }


                if ($debug) {
To:
PHP:
                }

                // Check for chatplan_detail in sms_destinations table
                $sql = "select domain_name, ";
                $sql .= "chatplan_detail_data, ";
                $sql .= "v_sms_destinations.domain_uuid as domain_uuid ";
                $sql .= "from v_sms_destinations, ";
                $sql .= "v_domains ";
                $sql .= "where v_sms_destinations.domain_uuid = v_domains.domain_uuid";
                $sql .= " and destination like :to";
                $sql .= " and chatplan_detail_data <> ''";

                if ($debug) {

From (about line 81):
PHP:
                if (count($result) == 0) {
                    error_log("Cannot find a destination: " . print_r($result,true));
                    die("Invalid Destination");
                }
                foreach ($result as &$row) {
                    $domain_name = $row["domain_name"];
                    preg_match('/(\d{2,7})/',$row["dialplan_detail_data"],$match);
                    $domain_uuid = $row["domain_uuid"];
                    break; //limit to 1 row
                }
                unset ($prep_statement);

                if ($debug) {
To:
PHP:
                if (count($result) > 0) {
                    foreach ($result as &$row) {
                        $domain_name = $row["domain_name"];
                        preg_match('/(\d{2,7})/',$row["chatplan_detail_data"],$match);
                        $domain_uuid = $row["domain_uuid"];
                        break; //limit to 1 row
                    }
                }
                else { // Fall back to destinations table for backwards compatibility
                    $sql = "select domain_name, ";
                    $sql .= "dialplan_detail_data, ";
                    $sql .= "v_domains.domain_uuid as domain_uuid ";
                    $sql .= "from v_destinations, ";
                    $sql .= "v_dialplan_details, ";
                    $sql .= "v_domains ";
                    $sql .= "where v_destinations.dialplan_uuid = v_dialplan_details.dialplan_uuid ";
                    $sql .= "and v_destinations.domain_uuid = v_domains.domain_uuid";
                    $sql .= " and destination_number like :to and dialplan_detail_type = 'transfer'";

                    if ($debug) {
                        error_log("SQL: " . print_r($sql,true));
                    }

                    $prep_statement = $db->prepare(check_sql($sql));
                    $prep_statement->bindValue(':to', "%{$to}%");
                    $prep_statement->execute();
                    $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
                    if (count($result) == 0) {
                        error_log("Cannot find a destination: " . print_r($result,true));
                        die("Invalid Destination");
                    }
                    foreach ($result as &$row) {
                        $domain_name = $row["domain_name"];
                        preg_match('/(\d{2,7})/',$row["dialplan_detail_data"],$match);
                        $domain_uuid = $row["domain_uuid"];
                        break; //limit to 1 row
                    }
                }
                unset ($prep_statement);

                if ($debug) {

(Let me know if you just need to full code listing for that one. I am not sure what the policy is for posting full files on this site.)

In /app/sms/sms_edit.php, change:
(Note that it has been a little while since I made some of these changes, and in reviewing them, I believe one or two of them were to re-enable MariaDB/MySQL support that has been broken in the main project. This should still work if you use PostgreSQL, since I'm using SQL standard syntax, but YMMV.)
From (about line 64):
PHP:
            $sms_destination_uuid = $row['sms_destination_uuid'];
        }
To:
PHP:
            $sms_destination_uuid = $row['sms_destination_uuid'];
            $chatplan_detail_data = $row['chatplan_detail_data'];
        }

From (about line 78):
PHP:
            $sms_destination_uuid = uuid();
        if ($action == "add") {
To:
PHP:
            $sms_destination_uuid = uuid();
            $chatplan_detail_data = check_str($_POST["chatplan_detail_data"]);
        if ($action == "add") {

From (about line 96):
PHP:
            $sql_insert .= "description, ";
            $sql_insert .= ")";
To:
PHP:
            $sql_insert .= "description, ";
            $sql_insert .= "chatplan_detail_data ";
            $sql_insert .= ")";

From (about 106):
PHP:
            $enabled = check_str($_POST["enabled"]);
            
            $sql_insert = "update v_sms_destinations set";
            $sql_insert .= "(";
            $sql_insert .= "carrier, ";
            $sql_insert .= "destination, ";
            $sql_insert .= "enabled, ";
            $sql_insert .= "description ";
            $sql_insert .= ")";
            $sql_insert .= "= ";
            $sql_insert .= "(";
            $sql_insert .= "'".$carrier."', ";
            $sql_insert .= "'".$destination."', ";
            $sql_insert .= "'".$enabled."', ";
            $sql_insert .= "'".$description."' ";
            $sql_insert .= ")";
            $sql_insert .= "where sms_destination_uuid = '" . $sms_destination_uuid . "' and domain_uuid = '" . $_SESSION['domain_uuid'] . "'";
            $db->exec($sql_insert);
            header( 'Location: sms.php') ;
To:
PHP:
            $enabled = check_str($_POST["enabled"]);
            $chatplan_detail_data = check_str($_POST["chatplan_detail_data"]);

            $sql_insert = "update v_sms_destinations set";
            $sql_insert .= " ";
            $sql_insert .= "carrier = '".$carrier."', ";
            $sql_insert .= "destination = '".$destination."', ";
            $sql_insert .= "enabled = '".$enabled."', ";
            $sql_insert .= "description = '".$description."', ";
            $sql_insert .= "chatplan_detail_data = '".$chatplan_detail_data."' ";
            $sql_insert .= "where sms_destination_uuid = '" . $sms_destination_uuid . "' and domain_uuid = '" . $_SESSION['domain_uuid'] . "'";
            $db->exec($sql_insert);
            error_log($sql_insert);
            header( 'Location: sms.php') ;

From (about 179):
PHP:
    echo "</tr>\n";

    if (permission_exists('sms_enabled')) {
To:
PHP:
    echo "</tr>\n";



    echo "<tr>\n";
    echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
    echo "    ".$text['label-chatplan_detail_data']."\n";
    echo "</td>\n";
    echo "<td class='vtable' align='left'>\n";
    echo "    <input class='formfld' type='text' name='chatplan_detail_data' autocomplete='off' maxlength='255' value=\"$chatplan_detail_data\" >\n";
    echo "<br />\n";
    echo $text['description-chatplan_detail_data']."\n";
    echo "</td>\n";
    echo "</tr>\n";

    if (permission_exists('sms_enabled')) {

In /app/sms/app_languages.php, change:
From (about line 132):
PHP:
$text['label-message']['he'] = "";

$text['button-mdr']['en-us'] = "MDRs";
To:
PHP:
$text['label-message']['he'] = "";

$text['label-chatplan_detail_data']['en-us'] = "Extension or Ring Group";
$text['label-chatplan_detail_data']['es-cl'] = "";
$text['label-chatplan_detail_data']['pt-pt'] = "";
$text['label-chatplan_detail_data']['fr-fr'] = "";
$text['label-chatplan_detail_data']['pt-br'] = "";
$text['label-chatplan_detail_data']['pl'] = " ";
$text['label-chatplan_detail_data']['uk'] = "";
$text['label-chatplan_detail_data']['sv-se'] = "";
$text['label-chatplan_detail_data']['ro'] = "";
$text['label-chatplan_detail_data']['de-at'] = "";
$text['label-chatplan_detail_data']['ar-eg'] = "";
$text['label-chatplan_detail_data']['he'] = "";

$text['description-chatplan_detail_data']['en-us'] = "Routing extension or ring group for inbound SMS messages";
$text['description-chatplan_detail_data']['es-cl'] = "";
$text['description-chatplan_detail_data']['pt-pt'] = "";
$text['description-chatplan_detail_data']['fr-fr'] = "";
$text['description-chatplan_detail_data']['pt-br'] = "";
$text['description-chatplan_detail_data']['pl'] = " ";
$text['description-chatplan_detail_data']['uk'] = "";
$text['description-chatplan_detail_data']['sv-se'] = "";
$text['description-chatplan_detail_data']['ro'] = "";
$text['description-chatplan_detail_data']['de-at'] = "";
$text['description-chatplan_detail_data']['ar-eg'] = "";
$text['description-chatplan_detail_data']['he'] = "";

$text['button-mdr']['en-us'] = "MDRs";
 
Jan 9, 2018
152
16
18
54
Once you implement all changes, when you are editing an SMS destination, you should now see a field for "Extension or Ring Group". This is not a drop-down, though ideally, it should be. Given time constraints, I couldn't figure out how to get that implemented. You just type in the extension or ring group for routing here. Like I said, it works, and for us, that's what counts right now.
 

MTR

Member
Oct 25, 2017
181
9
18
45
Works Great

now i will start working on this to work with 4.4 will report back
 
Last edited:

MTR

Member
Oct 25, 2017
181
9
18
45
1. If I have 2 devices for the same account the incoming sms will show on both devices but the outgoing will only show on th device the msg was send from

Isn’t the outgoing sms recorded on the DB as well?

2. Can we have an outbound clallerID separate for voice and SMS the same way we have for inbound separate destinations?
 
Status
Not open for further replies.