SOLVED SMS App Setup

Status
Not open for further replies.

Caleb

Member
Sep 12, 2017
42
17
8
WA, USA
We decided to add SMS to our phone system, just "because we can." Since the SMS app doesn't seem to be currently maintained, I've been doing some digging around to see what needed to be done to get it working. We now have SMS (both sending and receiving) functioning. Here's the steps I took in order to get it set up:
  1. Follow steps 1 - 5 in the FusionPBX SMS app setup instructions
  2. Change the Default Settings specifications by editing app/sms/app_defaults.php, between lines 28 and 179...
    1. Replace all references to $x to $y
    2. Replace $array with $apps[$x]['default_settings']
    3. Move this block of code to app/sms/app_config.php (I put it between the "permission details" and "schema details" sections of code already in that file)
    4. Comment or remove the remaining code within the if block in app_defaults.php
  3. Fix the schema definition by editing app/sms/app_config.php
    1. Replace $apps[$x]['db'][$y]['table']['name'] with $apps[$x]['db'][$y]['table']
    2. Comment or remove occurrences of $apps[$x]['db'][$y]['table']['parent'] = "";
  4. In FusionPBX web config > Advanced > Upgrade, check "Schema," "App Defaults," "Menu Defaults," " and "Permission Defaults," then click "Execute."
    • It should go without saying, but just to be sure, please document your custom configurations in each of these sections BEFORE doing the upgrade, as you will need to go through after the upgrade process and change them all back to how you had them set.
  5. After the process finishes, log out, and then log back in again to apply the new permissions and menu options
  6. The default chatplan doesn't line up with the default context settings in FusionPBX, so to make them use the same context, in Advanced > XML Editor, edit chatplan/default.xml change the context name of public to internal (or whatever other context should have access to sending SMS messages).
  7. The Lua script does some weird URL encoding that doesn't seem to get decoded before the message is sent to the SIP endpoints. Disable this by editing the SMS Lua script (ours is located at /usr/share/freeswitch/scripts/app/sms/index.lua, so I edited it using vi at the console) and commenting out lines 46 - 48.
  8. In Advanced > Default Settings, enable and set the values for your respective carrier
  9. In Apps > SMS, add the phone numbers that are allowed to send outgoing SMS messages
    • The number formatting isn't very thorough; at the time of this post, the Lua script supports only 10 digit numbers, with and without a preceding "1" (no "+" characters or RegEx's)
  10. Make sure you have the appropriate destinations set up in Dialplan > Destinations, with the destination number(s) matching those you specified in Apps > SMS
    • I have not thoroughly tested all the possibilities, but from what I can tell of the code, and from what I've confirmed with our setup, the SMS webhook for inbound messages supports regular extensions and ring groups (a message will go to all the destinations in a ring group)
  11. Go to Status > SIP Status, and click "Reload XML"
And there you have it! Enjoy!
 

yukon

Member
Oct 3, 2016
138
14
18
If you feel it needs work, why don't you submit code changes to the repo for the general public?

  1. The Lua script does some weird URL encoding that doesn't seem to get decoded before the message is sent to the SIP endpoints. Disable this by editing the SMS Lua script (ours is located at /usr/share/freeswitch/scripts/app/sms/index.lua, so I edited it using vi at the console) and commenting out lines 46 - 48.
This is a very bad suggestion, it does encoding so that when it gets written to the database you don't have SQL injection problems. Why don't you fix the issue instead of a work around?
 

Caleb

Member
Sep 12, 2017
42
17
8
WA, USA
@yukon, thanks for the feedback. I know just enough about the languages that make up FusionPBX to be able to figure things out and make my own changes, but I haven't been in to software development long enough to learn how to work with code repositories... (I know, I know... real programmers would know how to do that, I'm just not there yet)

Thanks for the pointer on the SQL! I definitely did not think of that. For the reader's sake, instead of step 7 in my setup instructions above, change the code on lines 74, 134, and 136 so the urlencode() function is not called (the respective variables will be copied directly instead of being processed by the function first). Then change body = body on line 314 to body = urlencode(body). If you want the MDRs to show up correctly, you'll need to edit app/sms/sms_mdr.php in the PHP Editor, and change $row['message'] on line 128 to urldecode($row['message']).
 
Last edited:

Caleb

Member
Sep 12, 2017
42
17
8
WA, USA
@bbrendon, I'm not familiar enough with the code to know what all references the SMS functionality, but all I've seen at this point is mostly just pass-through capabilities; FusionPBX receives the message (incoming and outgoing), and sends it to destination(s) as the chatplan specifies. There is a permission titled "voicemail_sms_edit," but I haven't seen any additional fields in the Voicemail Settings that allow VM notifications via SMS, so there might need to be some more development and/or configuration there.
 
Last edited:

yukon

Member
Oct 3, 2016
138
14
18
What capabilities does this add exactly? SMS notifications on voicemails?

If you go to group permissions, then enable voicemail_sms_edit, log out and back in, then go to the apps->voicemail there will be a field called "SMS To" where you can input the notification DID (IE cell phone number)
 

Caleb

Member
Sep 12, 2017
42
17
8
WA, USA
If you go to group permissions, then enable voicemail_sms_edit, log out and back in, then go to the apps->voicemail there will be a field called "SMS To" where you can input the notification DID (IE cell phone number)
I was expecting something like that, but I have been unable to find a field with that (or a similar) title in the Voicemail Settings for any given mailbox. I can't seem to find any part of the PHP files in the Voicemails app that references that permission, either.
 

Derick

New Member
Jun 21, 2018
15
2
1
Sydney Australia
Is this method still recommended? Also, my app/sms/app_defaults.php file is actually empty.. Does anyone know why that would be? I would appreciate any help. Im on version 4.4.3
 
Last edited:
  • Like
Reactions: Vzb007 and Edson

Edson

Member
Aug 1, 2017
59
4
8
47
Is this method still recommended? Also, my app/sms/app_defaults.php file is actually empty.. Does anyone know why that would be? I would appreciate any help. Im on version 4.4.3
Derik, the solution seems not be valid anymore. Let´s fix it.
 
  • Like
Reactions: Vzb007

mydigitalself

Member
Oct 20, 2019
71
7
8
I was just testing this and seeing 2 issues which I hope are simple things I may have missed.

When attempting to send a SMS I lose connectivity to freeswitch and just before it says the cell number I'm attempting to send to is not a registered user.

I already tried changing the chat plan to <action application="lua" data="app.lua sms outbound"/>

Any suggestions on getting around this?
 
Status
Not open for further replies.