Advice on SMS gateway...

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
Hello,

I've been working part-time for several weeks trying to connect SMS messages from our carriers (Bandwidth and Telnyx) to a FusionPBX instance in an attempt to accomplish a few things:

* Allow users to send/receive text messages using softphones
* Allow users to send/receive text messages using a web interface
* Allow users to receive text messages via e-mail

While I have part of this working, it required an incredible amount of debugging and fiddling with the Fusion SMS app. I now have it receiving SMS messages and e-mailing users, but something is broken when trying to deliver to endpoints. After exerting so much energy troubleshooting the simple part of things, I'm second guessing my approach and wondering if I need to have a sanity check on the whole attempt. Either I'm really doing this the hard way or this is simply the current state of affairs with SMS and FusionPBX.

Has anyone successfully setup SMS messaging, send/receive, with Telnyx and Bandwidth such that messages can be both sent and received by endpoints AND delivered via e-mail AND sent/received via a web interface? (i.e. FusionPBX app "messages")
 

voipBull

Member
Dec 3, 2023
96
21
8
Hello @micah.quinn, sorry I have no help to offer here but have a question for you if I may. Are you using both the SMS app and the Messages app? or just the Messages app alone to accomplish all the tasks you've listed above?
 

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
I'm using both SMS and Messages. Messages appears to be a way to simply receive/send via the web interface and SMS is gateway that routes messages.
 

voipBull

Member
Dec 3, 2023
96
21
8
hmmm, for some reason I was under the impression that Messages app is a replacement for the SMS app, and should be able to be used to send/receive SMS's via the FusionPBX WebUI Messages application and also via extensions registered on SIP softphones that are capable of sending/receiving messages.

@markjcrane apologies for tagging you directly into this thread, but if you have a minute, can you please clear this doubt for me.
 

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
Apologies. Bull, you are correct that messages does both inbound/outbound and UI. This means the SMS is not necessary when using Messages.

I've managed to get inbound SMS with messages (The documentation is not clear that the callback URL is supposed to be .../app/messages/index.php) And I'm seeing that a new message is received in the UI. I also hear the notification in the browser. However, I do not see the message contents (body) in the web UI. I've verified that the database (v_messages) does indeed populate correctly. I'm also getting an Invalid Profile when messages attempts to deliver to endpoints. I believe that is because the sofia profile name is not being prepended correctly to the destination. (i.e. internal/1000@sub.domain.tld)

I'll keep working on it.

(P.S. The messages app seems much more up to date with current providers. Much appreciated!)
hmmm, for some reason I was under the impression that Messages app is a replacement for the SMS app, and should be able to be used to send/receive SMS's via the FusionPBX WebUI Messages application and also via extensions registered on SIP softphones that are capable of sending/receiving messages.

@markjcrane apologies for tagging you directly into this thread, but if you have a minute, can you please clear this doubt for me.
 
  • Like
Reactions: voipBull

voipBull

Member
Dec 3, 2023
96
21
8
Maybe a selfish ask on my end, but when you get this to work, will you please share the steps/instructions you followed that are not very well covered in the documentation. It'll be a good kick start for me or anyone else who may want to setup the Messages app in the future.
 
  • Like
Reactions: johnnyorange

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
I can provide a summary of the steps here once I have everything working. Here's a brief update on my current status:
  • Messages is delivering to endpoints correctly; Invalid Profile was from a different test.
  • It looks like the SQL query for numbers in "message_contact.php" is stripping out the "+" from numbers which was causing issues when trying to display the messages. I modfied the line to not strip out the + and the messages started showing up. I'm not sure why the SQL query is arbitrarily stripping out pluses, but this seems to be incorrect:
    PHP:
    //      $sql .= "               select distinct(REPLACE(message_from, '+', '')) as number from v_messages \n";
            $sql .= "               select distinct message_from as number from v_messages \n";
  • Eventhough I hear the new message notification in the browser and the latest message under the contact number correctly updates, the main conversation thread goes blank. If I click on the contact again, the thread frame updates and shows the latest messages. This seems related to the "+" character issue as the hidden input value for "message_to" has the + stripped out. I'm assuming that value is used on state change to update the messages.

Perhaps there is something in my configuration that is just not set right to handle the leading plus. It feels like the plus should be getting stripped out on inbound message receipt, but I'm not sure how to affect this.

UPDATE: If I instead strip out the + in index.php, everything else seems to work properly:
PHP:
    $message_from = get_value($message, $setting['message_from']);
    $message_from = preg_replace('/\+/', '', $message_from);
 
