當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。