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


Python rest.Client方法代码示例

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


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

示例1: placeCall

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def placeCall():
  account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
  api_key = os.environ.get("API_KEY", API_KEY)
  api_key_secret = os.environ.get("API_KEY_SECRET", API_KEY_SECRET)

  client = Client(api_key, api_key_secret, account_sid)
  to = request.values.get("to")
  call = None

  if to is None or len(to) == 0:
    call = client.calls.create(url=request.url_root + 'incoming', to='client:' + IDENTITY, from_=CALLER_ID)
  elif to[0] in "+1234567890" and (len(to) == 1 or to[1:].isdigit()):
    call = client.calls.create(url=request.url_root + 'incoming', to=to, from_=CALLER_NUMBER)
  else:
    call = client.calls.create(url=request.url_root + 'incoming', to='client:' + to, from_=CALLER_ID)
  return str(call) 
开发者ID:twilio,项目名称:voice-quickstart-server-python,代码行数:18,代码来源:server.py

示例2: SendNotice

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def SendNotice(Message):

    try:

        client = Client(account_sid, auth_token)

        message = client.messages.create(
            to= to_number,
            from_ = from_number,
            body = Message)

        console.info(message.sid)

    except Exception as e1:
        log.error("Error: " + str(e1))
        console.error("Error: " + str(e1))

#------------------- Command-line interface for gengpio ------------------------ 
开发者ID:jgyates,项目名称:genmon,代码行数:20,代码来源:gensms.py

示例3: notify

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def notify(args, price_alert):
    """ Send notification via Twilio if notification hasn't already been sent """
    # Change twilio logging 
    twilio_logger = logging.getLogger('twilio.http_client')
    twilio_logger.setLevel(logging.WARNING)
    if args.twilio in ('None', 'False'):
        return
    twilio_dict = {str(k): str(v) for k, v in json.load(open(args.twilio)).items()}
    if twilio_dict['account'] == 'twilio_account':
        logger.info('Please update twilio.json file for notifications.')
    else:
        client = Client(twilio_dict['account'], twilio_dict['auth_token'])
        client.api.account.messages.create(
            to=twilio_dict['to'],
            from_=twilio_dict['from'],
            body=price_alert)
        logger.info('User notified.') 
开发者ID:broadtoad,项目名称:Flight_Tracker,代码行数:19,代码来源:utils.py

示例4: post_receive

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def post_receive(self, alert):

        if alert.repeat:
            return

        message = "%s: %s alert for %s - %s is %s" % (
            alert.environment, alert.severity.capitalize(),
            ','.join(alert.service), alert.resource, alert.event
        )

        client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
        for twilio_to in TWILIO_TO_NUMBER.split(','):
            LOG.debug('Twilio SMS: Send message from {}, to {}'.format(TWILIO_FROM_NUMBER, twilio_to))
            try:
                message = client.messages.create(body=message, to=twilio_to, from_=TWILIO_FROM_NUMBER)
            except TwilioRestException as e:
                LOG.error('Twilio SMS: ERROR - {}'.format(str(e)))
            else:
                LOG.info("Twilio SMS: Message ID: %s", message.sid) 
开发者ID:alerta,项目名称:alerta-contrib,代码行数:21,代码来源:alerta_twilio_sms.py

示例5: SendWhatsappMessage

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def SendWhatsappMessage(messageToSend):
    if (theConfig.CONFIG_INPUT_MODE_IS_REAL_MARKET == True):
        pass
        # Your Account Sid and Auth Token from twilio.com/console
#         account_sid = '<fill id here>'
#         auth_token = '<fill id here>'
#         client = Client(account_sid, auth_token)
#         
#         
#         message = client.messages.create(
#                                       body=messageToSend,
#                                       from_='whatsapp:+<fill number here>',
#                                       to='whatsapp:+<fill number here>'
#                                   )
#              
#         print("NOTI - Sent message, %s" % message) 
开发者ID:Florian455,项目名称:Astibot,代码行数:18,代码来源:Notifier.py

示例6: send_sms

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def send_sms():
    """Sends a simple SMS message."""
    to = request.args.get('to')
    if not to:
        return ('Please provide the number to message in the "to" query string'
                ' parameter.'), 400

    client = rest.Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
    rv = client.messages.create(
        to=to,
        from_=TWILIO_NUMBER,
        body='Hello from Twilio!'
    )
    return str(rv)
# [END gae_flex_twilio_send_sms]


# [START gae_flex_twilio_receive_sms] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20,代码来源:main.py

示例7: send_supplement_reminder

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def send_supplement_reminder(supplement_reminder_id):
    reminder = SupplementReminder.objects.get(id=supplement_reminder_id)

    reminder_text = 'BetterSelf.io - Daily Reminder to take {} of {}! Reply DONE when done!'.format(
        reminder.quantity, reminder.supplement.name)

    phone_to_text = reminder.user.userphonenumberdetails.phone_number.as_e164

    # autosave prior to sending to client, just in case twilio is down
    # this would queue up too many things
    reminder.last_sent_reminder_time = get_current_utc_time_and_tz()
    reminder.save()

    client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
    client.messages.create(
        to=phone_to_text,
        from_=settings.TWILIO_PHONE_NUMBER,
        body=reminder_text) 
开发者ID:jeffshek,项目名称:betterself,代码行数:20,代码来源:tasks.py

示例8: __init__

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def __init__(self, **options):
        super(TwilioBackend, self).__init__(**options)
        # Lower case it just to be sure
        options = {key.lower(): value for key, value in options.items()}
        self._sid = options.get("sid", None)
        self._secret = options.get("secret", None)  # auth_token
        self._from = options.get("from", None)

        self.client = TwilioRestClient(self._sid, self._secret)
        self.exception_class = TwilioRestException 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:12,代码来源:twilio.py

