當前位置: 首頁>>代碼示例>>Python>>正文


Python twilio.TwilioRestException方法代碼示例

本文整理匯總了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)) 
開發者ID:hackmh,項目名稱:text_support,代碼行數:22,代碼來源:text.py

示例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 
開發者ID:mikelambert,項目名稱:dancedeets-monorepo,代碼行數:21,代碼來源:sms.py

示例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 
開發者ID:ismailakkila,項目名稱:alexa-spark,代碼行數:20,代碼來源:alexaActions.py

示例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. 
開發者ID:bmcc0605,項目名稱:frosti,代碼行數:32,代碼來源:alert.py

示例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") 
開發者ID:steelheaddigital,項目名稱:elastalert-ui,代碼行數:14,代碼來源:alerts.py

示例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 
開發者ID:rollokb,項目名稱:django-channels-celery-websocket-example,代碼行數:8,代碼來源:test_tasks.py

示例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
            })
        }) 
開發者ID:rollokb,項目名稱:django-channels-celery-websocket-example,代碼行數:35,代碼來源:tasks.py

示例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) 
開發者ID:sandeepraju,項目名稱:sulley,代碼行數:10,代碼來源:_twilio.py

示例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) 
開發者ID:HackCU,項目名稱:mercurysms,代碼行數:17,代碼來源:twilio.py

示例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) 
開發者ID:FrontlineTechWorkers,項目名稱:real-connect,代碼行數:10,代碼來源:main.py

示例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']) 
開發者ID:errbufferoverfl,項目名稱:usb-canary,代碼行數:40,代碼來源:message_handler.py


注:本文中的twilio.TwilioRestException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。