Working SMS Integration

Status
Not open for further replies.
Jan 9, 2018
140
12
18
54
I've hit a bit of a snag ....
I believe I've figured out the settings in PHP. The pull request has been submitted. I don't know how long this will take to get accepted. If anyone wants to help test, I think you can get the code at that link, but if not, let me know.
In addition to the changes I listed in post #77 above, I also was able to add to the chatplan/default.xml a similar check for internal message delivery (verifies that the target extension is registered before letting it through). Note that the published version of this chatplan only allows for 10-digit/external messaging.
  • To enable internal messaging system-wide, you'll need to uncomment the "action application='send'" line in the last section ("other").
  • To enable it only for a specific domain, uncomment the "allowed-local" section and add your target domain in the condition.
 
Jan 9, 2018
140
12
18
54
For those who would like to add MMS support for other carriers:
The route_and_send_sms function in sms_hook_common will accept, as a fourth parameter, an array named "media" that looks like this:
Code:
   [media] => Array

        (

            [0] => stdClass Object

                (

                   [url] => https://test.com/abc.jpeg
                   [content_type] => image/jpeg
                )
        )
Try sending yourself an MMS and then look at the output in your error.log (it will dump the payload there). In your sms_hook_<carrier>.php you can build an array of those objects and pass it as the fourth parameter. Then, in sms_email.php, add your carrier to the attachment-handling block. If you recreate the array closely enough, you should be able to just say something like "if ($carrier == 'telnyx' or $carrier == 'mycarrier')" The other alternative is to build your own attachment-handling block in sms_email.php. For example, we don't actively use Twilio, but I have a test number on there. Twilio sends the following fields:
Code:
[NumMedia] => 1
[MediaContentType0] => image/jpeg
[MediaUrl0] => https://api.twilio.com/2010-04-01/Accounts/<filename>
You could use this to build the above array (obviously accounting for multiple attachments in the process).

(Sorry for the multiple edits, but the code tags are acting up.)
 
Last edited:

Len

Member
Mar 8, 2017
95
3
8
52
Anybody got this to work with Thinq? Im able to do use API manually but not via SMS App. I see incoming posts from thinq by tailing /var/log/nginx as follows:

192.81.236.250 - - [25/Nov/2019:20:15:43 -0500] "POST / HTTP/1.1" 301 184 "http:/************.com" "thinq-sms"
192.81.236.250 - - [25/Nov/2019:20:15:43 -0500] "POST / HTTP/1.1" 200 4175 "https://*********.com" "thinq-sms"

Under default settings, I filled in all thinq settings although I'm not sure what to put into "thinq_api_url"
 
Jan 9, 2018
140
12
18
54
Anybody got this to work with Thinq? Im able to do use API manually but not via SMS App. I see incoming posts from thinq by tailing /var/log/nginx as follows:

192.81.236.250 - - [25/Nov/2019:20:15:43 -0500] "POST / HTTP/1.1" 301 184 "http:/************.com" "thinq-sms"
192.81.236.250 - - [25/Nov/2019:20:15:43 -0500] "POST / HTTP/1.1" 200 4175 "https://*********.com" "thinq-sms"

Under default settings, I filled in all thinq settings although I'm not sure what to put into "thinq_api_url"
I mentioned this in a PM, but in case someone else has the same question:
The /var/log/nginx/access.log will only register the POST. More details can be found in the /var/log/nginx/error.log file. Most steps in the operation are logged there, along with any errors. Also, if set up properly, it will log information about the delivery of the inbound message to the Freeswitch log, since this is a SMS to SIP SIMPLE messaging protocol gateway.
 

Len

Member
Mar 8, 2017
95
3
8
52
Thank you. I don't see anything logged in error.log or in FS logs. I only see 2 lines in nginx access.log

192.81.236.250 - - [26/Nov/2019:20:45:01 -0500] "POST / HTTP/1.1" 301 184 "http://********.com" "thinq-sms"
192.81.236.250 - - [26/Nov/2019:20:45:02 -0500] "POST / HTTP/1.1" 200 4175 "https://*******s.com" "thinq-sms"

"thinq-sms" is the agent name sent by thinq in the header. The second line (200 response) seems to say that it was successful but it is not processing anything. I am trying to get logs of full body of the posts. Maybe that will give me an indication.
 

MTR

Member
Oct 25, 2017
181
9
18
45
i am testing the system with telnyx and i am getting an error

any ideas?

