simontelephonics / smsconnector

SMS Connector module for FreePBX 16 and 17
https://simon.tel/open-source/
GNU General Public License v3.0
41 stars 16 forks source link

Cannot receive SMS message on softphone #41

Closed sdwru closed 7 months ago

sdwru commented 7 months ago

Using latest (v16.0.15.2) version with Telnyx as my SIP/SMS provider

I don’t use Sangoma softphones and can’t seem to receive messages to MicroSIP, LinPhone, or Zoiper 5 free edition. It’s received by the PBX and shows up in UCP, it just never gets to the softphone. Sending SMS from those softphones works fine. It’s just receiving that is not working. I also tried the previous 3 versions of this module.

This is the error message from the asterisk console.

ERROR[28445]: res_pjsip_messaging.c:1257 msg_send: PJSIP MESSAGE - Could not find endpoint 'sip:999@x.x.x.x:20001' and no default outbound endpoint configured

Where x.x.x.x is the obfuscated public IP of my softphone. This exact configuration works using your freepbx-telnyx-sms script. The only thing I changed was switching from that script to the smsconnector module. I am pretty sure I have all that configured correctly because everything else works in both directions, including SMS to email when the extension is offline.

The PJSIP extension is definitely registered and reachable and is working for voice calls.

 Endpoint:  999/999                                              Not in use    0 of inf
    OutAuth:  999-auth/999
     InAuth:  999-auth/999
        Aor:  999                                                1
      Contact:  999/sip:999@x.x.x.x:20001            dbe13d98e9 Avail        52.531

Firewall and fail2ban are disabled on the server and no other iptables rules. MicroSIP app is fully allowed through Windows Defender firewall. Telnyx API log says the delivery was successful.

This is what's in freepbx.log.

[freepbx.INFO]: Error sending message to PJSIP/999/sip:999@x.x.x.x:20001: Message failed to send 
 [] []
[freepbx.INFO]: Webhook (telnyx): Return Code 202 [] []

Nothing in the apache logs.

billsimon commented 7 months ago

It looks like you have set up everything correctly. The error Could not find endpoint... that Asterisk is generating is what we should focus on. Can you get me a full output of the following console output?

start

core set verbose 9 pjsip set logger on pjsip show endpoints pjsip show endpoint 999 < generate an inbound message >

end

Feel free to send these privately as a message on the FreePBX forum.

I think if there is a bug here it is in the way we extract the PJSIP contacts:

                // get contacts
                $result = $this->FreePBX->astman->send_request('Getvar', array('Variable' => "PJSIP_DIAL_CONTACTS($device)"));
                $contacts = array();
                if (!empty($result['Value']))
                {
                    $contacts = explode('&', $result['Value']);
                }

                if (!empty($contacts))
                {
                    foreach ($contacts as $contact) // message all registered
                    {
                        $sipTo = sprintf("pjsip:%s", strstr($contact, 'sip'));
                        $result = $this->FreePBX->astman->MessageSend($sipTo, $sipFrom, $message);
                        if ($result['Response'] == 'Error')
                        {
                            freepbx_log(FPBX_LOG_INFO, sprintf(_("Error sending message to %s: %s"), $contact, $result['Message']));
                        }
                    }
                }
sdwru commented 7 months ago

I setup those parameters you asked for but there is nothing generated on the incoming message besides the error I already posted. The option packets also look normal to me.

I setup a new extension to receive voip.ms SMS messages and get the exact same error, so it does not appear to be specific to any one provider.

This is the output of pjsip show endpoint 999. I believe it's all just the standard defaults. The new voip.ms extension I setup, that has the same error, is definitely all defaults.

