Package s3 :: Module s3msg :: Class S3Msg
[frames] | no frames]

Class S3Msg

source code

object --+
         |
        S3Msg

Messaging framework

Instance Methods
 
__init__(self, modem=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
compose(self, type="SMS", recipient_type=None, recipient=None, subject="", message="", url=None)
Form to Compose a Message
source code
 
process_outbox(self, contact_method="EMAIL")
Send pending messages from outbox (usually called from scheduler)
source code
 
gcm_push(self, title=None, uri=None, message=None, registration_ids=None, channel_id=None)
Push the message relating to google cloud messaging server
source code
 
send_email(self, to, subject, message, attachments=None, cc=None, bcc=None, reply_to=None, sender=None, encoding="utf-8")
Function to send Email...
source code
 
send_email_by_pe_id(self, pe_id, subject="", message="", from_address=None, system_generated=False)
API wrapper over send_by_pe_id
source code
 
send_sms_via_api(self, mobile, text="", message_id=None, channel_id=None)
Function to send SMS via Web API
source code
 
send_sms_via_modem(self, mobile, text="", channel_id=None)
Function to send SMS via locally-attached Modem...
source code
 
send_sms_via_smtp(self, mobile, text="", channel_id=None)
Function to send SMS via SMTP
source code
 
send_sms_via_tropo(self, row_id, message_id, recipient, message, network="SMS", channel_id=None)
Send a URL request to Tropo to pick a message up
source code
 
send_sms_by_pe_id(self, pe_id, message="", from_address=None, system_generated=False)
API wrapper over send_by_pe_id
source code
 
send_tweet(self, text="", recipient=None, **data)
Function to tweet.
source code
 
post_to_facebook(self, text="", channel_id=None, recipient=None, **data)
Posts a message on Facebook
source code
 
poll(self, tablename, channel_id)
Poll a Channel for New Messages
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
sanitise_phone(phone, channel_id=None)
Strip out unnecessary characters from the string: +()- & space
source code
 
decode_email(header)
Decode an RFC2047-encoded email header (e.g.
source code
 
sort_by_sender(row)
Helper method to sort messages according to sender priority.
source code
 
parse(channel_id, function_name)
Parse unparsed Messages from Channel with Parser - called from Scheduler
source code
 
send(recipient, message, subject=None)
Send a single message to an Address
source code
 
send_by_pe_id(pe_id, subject="", message="", contact_method="EMAIL", document_ids=None, from_address=None, system_generated=False, **data)
Send a single message to a Person Entity (or list thereof)
source code
 
sanitize_sender(sender)
Sanitize the email sender string to prevent MIME-encoding of the from-address (RFC2047)
source code
 
prepare_opengeosms(location_id, code="S", map="google", text="")
Function to create an OpenGeoSMS
source code
 
parse_opengeosms(message)
Function to parse an OpenGeoSMS
source code
 
get_twitter_api(channel_id=None)
Initialize Twitter API
source code
 
poll_email(channel_id)
This is a simple mailbox polling script for the Messaging Module.
source code
 
poll_mcommons(channel_id)
Fetches the inbound SMS from Mobile Commons API http://www.mobilecommons.com/mobile-commons-api/rest/#ListIncomingMessages
source code
 
poll_twilio(channel_id)
Fetches the inbound SMS from Twilio API http://www.twilio.com/docs/api/rest
source code
 
poll_rss(channel_id)
Fetches all new messages from a subscribed RSS Feed
source code
 
poll_twitter(channel_id)
Function to call to fetch tweets into msg_twitter table - called via Scheduler or twitter_inbox controller
source code
 
update_channel_status(channel_id, status, period=None)
Update the Status for a Channel
source code
 
twitter_search(search_id)
Fetch Results for a Twitter Search Query
source code
 
process_keygraph(search_id)
Process results of twitter search with KeyGraph.
source code
 
preprocess_tweet(tweet)
Preprocesses tweets to remove URLs, RTs, extra whitespaces and replace hashtags with their definitions.
source code
 
tagdef(hashtag)
Returns the definition of a hashtag.
source code
Properties

Inherited from object: __class__

Method Details

__init__(self, modem=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

sanitise_phone(phone, channel_id=None)
Static Method

source code 

Strip out unnecessary characters from the string: +()- & space

decode_email(header)
Static Method

source code 

Decode an RFC2047-encoded email header (e.g. "Dominic =?ISO-8859-1?Q?K=F6nig?=") and return it as unicode.

Parameters:
  • header - the header

sort_by_sender(row)
Static Method

source code 

Helper method to sort messages according to sender priority.

parse(channel_id, function_name)
Static Method

source code 

Parse unparsed Messages from Channel with Parser
- called from Scheduler

@param channel_id: Channel
@param function_name: Parser

compose(self, type="SMS", recipient_type=None, recipient=None, subject="", message="", url=None)

source code 

Form to Compose a Message

Parameters:
  • type - The default message type: None, EMAIL, SMS or TWITTER
  • recipient_type - Send to Persons or Groups? (pr_person or pr_group)
  • recipient - The pe_id of the person/group to send the message to
    • this can also be set by setting one of (in priority order, if multiple found): request.vars.pe_id request.vars.person_id @ToDo request.vars.group_id @ToDo request.vars.hrm_id @ToDo
  • subject - The default subject text (for Emails)
  • message - The default message text
  • url - Redirect to the specified URL() after message sent
  • formid - If set, allows multiple forms open in different tabs

send(recipient, message, subject=None)
Static Method

source code 

Send a single message to an Address

Parameters:
  • recipient - "email@address", "+4412345678", "@nick"
  • message - message body
  • subject - message subject (Email only)

send_by_pe_id(pe_id, subject="", message="", contact_method="EMAIL", document_ids=None, from_address=None, system_generated=False, **data)
Static Method

source code 

Send a single message to a Person Entity (or list thereof)

To Do:
  • contact_method = ALL
    • look up the pr_contact options available for the pe & send via all
  • This is not transaction safe
    • power failure in the middle will cause no message in the outbox

process_outbox(self, contact_method="EMAIL")

source code 

Send pending messages from outbox (usually called from scheduler)

Parameters:
  • contact_method - the output channel (see pr_contact.method)

To Do: contact_method = "ALL"

gcm_push(self, title=None, uri=None, message=None, registration_ids=None, channel_id=None)

source code 

Push the message relating to google cloud messaging server

Parameters:
  • title - The title for notification
  • message - The message to be sent to GCM server
  • api_key - The API key for GCM server
  • registration_ids - The list of id that will be notified
  • channel_id - The specific channel_id to use for GCM push

send_email(self, to, subject, message, attachments=None, cc=None, bcc=None, reply_to=None, sender=None, encoding="utf-8")

source code 

Function to send Email
- simple Wrapper over Web2Py's Email API

sanitize_sender(sender)
Static Method

source code 

Sanitize the email sender string to prevent MIME-encoding of the from-address (RFC2047)

Returns:
the sanitized sender-string

send_email_by_pe_id(self, pe_id, subject="", message="", from_address=None, system_generated=False)

source code 

API wrapper over send_by_pe_id

prepare_opengeosms(location_id, code="S", map="google", text="")
Static Method

source code 

Function to create an OpenGeoSMS

@param: location_id - reference to record in gis_location table
@param: code - the type of OpenGeoSMS:
    S = Sahana
    SI = Incident Report
    ST = Task Dispatch
@param: map: "google" or "osm"
@param: text - the rest of the message

Returns the formatted OpenGeoSMS or None if it can't find
    an appropriate location

parse_opengeosms(message)
Static Method

source code 

Function to parse an OpenGeoSMS

send_sms_via_api(self, mobile, text="", message_id=None, channel_id=None)

source code 

Function to send SMS via Web API

send_sms_via_modem(self, mobile, text="", channel_id=None)

source code 

Function to send SMS via locally-attached Modem
- needs to have the cron/sms_handler_modem.py script running

send_sms_via_smtp(self, mobile, text="", channel_id=None)

source code 

Function to send SMS via SMTP

NB Different Gateways have different requirements for presence/absence of International code

http://en.wikipedia.org/wiki/List_of_SMS_gateways http://www.obviously.com/tech_tips/SMS_Text_Email_Gateway.html

send_sms_via_tropo(self, row_id, message_id, recipient, message, network="SMS", channel_id=None)

source code 

Send a URL request to Tropo to pick a message up

send_sms_by_pe_id(self, pe_id, message="", from_address=None, system_generated=False)

source code 

API wrapper over send_by_pe_id

get_twitter_api(channel_id=None)
Static Method

source code 

Initialize Twitter API

send_tweet(self, text="", recipient=None, **data)

source code 

Function to tweet.
If a recipient is specified then we send via direct message if the recipient follows us.
- falls back to @mention (leaves less characters for the message).
Breaks long text to chunks if needed.

@ToDo: Option to Send via Tropo

post_to_facebook(self, text="", channel_id=None, recipient=None, **data)

source code 

Posts a message on Facebook

https://developers.facebook.com/docs/graph-api

poll(self, tablename, channel_id)

source code 

Poll a Channel for New Messages

poll_email(channel_id)
Static Method

source code 

This is a simple mailbox polling script for the Messaging Module. It is normally called from the scheduler.

To Do:
  • If there is a need to collect from non-compliant mailers then suggest using the robust Fetchmail to collect & store in a more compliant mailer!
  • If delete_from_server is false, we don't want to download the same messages repeatedly. Perhaps record time of fetch runs (or use info from the scheduler_run table), compare w/ message timestamp, as a filter. That may not be completely accurate, so could check msg_email for messages close to the last fetch time. Or just advise people to have a dedicated account to which email is sent, that does not also need to be read by humans. Or don't delete the fetched mail until the next run.

poll_mcommons(channel_id)
Static Method

source code 

Fetches the inbound SMS from Mobile Commons API http://www.mobilecommons.com/mobile-commons-api/rest/#ListIncomingMessages

poll_twilio(channel_id)
Static Method

source code 

Fetches the inbound SMS from Twilio API http://www.twilio.com/docs/api/rest

poll_rss(channel_id)
Static Method

source code 

Fetches all new messages from a subscribed RSS Feed

poll_twitter(channel_id)
Static Method

source code 

Function  to call to fetch tweets into msg_twitter table
- called via Scheduler or twitter_inbox controller

http://tweepy.readthedocs.org/en/v3.3.0/api.html

update_channel_status(channel_id, status, period=None)
Static Method

source code 

Update the Status for a Channel

twitter_search(search_id)
Static Method

source code 

Fetch Results for a Twitter Search Query

process_keygraph(search_id)
Static Method

source code 

Process results of twitter search with KeyGraph.

preprocess_tweet(tweet)
Static Method

source code 

Preprocesses tweets to remove URLs, RTs, extra whitespaces and replace hashtags with their definitions.

tagdef(hashtag)
Static Method

source code 

Returns the definition of a hashtag.