2020/02/10 23:08:23 [error] 783#783: *1940806 FastCGI sent in stderr: "PHP message: [SMS] REQUEST: stdClass Object
(
[data] => stdClass Object
(
[event_type] => message.received
[id] => 3080cfca-b503-4013-9159-55604b71ffca
[occurred_at] => 2020-02-11T04:08:22.932+00:00
[payload] => stdClass Object
(
[completed_at] =>
[cost] =>
[direction] => inbound
[encoding] => GSM-7
[errors] => Array
(
)

[from] => stdClass Object
(
[carrier] => Verizon Wireless
[line_type] => long_code
[phone_number] => +17181234567
[status] => webhook_delivered
)

[id] => 7cf03e54-f01b-4f86-8b7d-5e2b2de10b8e
[media] => Array
(
...
PHP message: TO: 0
PHP message: FROM: 0
PHP message: BODY:
PHP message: BODY:
PHP message: BODY-revised:
PHP message: SQL: select domain_name, chatplan_detail_data, v_sms_destinations.domain_uuid as domain_uuid from v_sms_destinations, v_domains where v_sms_destinations.domain_uuid = v_domains.domain_uuid and destination like :to and chatplan_detail_data <> ''
PHP message: SQL: select domain_name, chatplan_detail_data, v_sms_destinations.domain_uuid as domain_uuid from v_sms_destinations, v_domains where v_sms_destinations.domain_uuid = v_domains.domain_uuid and destination like :to and chatplan_detail_data <> ''
PHP message: MATCH: 101
PHP message: DOMAIN_NAME: aaa.nnnnnnnn.cloud
PHP message: DOMAIN_UUID: 2f1a39b7-53c9-40de-b2df-6e8087157958
PHP message: email_from:
PHP message: Media:
PHP message: SQL: select domain_name, email, v_sms_destinations.domain_uuid as domain_uuid, carrier from v_sms_destinations, v_domains where v_sms_d
 

MTR

Member
Oct 25, 2017
181
9
18
45
This is what telnyx came back to me that the post to me

"event_type": "message.received", "occurred_at": "2020-02-10T23:00:12.763+00:00", "urls": ["https://fs.xxxxxxx.cloud/app/sms/hook/sms_hook_telnyx.php", ""], "organization_id": "6179b643-88fc-45be-8ad8-7918cffca6d3", "payload": {"record_type": "message", "direction": "inbound", "id": "c179058d-881b-4733-8dab-fe4c97744e80", "type": "SMS", "organization_id": "6179b643-88fc-45be-8ad8-7918cffca6d3", "messaging_profile_id": "49fa9719-06a8-43f8-ba4e-8c4a4a9926eb", "from": {"phone_number": "+17181234567", "status": "webhook_delivered", "carrier": "Verizon Wireless", "line_type": "long_code"}, "to": "+18452180000", "text": " Hhhhhhhh", "media": [], "parts": 1, "tags": [], "webhook_url": "https://fs.xxxxxxxx.cloud/app/sms/hook/sms_hook_telnyx.php", "webhook_failover_url": null, "encoding": "GSM-7", "cost": null, "received_at": "2020-02-10T23:00:12.749+00:00",
 
Jan 9, 2018
140
12
18
54
Our primary SMS carrier is Telnyx. For Telnyx, this is a typical response on an inbound message:
Code:
2020/02/11 17:16:03 [error] 6441#6441: *51203 FastCGI sent in stderr: "PHP message: [SMS] REQUEST: stdClass Object
(
    [sms_id] => 1e4dd539-0b67-4c90-a33e-b3f79dc7248d
    [direction] => inbound
    [from] => +1682203xxxx
    [to] => +1972293xxxx
    [body] => Test
)
Note that we are using their v1 API. (That was all they had when I wrote the integration.) I'm guessing that maybe your messaging profile is set to the v2 API. I haven't had a chance to look at implementing it yet. From a brief glance at the v1 api docs, it seems to square up with the results you are seeing. Try setting it to v1, and see if that fixes it.
 

dfwtx

New Member
Aug 25, 2018
2
0
1
49
@Jonathan Black It looks like a PHP update broke the SMS app it works for inbound, but out is broken after PHP update (PHP 7.3.4-2 ). Are you the one maintaining the SMS app:

[ERR] mod_lua.cpp:202 /usr/share/freeswitch/scripts/app/sms/index.lua:333: attempt to concatenate global 'carrier' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/app/sms/index.lua:333: in main chunk
/usr/share/freeswitch/scripts/app.lua:48: in main chunk
 
Jan 9, 2018
140
12
18
54
@Jonathan Black It looks like a PHP update broke the SMS app it works for inbound, but out is broken after PHP update (PHP 7.3.4-2 ). Are you the one maintaining the SMS app:

[ERR] mod_lua.cpp:202 /usr/share/freeswitch/scripts/app/sms/index.lua:333: attempt to concatenate global 'carrier' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/app/sms/index.lua:333: in main chunk
/usr/share/freeswitch/scripts/app.lua:48: in main chunk
It's pretty much a group effort--I've done some work on it as have others who have posted on this thread. Unfortunately, I am on PHP 7.1, so if that is the problem, I can't really do much at the moment to troubleshoot this.

That said, SMS doesn't use PHP for outbound--only for inbound, so I really doubt that's the problem. This error is more often associated with a configuration problem. Make sure that the extension you are trying to use has an outbound caller ID that matches a valid SMS destination and that the destination has a carrier assigned. (This error means that the system isn't finding a carrier associated with that extension, for some reason. This error will usually happen if I forget to set up the SMS destination, or fail to assign the carrier.)

If that checks out, but you still get this error, look right above this in the FS log and you should see a SELECT statement, something like:
Code:
SELECT carrier FROM   v_sms_destinations WHERE destination = :from and v_sms_destinations.domain_uuid = :domain_uuid and enabled = 'true'

There should then be some parameters that are listed. I recommend using a SQL tool to connect to your Postgres database, and run that command manually to see what you get. Most SQL GUI tools will let you run a parameterized query. If the results come up empty, then you'll need to work backwards from there to determine why it's not getting results.
 
  • Like
Reactions: yukon

dfwtx

New Member
Aug 25, 2018
2
0
1
49
I found it. Signalwire decided to make some changes and didn't tell anyone. I had the old version that didn't have the SMS entries before. I updated to the latest version and added the SMS number and it works. I now have to wait to see where I can get the A record from signalwire to add the ACL to the firewalls and fusion.

I do like that I can configure many carriers now. That is great! Good job!
 
Jan 9, 2018
140
12
18
54
Probably not. If they have, they haven't shared it back with the project.

While I realize this is a very long thread, you may wish to review the whole thing. I think there is probably enough information for you to be able to add a new carrier. Pretty much, everyone has added their own carrier, because it is very difficult to debug when you don't have an account with said carrier (also you're more motivated!)
 

socom

New Member
May 11, 2018
8
0
1
54
Sorry. Just realized I didn't "reply" to yours message, so you might not see my response.
Thanks for the feedback @Jonathan Black I'm going to take a stab at it. I did have it working before the plugin via VI using SIMPLE MSG aka SIMPLE SIP... somewhere along the way, it broke. VI supports both API and SIMPLE MSG methods.
 

yukon

Member
Oct 3, 2016
138
14
18
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.

Wow... I hadn't really followed this thread much but today I was trying to setup SMS to Email and couldn't get it to work, so I came back and started reading this thread thinking that I'd take some time and update the code, add some features etc.

But you know, this attitude is EXACTLY why I stopped supporting, paying for training and donating code to this project. Instead of taking the time to reach out to me, the original developer of this. He just comes in and says "missing multiple things", which he never actually goes and states what they are. And then wastes time to duplicate the effort instead of adding the features to this one. From what I can tell the missing feature was the ability to send via the web interface. Which would have been SUPER easy to add to what's already been done here.

I took a quick gander at the new "Messages" app and from what I can tell all you can do is send messages from the web interface which is completely useless, IMHO. Again, I just spent a few minutes looking it over but I also don't see a way to actually receive messages from the carriers. But you know, knowing Marc it's probably buried somewhere and not documented!

I came to you directly Mark before I started this SMS project asking to be included in the base code so that I could better integrate it with the core FusionPBX system. But because you refused to allow that I had to "hack" together and do a lot of work around to make it work. Instead now you're just wasting time duplicating the effort I had put into it in your "own" app.

What a waste of time... Can't wait for the defensive reply!
 

yukon

Member
Oct 3, 2016
138
14
18
Jan 9, 2018
140
12
18
54
hi, I was working sms feature. its working fine sending and receiving both are working fine. but when after sometimes I am receiving same message again and again . I think some event has been triggered from https://github.com/fusionpbx/fusionpbx-apps/blob/master/sms/sms_hook_common.php which is not stopping. It continuously running in background . I don't know how to stop these events. please help @Jonathan Black
Yes, as @yukon said, please start a new thread for this.
 
Status
Not open for further replies.