#NEWLINE# def send_sms( self , recipient , msg ) : #NEWLINE# #INDENT# 'Sends SMS message to specified phone number using Twilio.\n\n        Args:\n            recipient: Phone number to send SMS to.\n            msg: Message to send. Long messages will automatically be truncated.\n        ' #NEWLINE# if ( self . twilio_client is None ) : #NEWLINE# #INDENT# self . logger . info ( 'Initializing Twilio' ) #NEWLINE# if ( ( cfg . TWILIO_ACCOUNT == '' ) or ( cfg . TWILIO_TOKEN == '' ) ) : #NEWLINE# #INDENT# self . logger . error ( 'Twilio account or token not specified - unable to send SMS!' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . twilio_client = TwilioRestClient ( cfg . TWILIO_ACCOUNT , cfg . TWILIO_TOKEN ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . twilio_client != None ) : #NEWLINE# #INDENT# self . logger . info ( 'Sending SMS to %s: %s' , recipient , msg ) #NEWLINE# try : #NEWLINE# #INDENT# self . twilio_client . sms . messages . create ( to = recipient , from_ = cfg . TWILIO_PHONE_NUMBER , body = truncate ( msg , 140 ) ) #NEWLINE# #UNINDENT# except TwilioRestException as ex : #NEWLINE# #INDENT# self . logger . error ( 'Unable to send SMS: %s' , recipient ) #NEWLINE# #UNINDENT# except httplib2 . ServerNotFoundError as ex : #NEWLINE# #INDENT# self . logger . error ( 'Unable to send SMS - internet connectivity issues: %s' , ex ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . logger . error ( 'Exception sending SMS: %s' , sys . exc_info ( ) [ 0 ] )