pyramid_sms package¶
Submodules¶
pyramid_sms.dummy module¶
Dummy SMS service for testing.
pyramid_sms.events module¶
-
class
pyramid_sms.events.
SMSEvent
(request: pyramid.request.Request, receiver: str, text_body: str, sender: str, user_dialog: bool)[source]¶ Bases:
object
Base class for SMS events.
All events are fired within the web application process.
-
class
pyramid_sms.events.
SMSSent
(request: pyramid.request.Request, receiver: str, text_body: str, sender: str, user_dialog: bool)[source]¶ Bases:
pyramid_sms.events.SMSEvent
Outbound SMS sent.
pyramid_sms.interfaces module¶
pyramid_sms.outgoing module¶
Outgoing SMS API.
-
pyramid_sms.outgoing.
send_sms
(request: pyramid.request.Request, receiver: str, text_body: str, sender: str=None, log_failure: bool=True, async: bool=None, user_dialog: bool=False)[source]¶ Send outgoing SMS message using the default configured SMS service.
Example:
def test_sms_view(request): '''Dummy view to simulate outgoing SMS.''' send_sms(request, "+15551231234", "Test message")
Parameters: - receiver – Receiver’s phone number as international format. You should normalize this number from all user input before passing in. See
pyramid_sms.utils
for examples. - text_body – Outbound SMS body. Usually up to 1600 characters.
- sender – Envelope from number. Needs to be configured in the service. If none use default configured “sms.default_from”.
- log_failure – If there is an exception from the SMS backend then log this using Python logging system. Otherwise raise the error as an exception.
- async – Force asynchronous operation through task subsystem. If
None
respectsms.async
settings. If the operation is asynchronous, this function returns instantly and does not block HTTP request due to slow API calls to a third party service. - user_dialog – This SMS is part of a dialog with a known user. Use this flag to log messages with the user in your conversation dashboard. Set
False
to two-factor auth tokens and such.
Raises SMSConfigurationError: If configuration settings are missing
- receiver – Receiver’s phone number as international format. You should normalize this number from all user input before passing in. See
-
pyramid_sms.outgoing.
send_templated_sms
(request: pyramid.request.Request, template: str, context: dict, receiver: str, sender: str=None, log_failure: bool=True, async: bool=None, user_dialog: bool=False)[source]¶ Send out a SMS that is constructed using a page template.
Same as
pyramid_sms.outgoing.send_sms()
, but uses templates instead of hardcoded messages.Parameters: - request – HTTP request
- template – Template name. Like
welcome_sms.txt.jinja
. - context – Dictionary passed to template rendering engine
pyramid_sms.twilio module¶
-
class
pyramid_sms.twilio.
TwilioService
(request)[source]¶ Bases:
object
Send SMS using Twilio service.
-
send_sms
(receiver, text_body, sender, log_failure)[source]¶ Asynchronous call to Twilio.
We execute the actual SMS sending (calling Twilio HTTP API) in the Celery worker process, so that we do not block HTTP response head. This is especially important if we send more than one SMS message per HTTP request.
-
pyramid_sms.utils module¶
-
pyramid_sms.utils.
get_sms_backend
(request: <InterfaceClass pyramid.interfaces.IRequest>)[source]¶ Get currently configured SMS backend.
Raise: SMSConfigurationError if nothing is configure.d