ParameterName                      : ParameterValue
 ===================================================================================================
 100rel                             : yes
 accept_multiple_sdp_answers        : false
 accountcode                        :
 acl                                :
 aggregate_mwi                      : true
 allow                              : (opus|ulaw)
 allow_overlap                      : true
 allow_subscribe                    : true
 allow_transfer                     : true
 allow_unauthenticated_options      : false
 aors                               : 999
 asymmetric_rtp_codec               : false
 auth                               : 999-auth
 bind_rtp_to_media_address          : false
 bundle                             : false
 call_group                         :
 callerid                           : "testsms" <999>
 callerid_privacy                   : allowed_not_screened
 callerid_tag                       :
 codec_prefs_incoming_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_incoming_offer         : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_offer         : prefer:pending, operation:union, keep:all, transcode:allow
 connected_line_method              : invite
 contact_acl                        :
 context                            : from-internal
 cos_audio                          : 5
 cos_video                          : 4
 device_state_busy_at               : 0
 direct_media                       : true
 direct_media_glare_mitigation      : none
 direct_media_method                : invite
 disable_direct_media_on_nat        : false
 dtls_auto_generate_cert            : No
 dtls_ca_file                       :
 dtls_ca_path                       :
 dtls_cert_file                     :
 dtls_cipher                        :
 dtls_fingerprint                   : SHA-256
 dtls_private_key                   :
 dtls_rekey                         : 0
 dtls_setup                         : active
 dtls_verify                        : No
 dtmf_mode                          : rfc4733
 fax_detect                         : false
 fax_detect_timeout                 : 0
 follow_early_media_fork            : true
 force_avp                          : false
 force_rport                        : true
 from_domain                        :
 from_user                          :
 g726_non_standard                  : false
 geoloc_incoming_call_profile       :
 geoloc_outgoing_call_profile       :
 ice_support                        : false
 identify_by                        : username,ip
 ignore_183_without_sdp             : false
 inband_progress                    : false
 incoming_call_offer_pref           : local
 incoming_mwi_mailbox               :
 language                           : en
 mailboxes                          :
 max_audio_streams                  : 1
 max_video_streams                  : 1
 media_address                      :
 media_encryption                   : no
 media_encryption_optimistic        : false
 media_use_received_transport       : false
 message_context                    : smsconnector-messages
 moh_passthrough                    : false
 moh_suggest                        : default
 mwi_from_user                      :
 mwi_subscribe_replaces_unsolicited : no
 named_call_group                   :
 named_pickup_group                 :
 notify_early_inuse_ringing         : false
 one_touch_recording                : true
 outbound_auth                      : 999-auth
 outbound_proxy                     :
 outgoing_call_offer_pref           : remote_merge
 overlap_context                    :
 pickup_group                       :
 preferred_codec_only               : false
 record_off_feature                 : apprecord
 record_on_feature                  : apprecord
 refer_blind_progress               : true
 rewrite_contact                    : true
 rpid_immediate                     : false
 rtcp_mux                           : false
 rtp_engine                         : asterisk
 rtp_ipv6                           : false
 rtp_keepalive                      : 0
 rtp_symmetric                      : true
 rtp_timeout                        : 30
 rtp_timeout_hold                   : 300
 sdp_owner                          : -
 sdp_session                        : Asterisk
 security_mechanisms                :
 security_negotiation               : no
 send_aoc                           : false
 send_connected_line                : yes
 send_diversion                     : true
 send_history_info                  : false
 send_pai                           : false
 send_rpid                          : false
 set_var                            :
 srtp_tag_32                        : false
 stir_shaken                        : off
 stir_shaken_profile                :
 sub_min_expiry                     : 0
 subscribe_context                  :
 suppress_q850_reason_headers       : false
 t38_bind_udptl_to_media_address    : false
 t38_udptl                          : true
 t38_udptl_ec                       : redundancy
 t38_udptl_ipv6                     : false
 t38_udptl_maxdatagram              : 0
 t38_udptl_nat                      : true
 timers                             : yes
 timers_min_se                      : 90
 timers_sess_expires                : 1800
 tone_zone                          :
 tos_audio                          : 184
 tos_video                          : 136
 transport                          :
 trust_connected_line               : yes
 trust_id_inbound                   : true
 trust_id_outbound                  : false
 use_avpf                           : false
 use_ptime                          : false
 user_eq_phone                      : false
 voicemail_extension                :
 webrtc                             : no
billsimon commented 7 months ago

You trimmed out the AORs section - could you post that also?

sdwru commented 7 months ago
Endpoint:  999/999                                             Not in use    0 of inf
    OutAuth:  999-auth/999
     InAuth:  999-auth/999
        Aor:  999                                                2
      Contact:  999/sip:999@x.x.x.x:58209;ob         90b8b4165e Avail        34.530
sdwru commented 7 months ago

Here is an option packet response from the extension with IPs obfuscated where x.x.x.x is the extension public IP and xx.xx.xx.xx is the PBX public IP.

<--- Received SIP response (796 bytes) from UDP:x.x.x.x:58209 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP xx.xx.xx.xx:5060;rport=5060;received=xx.xx.xx.xx;branch=z9hG4bKPj0320a744-2f1b-43a9-9fea-f638c1d299a3
Call-ID: 8daed805-38ee-4916-b766-9e662eaf840b
From: <sip:999@xx.xx.xx.xx>;tag=4da088a7-d6ed-4d0d-83da-bc82bc0ce717
To: <sip:999@x.x.x.x;ob>;tag=z9hG4bKPj0320a744-2f1b-43a9-9fea-f638c1d299a3
CSeq: 25706 OPTIONS
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Accept: application/sdp, application/pidf+xml, application/xpidf+xml, application/simple-message-summary, message/sipfrag;version=2.0, application/im-iscomposing+xml, text/plain
Supported: replaces, 100rel, timer, norefersub, trickle-ice
Allow-Events: presence, message-summary, refer
User-Agent: MicroSIP/3.21.3
Content-Length:  0
billsimon commented 7 months ago

Can you do this from the asterisk CLI?

dialplan eval function PJSIP_DIAL_CONTACTS(999)
sdwru commented 7 months ago
pbx1*CLI> dialplan eval function PJSIP_DIAL_CONTACTS(999)
Return Value: Success (0)
Result: PJSIP/999/sip:999@x.x.x.x:58209;ob
billsimon commented 7 months ago

I think I see a bug but I can't figure out why it works for me now... will be a good afternoon puzzle. Thanks for the info and I'll get back to you soon.

billsimon commented 7 months ago

Can you apply this patch and confirm it fixes the problem? (patch) If you're not familiar with the process then I'll just go ahead and do a release later this afternoon because I'm pretty confident this will solve it.

sdwru commented 7 months ago

That appears to have resolved it.