📄 app-sms.tex
字号:
\section{Introduction} The SMS module for Asterisk was developed by Adrian Kennard, and is an implementation of the ETSI specification for landline SMS, ETSI ES 201 912, which is available from \url{www.etsi.org}. Landline SMS is starting to be available in various parts of Europe, and is available from BT in the UK. However, Asterisk would allow gateways to be created in other locations such as the US, and use of SMS capable phones such as the Magic Messenger. SMS works using analogue or ISDN lines.\section{Background} Short Message Service (SMS), or texting is very popular between mobile phones. A message can be sent between two phones, and normally contains 160 characters. There are ways in which various types of data can be encoded in a text message such as ring tones, and small graphic, etc. Text messaging is being used for voting and competitions, and also SPAM... Sending a message involves the mobile phone contacting a message centre (SMSC) and passing the message to it. The message centre then contacts the destination mobile to deliver the message. The SMSC is responsible for storing the message and trying to send it until the destination mobile is available, or a timeout. Landline SMS works in basically the same way. You would normally have a suitable text capable landline phone, or a separate texting box such as a Magic Messenger on your phone line. This sends a message to a message centre your telco provides by making a normal call and sending the data using 1200 Baud FSK signaling according to the ETSI spec. To receive a message the message centre calls the line with a specific calling number, and the text capable phone answers the call and receives the data using 1200 Baud FSK signaling. This works particularly well in the UK as the calling line identity is sent before the first ring, so no phones in the house would ring when a message arrives.\section{Typical use with Asterisk} Sending messages from an Asterisk box can be used for a variety of reasons, including notification from any monitoring systems, email subject lines, etc. Receiving messages to an Asterisk box is typically used just to email the messages to someone appropriate - we email and texts that are received to our direct numbers to the appropriate person. Received messages could also be used to control applications, manage competitions, votes, post items to IRC, anything. Using a terminal such as a magic messenger, an Asterisk box could ask as a message centre sending messages to the terminal, which will beep and pop up the message (and remember 100 or so messages in its memory).\section{Terminology}\begin{itemize} \item SMS - Short Message Service i.e. text messages \item SMSC - Short Message Service Centre The system responsible for storing and forwarding messages \item MO - Mobile Originated A message on its way from a mobile or landline device to the SMSC \item MT - Mobile Terminated A message on its way from the SMSC to the mobile or landline device \item RX - Receive A message coming in to the Asterisk box \item TX - Transmit A message going out of the Asterisk box\end{itemize}\section{Sub address} When sending a message to a landline, you simply send to the landline number. In the UK, all of the mobile operators (bar one) understand sending messages to landlines and pass the messages to the BTText system for delivery to the landline. The specification for landline SMS allows for the possibility of more than one device on a single landline. These can be configured with Sub addresses which are a single digit. To send a message to a specific device the message is sent to the landline number with an extra digit appended to the end. The telco can define a default sub address (9 in the UK) which is used when the extra digit is not appended to the end. When the call comes in, part of the calling line ID is the sub address, so that only one device on the line answers the call and receives the message. Sub addresses also work for outgoing messages. Part of the number called by the device to send a message is its sub address. Sending from the default sub address (9 in the UK) means the message is delivered with the sender being the normal landline number. Sending from any other sub address makes the sender the landline number with an extra digit on the end. Using Asterisk, you can make use of the sub addresses for sending and receiving messages. Using DDI (DID, i.e. multiple numbers on the line on ISDN) you can also make use of many different numbers for SMS.\section{extensions.conf} The following contexts are recommended.\begin{astlisting}\begin{verbatim}; Mobile Terminated, RX. This is used when an incoming call from the SMS arrives, with the queue (called number and sub address) in ${EXTEN}; Running an app after receipt of the text allows the app to find all messagesin the queue and handle them, e.g. email them.; The app may be something like smsq --process=somecommand --queue=${EXTEN}to run a command for each received message; See below for usage[smsmtrx]exten = _X.,1, SMS(${EXTEN},a)exten = _X.,2,System("someapptohandleincomingsms ${EXTEN}")exten = _X.,3,Hangup; Mobile originated, RX. This is receiving a message from a device, e.g.; a Magic Messenger on a sip extension; Running an app after receipt of the text allows the app to find all messages; in the queue and handle then, e.g. sending them to the public SMSC; The app may be something like smsq --process=somecommand --queue=${EXTEN}; to run a command for each received message; See below for example usage[smsmorx]exten = _X.,1, SMS(${EXTEN},sa)exten = _X.,2,System("someapptohandlelocalsms ${EXTEN}")exten = _X.,3,Hangup\end{verbatim}\end{astlisting} smsmtrx is normally accessed by an incoming call from the SMSC. In the UK this call is from a CLI of 080058752X0 where X is the sub address. As such a typical usage in the extensions.conf at the point of handling an incoming call is:\begin{astlisting}\begin{verbatim}exten = _X./8005875290,1,Goto(smsmtrx,${EXTEN},1)exten = _X./_80058752[0-8]0,1,Goto(smsmtrx,${EXTEN}-${CALLERID(num):8:1},1)\end{verbatim}\end{astlisting} Alternatively, if you have the correct national prefix on incoming CLI, e.g. using dahdi\_hfc, you might use:\begin{astlisting}\begin{verbatim}exten = _X./08005875290,1,Goto(smsmtrx,${EXTEN},1)exten = _X./_080058752[0-8]0,1,Goto(smsmtrx,${EXTEN}-${CALLERID(num):9:1},1)\end{verbatim}\end{astlisting} smsmorx is normally accessed by a call from a local sip device connected to a Magic Messenger. It could however by that you are operating Asterisk as a message centre for calls from outside. Either way, you look at the called number and goto smsmorx. In the UK, the SMSC number that would be dialed is 1709400X where X is the caller sub address. As such typical usage in extension.config at the point of handling a call from a sip phone is:\begin{astlisting}\begin{verbatim}exten = 17094009,1,Goto(smsmorx,${CALLERID(num)},1)exten = _1709400[0-8],1,Goto(smsmorx,${CALLERID(num)}-{EXTEN:7:1},1)\end{verbatim}\end{astlisting}\section{Using smsq} smsq is a simple helper application designed to make it easy to send messages from a command line. it is intended to run on the Asterisk box and have direct access to the queue directories for SMS and for Asterisk. In its simplest form you can send an SMS by a command such as smsq 0123456789 This is a test to 0123456789 This would create a queue file for a mobile originated TX message in queue 0 to send the text "This is a test to 0123456789" to 0123456789. It would then place a file in the \path{/var/spool/asterisk/outgoing} directory to initiate a call to 17094009 (the default message centre in smsq) attached to application SMS with argument of the queue name (0). Normally smsq will queue a message ready to send, and will then create a file in the Asterisk outgoing directory causing Asterisk to actually connect to the message centre or device and actually send the pending message(s). Using \verb!--process!, smsq can however be used on received queues to run a command for each file (matching the queue if specified) with various environment variables set based on the message (see below); smsq options:\begin{verbatim} --help Show help text --usage Show usage --queue -q Specify a specific queue In no specified, messages are queued under queue "0" --da -d Specify destination address --oa -o Specify originating address This also implies that we are generating a mobile terminated message --ud -m Specify the actual message --ud-file -f Specify a file to be read for the context of the message A blank filename (e.g. --ud-file= on its own) means read stdin. Very useful when using via ssh where command line parsing could mess up the message. --mt -t Mobile terminated message to be generated --mo Mobile originated message to be generated Default --tx Transmit message Default --rx -r Generate a message in the receive queue --UTF-8 Treat the file as UTF-8 encoded (default) --UCS-1 Treat the file as raw 8 bit UCS-1 data, not UTF-8 encoded --UCS-2 Treat the file as raw 16 bit bigendian USC-2 data --process Specific a command to process for each file in the queue Implies --rx and --mt if not otherwise specified. Sets environment variables for every possible variable, and also ud, ud8 (USC-1 hex), and ud16 (USC-2 hex) for each call. Removes files. --motx-channel Specify the channel for motx calls May contain X to use sub address based on queue name or may be full number Default is Local/1709400X --motx-callerid Specify the caller ID for motx calls The default is the queue name without -X suffix --motx-wait Wait time for motx call Default 10 --motx-delay
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -