当前位置: 首页>>代码示例>>Python>>正文


Python rest.TwilioRestClient方法代码示例

本文整理汇总了Python中twilio.rest.TwilioRestClient方法的典型用法代码示例。如果您正苦于以下问题:Python rest.TwilioRestClient方法的具体用法?Python rest.TwilioRestClient怎么用?Python rest.TwilioRestClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twilio.rest的用法示例。


在下文中一共展示了rest.TwilioRestClient方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plugin

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def plugin(srv, item):
    """ expects (accountSID, authToken, from, to) in addrs"""

    srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target)

    try:
        account_sid, auth_token, from_nr, to_nr = item.addrs
    except:
        srv.logging.warn("Twilio target is incorrectly configured")
        return False

    text = item.message

    try:
        client = TwilioRestClient(account_sid, auth_token)
        message = client.messages.create(
                    body=text,
                    to=to_nr,
                    from_=from_nr)
        srv.logging.debug("Twilio returns %s" % (message.sid))
    except Exception as e:
        srv.logging.warn("Twilio failed: %s" % e)
        return False

    return True 
开发者ID:jpmens,项目名称:mqttwarn,代码行数:27,代码来源:twilio.py

示例2: sendsms

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def sendsms(message):
    """Send SMS via Twilio SMS API

    :param str message: SMS body to send
    """

    # read configuration from the config file
    config = check_config_values()
    account_sid = config.get('DEFAULT', 'twilio_account_sid')
    auth_token = config.get('DEFAULT', 'twilio_auth_token')
    to_phone = config.get('DEFAULT', 'twilio_to_phone')
    from_phone = config.get('DEFAULT', 'twilio_from_phone')

    client = TwilioRestClient(account_sid, auth_token)
    print("Sending this notification as SMS")
    message = client.messages.create(
        body=message, to=to_phone, from_=from_phone)
    print("SMS sent")
    # print(message.sid) 
开发者ID:sandipbgt,项目名称:twilio-fb-notification,代码行数:21,代码来源:app.py

示例3: _send

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def _send(recipients, text_content=None, html_content=None, sent_from=None, subject=None, extra_data=None,
              attachments=None):
        try:
            # twilio version 6
            from twilio.rest import Client
        except ImportError:
            try:
                # twillio version < 6
                from twilio.rest import TwilioRestClient as Client
            except ImportError:
                raise Exception(
                    "Twilio is required for sending a TwilioTextNotification."
                )

        try:
            account_sid = settings.TWILIO_ACCOUNT_SID
            auth_token = settings.TWILIO_AUTH_TOKEN
        except AttributeError:
            raise Exception(
                "TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN settings are required for sending a TwilioTextNotification"
            )

        client = Client(account_sid, auth_token)

        for recipient in recipients:
            client.messages.create(body=text_content, to=recipient, from_=sent_from) 
开发者ID:worthwhile,项目名称:django-herald,代码行数:28,代码来源:base.py

示例4: init_twilio

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def init_twilio(self):
        self.client = TwilioRestClient(self.sid, self.token) 
开发者ID:itsnauman,项目名称:postie,代码行数:4,代码来源:main.py

示例5: notify

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def notify(self, notification):
        client = TwilioRestClient(self.__config['SID'], self.__config['token'])
        try:
            client.calls.create(
                url=settings.BASE_URL + "/twilio/%s/%s" % (notification.id, notification.user_to_notify.id),
                method="GET",
                to=notification.user_to_notify.profile.phone_number,
                from_=self.__config['phone_number'])
            print 'successfully sent the call'
        except :
            print 'failed to send the call' 
开发者ID:ustream,项目名称:openduty,代码行数:13,代码来源:twilio_call.py

示例6: notify

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def notify(self, notification):
        max_length = 160
        message = (notification.message[:max_length-2] + '..') if len(notification.message) > max_length else notification.message
        client = TwilioRestClient(self.__config['SID'], self.__config['token'])
        try:
            client.sms.messages.create(body=message,
                to=notification.user_to_notify.profile.phone_number,
                from_=self.__config['sms_number'])
            print 'successfully sent the sms'
        except twilio.TwilioRestException as e:
            print 'failed to send sms, Error: %s' % e
        except :
            e = sys.exc_info()[0]
            print 'failed to send sms, Error: %s' % e 
开发者ID:ustream,项目名称:openduty,代码行数:16,代码来源:twilio_sms.py

示例7: text_myself

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def text_myself(message):
    """Use Twilo to text the message argument to your phone."""
    twilo_cli = TwilioRestClient(account_sid, auth_token)
    twilo_cli.messages.create(body=message, from_=twilo_number, to=my_number) 
开发者ID:IFinners,项目名称:automate-the-boring-stuff-projects,代码行数:6,代码来源:umbrella-reminder.py

