本文整理汇总了Python中twilio.TwilioRestException方法的典型用法代码示例。如果您正苦于以下问题:Python twilio.TwilioRestException方法的具体用法?Python twilio.TwilioRestException怎么用?Python twilio.TwilioRestException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twilio
的用法示例。
在下文中一共展示了twilio.TwilioRestException方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_message
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def send_message(cls, phone_number, body):
"""
Send a text message with Twilio.
Args:
phone_number(str): The phone number to which we wish to send the message.
body (str): The body of the message that we will send.
Raises:
TextException: If failed to send text message.
"""
super(TwilioText, TwilioText).send_message(phone_number, body)
client = cls._get_twilio_client()
from_number = os.environ["FROM_NUMBER"]
try:
client.messages.create(to=phone_number, from_=from_number, body=body)
except TwilioRestException as ex:
raise TextException(str(ex))
示例2: send_email_link
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def send_email_link(phone_number):
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
orig_get_cert_file = base.get_cert_file
try:
# We monkey patch the cert file to not use anything
base.get_cert_file = lambda: None
logging.info("Sending SMS to %s", phone_number)
client.messages.create(
to=phone_number,
from_="+12566932623",
body="Download the DanceDeets App at https://www.dancedeets.com/mobile_apps?action=download",
)
except TwilioRestException as e:
if 'not a valid phone number' in e.msg:
raise InvalidPhoneNumberException(e.msg)
else:
raise
finally:
base.get_cert_file = orig_get_cert_file
示例3: startJoinMeetingAction
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def startJoinMeetingAction(startJoinRoomIdVal):
getRoomDetailsResponse = sparkApi.get('rooms', {'roomId': startJoinRoomIdVal, 'showSipAddress': 'true'})
if getRoomDetailsResponse != 'Error':
roomSipVal = getRoomDetailsResponse['sipAddress']
try:
client = TwilioRestClient(main.twilio_AccountSid, main.twilio_AuthToken)
call = client.calls.create(url=main.twilioXmlPath + '/' + roomSipVal, to=main.cellPhoneE164, from_=main.twilioNumber)
callStatus = client.calls.get(call.sid).status
if callStatus != 'failed':
speechOutput = "Calling your cellphone now"
else:
speechOutput = "There is a problem connecting you to the Spark room. Please try again in a few minutes."
except TwilioRestException as e:
speechOutput = "There is a problem connecting to Twilio. Please try again in a few minutes."
else:
speechOutput = "There is a problem connecting to Cisco Spark. Please try again in a few minutes."
return speechOutput
示例4: sms_alert
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def sms_alert(sid, token, client, errorText):
returnval = 0
#read users
userFile = open("/home/pi/frosti/alertSrc/user_register/phone.txt", 'r')
users = []
#load file into list
for line in userFile:
users.append(line)
for user in users:
userList = str.split(user)
#For each user with the appropriate scope
if(userList[1] == "all" or userList[1] == scope):
try:
client.messages.create(
to = userList[0],
from_="+13609001272",
body = "\"" + errorText + "\""
)
except TwilioRestException as e:
#note: will return -1 even if only one message fails
returnval = -2
return returnval
#alert email users. Retiurn -1 on failure.
示例5: alert
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def alert(self, matches):
client = TwilioRestClient(self.twilio_accout_sid, self.twilio_auth_token)
try:
client.messages.create(body=self.rule['name'],
to=self.twilio_to_number,
from_=self.twilio_to_number)
except TwilioRestException as e:
raise EAException("Error posting to twilio: %s" % e)
elastalert_logger.info("Trigger sent to Twilio")
示例6: create_message_factory
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def create_message_factory(throw=False):
def create_message(*args, **kwargs):
if throw:
raise TwilioRestException(500, '/')
return create_message
示例7: send_phone_code
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def send_phone_code(user_id, verify_token, phone_number):
customer = Customer.objects.get(id=user_id)
# simulating a short delay
sleep(randint(3, 9))
client = TwilioRestClient( # noqa
settings.TWILLO_API_KEY,
settings.TWILLO_AUTH_TOKEN,
)
try:
client.messages.create(
to=phone_number,
from_=settings.TWILLO_FROM_NUMBER,
body="Your Verify Code is {}".format(
verify_token
)
)
# Notify the FE task has completed
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': True,
'msg': 'new message sent'
})
})
except TwilioRestException as e:
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': False,
'msg': e.msg
})
})
示例8: send
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def send(self, recipient, message):
try:
message = self.client.messages.create(
body=message, to=recipient, from_=self.phone)
except TwilioRestException as e:
# TODO: this currently hides twilio's exception.
# find a way to pass it on.
raise exceptions.ProviderError(e.message)
示例9: mass_sms
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def mass_sms(message, numbers):
error_numbers = []
for number in numbers:
if '+' not in number:
number = '+' + number
try:
get_client().messages.create(to=number, from_=FROM_TWILIO,
body=message)
except TwilioRestException as e:
logger.error(e.msg)
error_numbers += [number]
cost = float((len(numbers)-len(error_numbers)))*SMS_COST
return (error_numbers, cost)
示例10: _delete_recording
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def _delete_recording(recording_url):
sid = recording_url[recording_url.rindex('/') + 1:]
client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
try:
client.recordings.delete(sid)
app.logger.info("evt=delete_recording_success sid=%s", sid)
except TwilioRestException as e:
app.logger.warn("evt=delete_recording_fail sid=%s", sid)
示例11: send_message
# 需要导入模块: import twilio [as 别名]
# 或者: from twilio import TwilioRestException [as 别名]
def send_message(alert):
logging.debug('Opening settings.json.')
settings_file = settings.open_settings()
logging.debug('Getting Twilio settings.')
twilio_enabled = settings_file['settings']['general']['twilio']
logging.debug('Getting Slack settings.')
slack_enabled = settings_file['settings']['general']['slack']
logging.debug('Getting Pushover settings.')
pushover_enabled = settings_file['settings']['general']['pushover']
logging.debug('Checking if Twilio is enabled.')
if twilio_enabled:
logging.debug('Twilio enabled.')
logging.debug('Loading Twilio settings.')
twilio_settings = load_twilio_settings()
logging.debug('Configuring Twilio client.')
client = TwilioRestClient(twilio_settings["account_sid"], twilio_settings["auth_token"])
try:
logging.debug('Trying to send Twilio message.')
client.messages.create(body=alert,
to=twilio_settings['mobile_number'],
from_=twilio_settings["twilio_number"])
except TwilioRestException:
print('Unable to run application, correct Twilio credentials provided?')
logging.critical('Aborting... Unable to run application, Twilio credentials incorrect.')
sys.exit(406)
logging.debug('Checking if Slack is enabled.')
if slack_enabled:
logging.debug('Opening settings.json.')
slack_settings = load_slack_settings()
logging.debug('Staring up Slack Bot.')
slack_bot.run_bot(alert, slack_settings['channel_name'])
logging.debug('Checking if Pushover is enabled.')
if pushover_enabled:
logging.debug('Opening settings.json.')
pushover_settings = load_pushover_settings()
client = Client(pushover_settings['user_key'], api_token=pushover_settings['api_token'])
client.send_message(alert, priority=pushover_settings['priority'])