Last edited:

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
I'm going to post a quasi-final update on this here to close out this thread. I was able to get Messages to work sufficiently enough for me to test/evaulate if it will work for our needs.

Currently I have the following working:

* Send/receive from web UI
* Send/receive from softphone endpoint
* Send/receive from hardphone endpoint

In addition to the the changes in my previous post I added some code to be able to support multiple inbound carriers based on user agent rather than IP address. Since our server exists behind a reverse-proxy, all originating IPs appear to come from the reverse proxy. I can then control access via the reverse proxy. A less disruptive change would probably be to configure the webserver to use the "real IP" header.

Sending messages through the web UI works, but is buggy. You cannot simply reply to a text message using the "Enter Response..." text field. Instead, you have to click "+ NEW MESSAGE" and enter all the associated information, then hit send. I'm sure it's just a bug. The code does not appear to be populating the reply phone number correctly in a hidden form value. There also seems to be no way to select from contacts when composing a new message. There appears to be no delete option for messages/threads.

My experience leads me to believe that, while a vast improvement over SMS, Messages still has some issues that need to be addressed:
  • The documentation does not mention that index.php is the endpoint for carrier webhooks
  • Handling of + in a routing a number needs some work. (There's a bunch of adhoc code for doing various things with plus or %2B.) It's not clear anywhere in the UI if I need to use a country code or not when addressing numbers.
  • Telnyx V2 messaging API doesn't seem to work properly with Messages. Messages sent using this API store the JSON data in the text field of the database and nothing else. This leads me to believe it's a parsing issue, but I didn't take the time to debug it.
  • Fix the in-thread reply form in the web UI
  • No way to delete messages/threads
  • No integration with contacts for new messages
Feel free to request any details that might be helpful.
 
  • Like
Reactions: voipBull

johnnyorange

New Member
Dec 9, 2019
3
3
3
I realize this is a tremendous ask @micah_quinn, but if you would be so kind as to post the steps and code you utilized in order to get the messages app working for telnyx to deliver sms to endpoints?

On a totally new 5.3.3 fusionpbx install with tls and telnyx voice inbound/outbound working beautifully.

In the messages app, I see inbound messages there in the log, but they never get delivered to endpoints (groundwire in my case).

To your point, I agree that the json response is not being parsed by the messages/index.php and thusly not delivered to endpoints.

the issue that is a showstopper for me now is outbound sms through telnyx, and I believe my issue is in chatplan.xml in that it is not formatted set up to work.

that said, for the messages app, am I correct in assuming that freeswitch and chatplan.xml are being called by the messages app?

or am i barking up the wrong tree?
 
Oh how I would love to send/receive SMS using a softphone like Groundwire. I have the SMS app installed in FusionPBX presently and can successfully get inbound SMS sent via email, but beyond that I just haven't found the appropriate documentation that would allow me to tie in Groundwire (or any other softphone) to do both inbound/outbound.
 

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
@datafanatics I would imagine that Groundwire would work just like any other softphone using the Messages app. Like I said, I gave up on the SMS app.

@johnnyorange I believe the Messages app does tie into the chatplan, but I made no modification to it in order to make this work. The only code modification I made, with the exception of the user_agent -> provider ID change, was the one mentioned above in index.php. If you're running Fusion on a public IP or otherwise passing through the public ID you shouldn't need to use user_agent identification.

From there, just make sure at least one extension has your SMS number set as it's outbound caller id number. Messages should then be delivered to any connected endpoints. If it isn't working, I'd recommend using postman or curl to send test inbound SMS messages and debug statements in the code to see where the breakdown is. You can also monitor the v_messages table in the database to see if they are getting correctly added. Again, this only worked for me with the Bandwidth.com provider; the Telnyx provider is not properly parsing the JSON.
 
  • Like
Reactions: johnnyorange

micah.quinn

New Member
Apr 23, 2024
7
5
3
54
What exactly do you mean by "interface with it"? If you mean connecting your carrier to the app, the webhook is ".../apps/messages/index.php". There is logic in there that matches the from IP address in the request header with the provider. (Make sure you setup the provider correctly in FusionPBX).
 
What exactly do you mean by "interface with it"? If you mean connecting your carrier to the app, the webhook is ".../apps/messages/index.php". There is logic in there that matches the from IP address in the request header with the provider. (Make sure you setup the provider correctly in FusionPBX).
You nailed it! Thanks! I'm about to add things into Twilio to see if I can start receiving.