示例8: __init__

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def __init__(self):
        try:
            number, account_sid, auth_token = utils.load_twilio_config()
            self.number = number
            self.twilio_client = TwilioRestClient(account_sid, auth_token)
        except TwilioException:
            print('\U0001F6AB  Current twilio credentials invalid. '
                  'Please reset.'.encode("utf-8"))
            utils.initialize_twiolio()
            number, account_sid, auth_token = utils.load_twilio_config()
            self.number = number
            self.twilio_client = TwilioRestClient(account_sid, auth_token) 
开发者ID:brianzq,项目名称:att-bill-splitter,代码行数:14,代码来源:services.py

示例9: send_message

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [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

示例10: __init__

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def __init__(self, config):
        super(TwilioSendSMSAction, self).__init__(config=config)
        self.client = TwilioRestClient(self.config['account_sid'],
                                       self.config['auth_token']) 
开发者ID:StackStorm,项目名称:st2,代码行数:6,代码来源:send_sms.py

示例11: _get_twilio_client

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def _get_twilio_client(self):
		account = settings.TWILIO_ACCOUNT_SID
		token = settings.TWILIO_AUTH_TOKEN
		client = TwilioRestClient(account, token)
		return client 
开发者ID:RyanBalfanz,项目名称:django-smsish,代码行数:7,代码来源:twilio.py

示例12: _Action

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def _Action(self):
        account_sid = self.redata['data']['account_sid']
        auth_token = self.redata['data']['auth_token']
        from_address = self.redata['data']['from_address']
        to_address = self.redata['data']['to_address']
        text = self.redata['data']['text']
        client = TwilioRestClient(account_sid, auth_token)
        message = client.messages.create(
            to=to_address,
            from_=from_address,
            body=text)
        assert message.status not in ('failed', 'undelivered'), \
            message.ErrorMessage
        return True 
开发者ID:Runbook,项目名称:runbook,代码行数:16,代码来源:__init__.py

示例13: sms_twilio

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def sms_twilio(data, context):
	'''
	Sends an SMS message via Twilio to the given number.
	The message is "[title] message"
	config must include the strings twilio_accountsid, twilio_authtoken, and twilio_number

	data['number']: phone number to send SMS message to.
	data['twilio_accountsid'], data['twilio_authtoken'], data['twilio_number']: optional Twilio configuration
	context['title']: used in creating SMS message
	context['message']: used in creating SMS message
	'''
	from config import config
	from twilio.rest import TwilioRestClient

	if 'number' not in data:
		util.die('alert_sms_twilio: missing number')

	config_target = config

	if 'twilio_accountsid' in data and 'twilio_authtoken' in data and 'twilio_number' in data:
		config_target = data

	sms_message = "[%s] %s" % (context['title'], context['message'])
	client = TwilioRestClient(config_target['twilio_accountsid'], config_target['twilio_authtoken'])

	message = client.messages.create(body = sms_message, to = data['number'], from_ = config_target['twilio_number']) 
开发者ID:uakfdotb,项目名称:pybearmon,代码行数:28,代码来源:alerts.py

示例14: __init__

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import TwilioRestClient [as 别名]
def __init__(self, message):
        
        self.entity = message['entity']
        self.status = int(message['status'])
        self.output = message['output']
              
        if int(message['status']) == 0:
            self.color = '#36a64f'
            self.twilio_msg_prefix = 'recovery notification.'
            self.twilio_msg_postfix = 'is okay!'
        elif int(message['status']) == 1:
            self.color = '#FFA500'
            self.twilio_msg_prefix = 'this is a warning!'
            self.twilio_msg_postfix = 'is in status warning!'
        elif int(message['status']) == 2:
            self.color = '#C74350'
            self.twilio_msg_prefix = 'bad news, this is a critical notification!'
            self.twilio_msg_postfix = 'is in status critical!'
        else:
            self.color = ''
            self.twilio_msg_prefix = 'unknown notification.'
            self.twilio_msg_postfix = 'is in status unknown!'
        
        slack_alert_template     = get_template('isubscribe/slack_alert.txt')
        self.slack_msg_content_fallback = slack_alert_template.render({ 'entity': self.entity, 'status': self.status, 'output':self.output })
        
        
        
        self.slack_attachments = [{
                    "fallback": self.slack_msg_content_fallback,
                    "title": self.entity,
                    "title_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
                    "text": self.output,
                    "color": self.color,
                    "author_name": settings.SLACK_BOT_NAME,
                    "author_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
                    "author_icon": settings.SLACK_BOT_ICON,
        }]
               
        twilio_msg_formated = self.twilio_msg_prefix + ' ' + self.entity + ' ' + self.twilio_msg_postfix
        self.twilio_params = { 'msg' : twilio_msg_formated,
                               'api_token' : settings.TWILIO_CALLBACK_API_TOKEN,
                               'entity': self.entity, 
                               'status': self.status 
                            }
        
        self.twilio_client = TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
        
        self.slack_delivery_to = []
        self.twilio_delivery_to = [] 
开发者ID:ilavender,项目名称:sensu_drive,代码行数:52,代码来源:notify.py


注:本文中的twilio.rest.TwilioRestClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。