SMS support in FreeSWITCH

Intro

FreeSWITCH (FS) handles SMS as events rather than as sessions or channels. FS can send SMS events in the Fire and Forget where FS sends the message but does not wait for confirmation of delivery. Once fired, there is no retry, as there is no confirmation of success or failure. This is useful in the following scenario: alert everyone that IT is about to bounce the system. It does no good to a user to receive the message an hour later when they register. The alternate method is Confirmed Delivery. Sofia will not respond until after it has received a 200 OK from the remote side. If the recipient is not currently registered on the system, the sender receives a Delivery Failure event. This leads to an administrative decision whether to store the message and forward it or to reach out another way, etc. These more advanced SMS handling may be covered in a future article, or you can contact us (link to contact page or email hyperlink) and we can coordinate with your organization.

First Setup

Install the release branch of FreeSWITCH from debian packages

From the default configuration, make the change to enable sms in autoload_configs/modules.conf.xml

 <load module="mod_sms"/>

Send Successful Message

Using each's web user interface, configure 2 Yealink T28 phones to FreeSWITCH, using extensions 1001 and 1002.

On the Yealink phone registered as 1001, go to Menu->Message->Text Message->New Message. Enter any message, then set the To: field to 1002.

In fs_cli with sofia global siptrace on, this will produce:

 recv 369 bytes from udp/[172.18.101.78]:5060 at 16:10:20.107876:
 ------------------------------------------------------------------------
 MESSAGE sip:1002@172.18.101.161 SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.78:5060;branch=z9hG4bK1047636800
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=2469894683
 To: <sip:1002@172.18.101.161>
 Call-ID: 0_4129146100@172.18.101.78
 CSeq: 1 MESSAGE
 Content-Type: text/plain
 Max-Forwards: 70
 User-Agent: Yealink SIP-T27P 45.80.0.20
 Content-Length:    11

 hello world

 ------------------------------------------------------------------------
 2015-07-01 16:10:20.097545 [INFO] mod_sms.c:336 Processing text message 1001->1002 in context public
 Chatplan: 1002 parsing [public->demo] continue=false
 send 522 bytes to udp/[172.18.101.78]:5060 at 16:10:20.108225:
 ------------------------------------------------------------------------
 SIP/2.0 202 Accepted
 Via: SIP/2.0/UDP 172.18.101.78:5060;branch=z9hG4bK1047636800
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=2469894683
 To: <sip:1002@172.18.101.161>;tag=aK9H8SNN3U7ec
 Call-ID: 0_4129146100@172.18.101.78
 CSeq: 1 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Length: 0

 ------------------------------------------------------------------------
 Chatplan: 1002@172.18.101.161 Regex (PASS) [demo] to(1002@172.18.101.161) =~ /^(.*)$/ break=on-false
 Chatplan: 1002@172.18.101.161 Action reply(Hello, you said: ${_body})

 send 720 bytes to udp/[172.18.101.182]:5060 at 16:10:20.108713:
 ------------------------------------------------------------------------
 MESSAGE sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.161;rport;branch=z9hG4bK3B6NF43HF7t0p
 Max-Forwards: 70
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=2469894683
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>
 Call-ID: 5803689e-2046-11e5-bb1a-8dbc1bf6c3e0
 CSeq: 77557687 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Type: text/plain
 Content-Length: 11
 X-FS-Sending-Message: a6cba934-203a-11e5-bae5-8dbc1bf6c3e0

 hello world

 ------------------------------------------------------------------------
 send 733 bytes to udp/[172.18.101.78]:5060 at 16:10:20.108868:
 ------------------------------------------------------------------------
 MESSAGE sip:1001@172.18.101.78:5060;line=d15ffa09c50671f SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.161;rport;branch=z9hG4bK4mZeHZmNcgHKj
 Max-Forwards: 70
 From: "1002" <sip:1002@172.18.101.161>;tag=Bv2aaN6r04X1Q
 To: "1001" <sip:1001@172.18.101.78:5060;line=d15ffa09c50671f>
 Call-ID: 58036de4-2046-11e5-bb1b-8dbc1bf6c3e0
 CSeq: 77557688 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Type: text/plain
 Content-Length: 28
 X-FS-Sending-Message: a6cba934-203a-11e5-bae5-8dbc1bf6c3e0

 Hello, you said: hello world

 ------------------------------------------------------------------------
 recv 360 bytes from udp/[172.18.101.182]:5060 at 16:10:20.116054:
 ------------------------------------------------------------------------
 SIP/2.0 200 OK
 Via: SIP/2.0/UDP 172.18.101.161;rport=5060;branch=z9hG4bK3B6NF43HF7t0p
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=2469894683
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>;tag=3154943253
 Call-ID: 5803689e-2046-11e5-bb1a-8dbc1bf6c3e0
 CSeq: 77557687 MESSAGE
 User-Agent: Yealink SIP-T29G 46.80.0.25
 Content-Length: 0

 ------------------------------------------------------------------------
 recv 356 bytes from udp/[172.18.101.78]:5060 at 16:10:20.118244:
 ------------------------------------------------------------------------
 SIP/2.0 200 OK
 Via: SIP/2.0/UDP 172.18.101.161;rport=5060;branch=z9hG4bK4mZeHZmNcgHKj
 From: "1002" <sip:1002@172.18.101.161>;tag=Bv2aaN6r04X1Q
 To: "1001" <sip:1001@172.18.101.78:5060;line=d15ffa09c50671f>;tag=484260914
 Call-ID: 58036de4-2046-11e5-bb1b-8dbc1bf6c3e0
 CSeq: 77557688 MESSAGE
 User-Agent: Yealink SIP-T27P 45.80.0.20
 Content-Length: 0

 ------------------------------------------------------------------------