示例9: _send

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

示例10: connect

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def connect(self, params):
        account_sid = params.get('credentials').get('username')
        auth_token = params.get('credentials').get('password')
        self.client = Client(account_sid, auth_token)
        self.twilio_phone_number = params.get('twilio_phone_number')

        self.logger.info("connecting") 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:9,代码来源:connection.py

示例11: send_sms

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def send_sms(self, from_number, to_number, msg):
            """ Send message via twilio account. """
            client = Client(self.account_sid, self.auth_token)
            client.messages.create(to=to_number, from_=from_number, body=msg) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:6,代码来源:utils.py

示例12: check_profainty

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def check_profainty(text_to_check):
    account_sid = "ACdXXXXXXXXXXXXXXXX" #ادخل هذا الرقم من twilio
    auth_token = "3bXXXXXXXXXXXXXXXXX" #ادخل هذا الرقم من twilio
    client = Client(account_sid, auth_token)
    connection = urllib.urlopen("http://www.wdylike.appspot.com/?q=" + text_to_check)
    output= connection.read()
    #print (output)
    connection.close()

    if "true" in output:
        message = client.messages.create(
            body="profainty Alert!",
            to="+213xxxxxxxx", # ضع رقم هاتفك
            from_="+143xxxxxxx") # ضع رقمك في موقع twilio
        print(message.sid)

    elif "false" in output:
        message = client.messages.create(
            body="This document has no curse words!",
            to="+213xxxxxxxx", # ضع رقم هاتفك
            from_="+143xxxxxxx") # ضع رقمك في موقع twilio
        print(message.sid)

    else:
        message = client.messages.create(
            body="Could not scan the document properly.",
            to="+213xxxxxxxx", # ضع رقم هاتفك
            from_="+143xxxxxxx") # ضع رقمك في موقع twilio
        print(message.sid)

# الخطوة الأخيرة, ولكن في الواقع , هذه الخطوة الأولى, عندما تقوم بتشغيل البرنامج,
# هذه الدالة سوف تبدأ بالعمل على استدعاء دالة read_text . 
开发者ID:remon,项目名称:pythonCodes,代码行数:34,代码来源:(Twilio + Profanity) Arabic version.py

示例13: check_profanity

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def check_profanity(text_to_check):
    account_sid = "ACdXXXXXXXXXXXXXXXX" # Entrez votre twilio account_sid
    auth_token = "3bXXXXXXXXXXXXXXXXX" # Entrez votre twilio account_token
    client = Client(account_sid, auth_token)
    connection = urllib.urlopen("http://www.wdylike.appspot.com/?q=" + text_to_check)
    output= connection.read()
    #print (output)
    connection.close()

    if "true" in output:
        message = client.messages.create(
            body="profainty Alert!",
            to="+213xxxxxxxx", # mettez votre numéro de téléphone
            from_="+143xxxxxxx")# mettez votre numéro de téléphone sur Twilio
        print(message.sid)

    elif "false" in output:
        message = client.messages.create(
            body="This document has no curse words!",
            to="+213xxxxxxxx",# mettez votre numéro de téléphone
            from_="+143xxxxxxx")# mettez votre numéro de téléphone sur Twilio
        print(message.sid)

    else:
        message = client.messages.create(
            body="Could not scan the document properly.",
            to="+213xxxxxxxx",# mettez votre numéro de téléphone
            from_="+143xxxxxxx")# mettez votre numéro de téléphone sur Twilio
        print(message.sid)

# La dernière étape, mais en fait, c'est la première étape, lorsque vous exécutez ce programme,
# Cette def commencera dans le begging pour invoquer read_text def. 
开发者ID:remon,项目名称:pythonCodes,代码行数:34,代码来源:(Twilio + Profanity) French version.py

示例14: check_profanity

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def check_profanity(text_to_check):
    account_sid = "ACdXXXXXXXXXXXXXXXX" #Enter your twilio account_sid
    auth_token = "3bXXXXXXXXXXXXXXXXX" # Enter your twilio account_token
    client = Client(account_sid, auth_token)
    connection = urllib.urlopen("http://www.wdylike.appspot.com/?q=" + text_to_check)
    output= connection.read()
    #print (output)
    connection.close()

    if "true" in output:
        message = client.messages.create(
            body="profainty Alert!",
            to="+213xxxxxxxx", # put your number phone
            from_="+143xxxxxxx")# put your number phone on Twilio
        print(message.sid)

    elif "false" in output:
        message = client.messages.create(
            body="This document has no curse words!",
            to="+213xxxxxxxx",# put your number phone
            from_="+143xxxxxxx")# put your number phone on Twilio
        print(message.sid)

    else:
        message = client.messages.create(
            body="Could not scan the document properly.",
            to="+213xxxxxxxx",# put your number phone
            from_="+143xxxxxxx")# put your number phone on Twilio
        print(message.sid)

# The last step, but in fact, this is the first step, when you run this program,
# This def will start in the begging to summon read_text def. 
开发者ID:remon,项目名称:pythonCodes,代码行数:34,代码来源:(Twilio + Profanity) English version.py

示例15: __init__

# 需要导入模块: from twilio import rest [as 别名]
# 或者: from twilio.rest import Client [as 别名]
def __init__(self):
        logger.debug('Initializing messaging client')

        (
            twilio_number,
            twilio_account_sid,
            twilio_auth_token,
        ) = load_twilio_config()

        self.twilio_number = twilio_number
        self.twilio_client = Client(twilio_account_sid, twilio_auth_token)

        logger.debug('Twilio client initialized') 
开发者ID:TwilioDevEd,项目名称:server-notifications-django,代码行数:15,代码来源:middleware.py


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