SMS engine

Engine object

If you want to add a new SMS engine, you must inherit from SMSEngine object and implement all methods describe below.

Put your SMS engine in /opt/janua/custom/engine directory and restart Janua-SMS

Example:

config_spec = """
#
# android section
#
[android]
message_timeout = integer(1000, 30000, default=1000)
"""

class AndroidSMS(SMSEngine):
    """Android SMS class interface"""
    name = 'android'
    config_spec = config_spec
 
    def __init__(self, config):
        log.debug('message timeout: %d ms' % config.android.message_timeout)
 
    def reconnect(self, event):
        pass

    ...
class janua.sms.engine.SMSEngine(config)[source]

Abstract class for SMS interface

name = None

Engine name

config_spec = None

Configuration specification for this engine. You can refer to configobj documentation

__init__(config)[source]

Engine initialization

Parameters:config – global configuration object
reconnect(event)[source]

Try to connect to modem or service in case of communication error

Parameters:event – a threading event object
send(message, to)[source]

Send SMS

Parameters:
  • message – a text message to send
  • to – recipient phone number
Returns:

a tuple containing reference which identify message and number of parts in case of multi-part SMS. Replace by None values if you don’t need to support multi-part SMS or if your engine use a service which take care of multi-part message

event()[source]

Listen event

Returns:True when a message is received or False when there is no message
process()[source]

Process SMS

Returns:a list of messages as dictionary

Message dictionary must contain followings keys:

  • body: SMS message
  • address: sender phone number
  • date: when sms was received
  • status: SMS status report if supported, None otherwise
stop()[source]

Stop

Exceptions

exception janua.sms.SMSError[source]

An exception raised while sending/receiving SMS

exception janua.sms.ModemError[source]

An exception raised while communicating with modem