Send Unsuccessful Message

On the Yealink phone registered as 1002, go to Menu->Message->Text Message->New Message. Enter any message, then set the To: field to 1003, remembering that so far we have only registered phones to extensions 1001 and 1002.

In fs_cli, this will produce:

 recv 365 bytes from udp/[172.18.101.182]:5060 at 16:19:48.633682:
 ------------------------------------------------------------------------
 MESSAGE sip:1003@172.18.101.161 SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.182:5060;branch=z9hG4bK1157335874
 From: "1002" <sip:1002@172.18.101.161:5060>;tag=1945922449
 To: <sip:1003@172.18.101.161>
 Call-ID: 0_30549266@172.18.101.182
 CSeq: 1 MESSAGE
 Content-Type: text/plain
 Max-Forwards: 70
 User-Agent: Yealink SIP-T29G 46.80.0.25
 Content-Length:     7

 testing

 ------------------------------------------------------------------------
 2015-07-01 16:19:48.617536 [INFO] mod_sms.c:336 Processing text message 1002->1003 in context public
 Chatplan: 1003 parsing [public->demo] continue=false
 Chatplan: 1003@172.18.101.161 Regex (PASS) [demo] to(1003@172.18.101.161) =~ /^(.*)$/ break=on-false
 Chatplan: 1003@172.18.101.161 Action reply(Hello, you said: ${_body})

 send 522 bytes to udp/[172.18.101.182]:5060 at 16:19:48.634079:
 ------------------------------------------------------------------------
 SIP/2.0 202 Accepted
 Via: SIP/2.0/UDP 172.18.101.182:5060;branch=z9hG4bK1157335874
 From: "1002" <sip:1002@172.18.101.161:5060>;tag=1945922449
 To: <sip:1003@172.18.101.161>;tag=c5U3BgQvXDmmK
 Call-ID: 0_30549266@172.18.101.182
 CSeq: 1 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Length: 0

 ------------------------------------------------------------------------
 2015-07-01 16:19:48.617536 [WARNING] sofia_presence.c:221 Not sending to local box for 1003@172.18.101.161
 2015-07-01 16:19:48.617536 [ERR] sofia_presence.c:272 Chat proto [sip]
 from ["1002" <sip:1002@172.18.101.161:5060>;tag=1945922449]
 to [1003@172.18.101.161]
 testing
 Nobody to send to: Profile internal
 send 731 bytes to udp/[172.18.101.182]:5060 at 16:19:48.634722:
 ------------------------------------------------------------------------
 MESSAGE sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.161;rport;branch=z9hG4bK5Xr7jt5r9r75D
 Max-Forwards: 70
 From: "1003" <sip:1003@172.18.101.161>;tag=DeNvDB8Ztpa7e
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>
 Call-ID: aae1971a-2047-11e5-bb1c-8dbc1bf6c3e0
 CSeq: 77557689 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Type: text/plain
 Content-Length: 24
 X-FS-Sending-Message: a6cba934-203a-11e5-bae5-8dbc1bf6c3e0

 Hello, you said: testing

 ------------------------------------------------------------------------
 recv 358 bytes from udp/[172.18.101.182]:5060 at 16:19:48.650377:
 ------------------------------------------------------------------------
 SIP/2.0 200 OK
 Via: SIP/2.0/UDP 172.18.101.161;rport=5060;branch=z9hG4bK5Xr7jt5r9r75D
 From: "1003" <sip:1003@172.18.101.161>;tag=DeNvDB8Ztpa7e
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>;tag=1318598719
 Call-ID: aae1971a-2047-11e5-bb1c-8dbc1bf6c3e0
 CSeq: 77557689 MESSAGE
 User-Agent: Yealink SIP-T29G 46.80.0.25
 Content-Length: 0

 ------------------------------------------------------------------------

Send Successful Message, Verbose

Change the default chatplan (chatplan/default.xml) to add an info app to see the SMS event.

 <?xml version="1.0" encoding="utf-8"?>
 <include>
   <context name="default">
     <extension name="demo">
       <condition field="to" expression="^(.*)$">
         <action application="info"/> <!-- the added info app -->
         <action application="reply" data="Hello, you said: ${_body}"/>
       </condition>
     </extension>
   </context>
 </include>

Then apply in fs_cli with

 reloadxml

On the Yealink phone registered as 1001, go to Menu->Message->Text Message->New Message. Enter any message, then set the To: field to 1002.

In fs_cli, this will produce:

 recv 374 bytes from udp/[172.18.101.78]:5060 at 16:25:43.876507:
 ------------------------------------------------------------------------
 MESSAGE sip:1002@172.18.101.161 SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.78:5060;branch=z9hG4bK768884437
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=956811745
 To: <sip:1002@172.18.101.161>
 Call-ID: 0_294787559@172.18.101.78
 CSeq: 1 MESSAGE
 Content-Type: text/plain
 Max-Forwards: 70
 User-Agent: Yealink SIP-T27P 45.80.0.20
 Content-Length:    19

 greetings earthling

 ------------------------------------------------------------------------
 2015-07-01 16:25:43.857503 [INFO] mod_sms.c:336 Processing text message 1001->1002 in context public
 Chatplan: 1002 parsing [public->demo] continue=false
 Chatplan: 1002@172.18.101.161 Regex (PASS) [demo] to(1002@172.18.101.161) =~ /^(.*)$/ break=on-false
 Chatplan: 1002@172.18.101.161 Action info()
 Chatplan: 1002@172.18.101.161 Action reply(Hello, you said: ${_body})
 2015-07-01 16:25:43.857503 [INFO] mod_sms.c:463 CHANNEL_DATA:
 Event-Name: [MESSAGE]
 Core-UUID: [a6cba934-203a-11e5-bae5-8dbc1bf6c3e0]
 FreeSWITCH-Hostname: [Quentus57483]
 FreeSWITCH-Switchname: [Quentus57483]
 FreeSWITCH-IPv4: [172.18.101.161]
 FreeSWITCH-IPv6: [2601:603:c01:97f0:64d4:31ff:fed7:6b51]
 Event-Date-Local: [2015-07-01 16:25:43]
 Event-Date-GMT: [Wed, 01 Jul 2015 23:25:43 GMT]
 Event-Date-Timestamp: [1435793143857503]
 Event-Calling-File: [sofia_presence.c]
 Event-Calling-Function: [sofia_presence_handle_sip_i_message]
 Event-Calling-Line-Number: [4883]
 Event-Sequence: [1391]
 login: [sip:mod_sofia@172.18.101.161:5060]
 proto: [sip]
 to_proto: [sip]
 from: [1001@172.18.101.161]
 from_user: [1001]
 from_host: [172.18.101.161]
 to_user: [1002]
 to_host: [172.18.101.161]
 from_sip_ip: [172.18.101.78]
 from_sip_port: [5060]
 to: [1002@172.18.101.161]
 subject: [SIMPLE MESSAGE]
 context: [public]
 type: [text/plain]
 from_full: ["1001" <sip:1001@172.18.101.161:5060>;tag=956811745]
 sip_profile: [internal]
 dest_proto: [sip]
 max_forwards: [70]
 DP_MATCH: [1002@172.18.101.161]
 Content-Length: 19

 greetings earthling

 send 519 bytes to udp/[172.18.101.78]:5060 at 16:25:43.876977:
 ------------------------------------------------------------------------
 SIP/2.0 202 Accepted
 Via: SIP/2.0/UDP 172.18.101.78:5060;branch=z9hG4bK768884437
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=956811745
 To: <sip:1002@172.18.101.161>;tag=eQeNF6r3QZ0Sa
 Call-ID: 0_294787559@172.18.101.78
 CSeq: 1 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Length: 0

 ------------------------------------------------------------------------
 send 727 bytes to udp/[172.18.101.182]:5060 at 16:25:43.877527:
 ------------------------------------------------------------------------
 MESSAGE sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.161;rport;branch=z9hG4bK66H0mNpv61XrS
 Max-Forwards: 70
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=956811745
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>
 Call-ID: 7e9f5768-2048-11e5-bb1d-8dbc1bf6c3e0
 CSeq: 77557690 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Type: text/plain
 Content-Length: 19
 X-FS-Sending-Message: a6cba934-203a-11e5-bae5-8dbc1bf6c3e0

 greetings earthling

 ------------------------------------------------------------------------
 send 741 bytes to udp/[172.18.101.78]:5060 at 16:25:43.877743:
 ------------------------------------------------------------------------
 MESSAGE sip:1001@172.18.101.78:5060;line=d15ffa09c50671f SIP/2.0
 Via: SIP/2.0/UDP 172.18.101.161;rport;branch=z9hG4bK7FBSpg7Z3amBN
 Max-Forwards: 70
 From: "1002" <sip:1002@172.18.101.161>;tag=F07DH196m8pcp
 To: "1001" <sip:1001@172.18.101.78:5060;line=d15ffa09c50671f>
 Call-ID: 7e9f60b4-2048-11e5-bb1e-8dbc1bf6c3e0
 CSeq: 77557691 MESSAGE
 Contact: <sip:172.18.101.161>
 User-Agent: FreeSWITCH-mod_sofia/1.4.20+git~20150701T175516Z~39d0797abe~64bit
 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
 Supported: timer, path, replaces
 Content-Type: text/plain
 Content-Length: 36
 X-FS-Sending-Message: a6cba934-203a-11e5-bae5-8dbc1bf6c3e0

 Hello, you said: greetings earthling

 ------------------------------------------------------------------------
 recv 359 bytes from udp/[172.18.101.182]:5060 at 16:25:43.889810:
 ------------------------------------------------------------------------
 SIP/2.0 200 OK
 Via: SIP/2.0/UDP 172.18.101.161;rport=5060;branch=z9hG4bK66H0mNpv61XrS
 From: "1001" <sip:1001@172.18.101.161:5060>;tag=956811745
 To: "1002" <sip:1002@172.18.101.182:5060;line=2fc2907cbdf730d>;tag=2457624896
 Call-ID: 7e9f5768-2048-11e5-bb1d-8dbc1bf6c3e0
 CSeq: 77557690 MESSAGE
 User-Agent: Yealink SIP-T29G 46.80.0.25
 Content-Length: 0

 ------------------------------------------------------------------------
 recv 356 bytes from udp/[172.18.101.78]:5060 at 16:25:43.890480:
 ------------------------------------------------------------------------
 SIP/2.0 200 OK
 Via: SIP/2.0/UDP 172.18.101.161;rport=5060;branch=z9hG4bK7FBSpg7Z3amBN
 From: "1002" <sip:1002@172.18.101.161>;tag=F07DH196m8pcp
 To: "1001" <sip:1001@172.18.101.78:5060;line=d15ffa09c50671f>;tag=197979088
 Call-ID: 7e9f60b4-2048-11e5-bb1e-8dbc1bf6c3e0
 CSeq: 77557691 MESSAGE
 User-Agent: Yealink SIP-T27P 45.80.0.20
 Content-Length: 0

 ------------------------------------------------------------------------

Conclusion

FreeSWITCH can support multiple endpoints/protocals through its modules. Mod_sofia provides SIP; mod_conference supports SMS; mod_verto supports SMS.

You can read more about mod_sms in the FreeSWITCH online documentation: https://freeswitch.org/confluence/display/FREESWITCH/mod_sms.

Category
Tagcloud
rabbitmq amqp reviews limits hiredis freeswitch sip smpp sms yealink flowroute redis
Powered by Pelican
which takes great advantage of Python