示例#1
0
 def get_sms_response(self, phone_number):
     account = twilio.Account(settings.TWILIO_ACCOUNT_SID,
                              settings.TWILIO_ACCOUNT_TOKEN)
     response = account.request(
         '/2010-04-01/Accounts/%s/SMS/Messages.json' %
         settings.TWILIO_ACCOUNT_SID, 'POST',
         dict(From=self.sms_number, To=phone_number, Body=self.body))
     return json.loads(response)
示例#2
0
    def sendSMS(self,body):

        import twilio

        recipient = self.phone
        account = twilio.Account(TWILIO_ID, TWILIO_TOKEN)
        params = { 'From': TWILIO_NUM, 'To': recipient, 'Body': body, }
        account.request('/%s/Accounts/%s/SMS/Messages' % (TWILIO_API_VERSION, TWILIO_ID), 'POST', params)
示例#3
0
    def configure(self, host="localhost", port=8080, config=None, **kwargs):

        super(TwilioBackend, self).configure(host, port, **kwargs)
        self.config = config
        self.account = twilio.Account(self.config['account_sid'],
                                      self.config['auth_token'])

        # has the added benefit of failing hard if this is set wrong
        self.debug("using api version %s" % self.api_version)
示例#4
0
	def StartCall(self):
		account = twilio.Account(gTwilioSid, gTwilioToken)
		d = {
				'Caller':		gPhoneNumber,
				'Called':		self.number,
				'Url':			'http://%s/answered/%s'%(gAppHost, self.key()),
				'Method':		'GET'
		}
		account.request('/2008-08-01/Accounts/%s/Calls' % (gTwilioSid), 'POST', d)
		self.trys+=1
		self.put()
示例#5
0
def twilio_update(sid):
    """Update status for a given SMS. """

    account = twilio.Account(app.config['ACCOUNT_SID'],
                             app.config['ACCOUNT_TOKEN'])

    tw_response = account.request(
        '/%s/Accounts/%s/SMS/Messages/%s.json' %
        (app.config['API_VERSION'], app.config['ACCOUNT_SID'], sid), 'GET')

    return tw_response
示例#6
0
文件: views.py 项目: tonomuniz/tiger
 def post(self, request, *args, **kwargs):
     account = twilio.Account(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_ACCOUNT_TOKEN)
     if request.method == 'POST':
         sms = request.site.sms
         account.request(
             '/2010-04-01/Accounts/%s/IncomingPhoneNumbers/%s' % (settings.TWILIO_ACCOUNT_SID, sms.sid), 
             'DELETE' 
         )
         sms.sms_number = sms.sid = None
         sms.save()
         messages.success(request, "Your SMS number has been disabled.")
         return HttpResponseRedirect(reverse('sms_home'))
示例#7
0
 def post(self):
     logging.info("Outbound SMS for ID %s to %s" %
                  (self.request.get('sid'), self.request.get('phone')))
     account = twilio.Account(config.ACCOUNT_SID, config.ACCOUNT_TOKEN)
     sms = {
         'From': config.CALLER_ID,
         'To': self.request.get('phone'),
         'Body': self.request.get('text'),
     }
     try:
         account.request(
             '/%s/Accounts/%s/SMS/Messages' %
             (config.API_VERSION, config.ACCOUNT_SID), 'POST', sms)
     except Exception, e:
         logging.error("Twilio REST error: %s" % e)
示例#8
0
 def send_sms_for_note(klass, note):
     tw = twilio.Account(settings.TWILIO_SID, settings.TWILIO_TOKEN)
     sms_params = {
         'From': settings.TWILIO_NUMBER,
         'To': settings.SHREYANS_NUMBER,
         'Body': note[0:140]
     }
     post_url = '/%s/Accounts/%s/SMS/Messages' % (
         settings.TWILIO_API_VERSION, settings.TWILIO_SID)
     try:
         tw.request(post_url, 'POST', sms_params)
         return True
     except Exception, e:
         print e
         print e.read()
         return False
示例#9
0
def sendSms(sms_message):
    data = {
        'From': s.SMS_GATEWAY,
        'To': sms_message.phone_number,
        'Body': sms_message.message,
        'StatusCallback': 'https://%s/smsgateway/twilio/callback' % s.HOST
    }
    account = twilio.Account(s.TWILIO_ACCOUNT_ID, s.TWILIO_AUTH_TOKEN)
    response = account.request(URL_BASE + '/SMS/Messages',
                               method='POST',
                               vars=data)

    sms_message.twilio_sid = SID_REGEX.search(response).groups()[0]
    sms_message.status = 'sent'

    sms_message.put()
示例#10
0
def twilio_send(phone_number, message):
    """Sends an SMS via the Twilio service. """

    data = {
        'From': app.config['CALLER_ID'],
        'To': phone_number,
        'Body': message
    }

    account = twilio.Account(app.config['ACCOUNT_SID'],
                             app.config['ACCOUNT_TOKEN'])

    tw_response = account.request(
        '/%s/Accounts/%s/SMS/Messages.json' %
        (app.config['API_VERSION'], app.config['ACCOUNT_SID']), 'POST', data)

    return tw_response
示例#11
0
def initiate_call(request, **kwargs):
    """
    Initiate a Twilio call using the parameters in kwargs.  The method should
    check that the required parameters are given.
    """
    from django.conf import settings
    assert 'From' in kwargs, "'From' is required when initiating a call."
    assert 'To' in kwargs, "'To' is required when initiating a call."
    assert 'Url' in kwargs, "'Url' is required when initiating a call."

    account = twilio.Account(
        settings.TWILIO_ACCOUNT_SID,
        settings.TWILIO_ACCOUNT_TOKEN,
    )

    url = "/%s/Accounts/%s/Calls" % (
        settings.TWILIO_API_VERSION,
        settings.TWILIO_ACCOUNT_SID,
    )
    host = "http://%s" % request.META['HTTP_HOST']
    account.request(url, 'POST', kwargs)
示例#12
0
def get_account(config):
    account = twilio.Account(config.twilio_account_sid,
                             config.twilio_account_token)
    return account
示例#13
0
#!/usr/bin/env python

import twilio

# Twilio REST API version
API_VERSION = '2010-04-01'

# Twilio AccountSid and AuthToken
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'

# Outgoing Caller ID previously validated with Twilio
CALLER_ID = 'NNNNNNNNNN';

# Create a Twilio REST account object using your Twilio account ID and token
account = twilio.Account(ACCOUNT_SID, ACCOUNT_TOKEN)

# ===========================================================================
# 1. Initiate a new outbound call to 415-555-1212
#    uses a HTTP POST
d = {
    'From' : CALLER_ID,
    'To' : '415-555-1212',
    'Url' : 'http://demo.twilio.com/welcome',
}
try:
    print account.request('/%s/Accounts/%s/Calls' % \
                              (API_VERSION, ACCOUNT_SID), 'POST', d)
except Exception, e:
    print e
    print e.read()
示例#14
0
#!/usr/bin/env python
from settings import WALRUS_DOMAIN
import twilio
from creds import TWILIO_ACCOUNT_SID, TWILIO_ACCOUNT_TOKEN, TWILIO_CALLER_ID

# Twilio REST API version
API_VERSION = '2010-04-01'

# Create a Twilio REST account object using your Twilio account ID and token
account = twilio.Account(TWILIO_ACCOUNT_SID, TWILIO_ACCOUNT_TOKEN)

# ===========================================================================
# 1. Initiate a new outbound call to 415-555-1212
#    uses a HTTP POST
d = {
    'From' : TWILIO_CALLER_ID,
    'To' : '(865) 484-6657',
    'Url' : '%s/jobs/make-wakeup-calls' % WALRUS_DOMAIN,
}
try:
    print account.request('/%s/Accounts/%s/Calls.json' % \
                              (API_VERSION, TWILIO_ACCOUNT_SID), 'POST', d)
except Exception, e:
    print e
    print e.read()

# ===========================================================================
# 2. Get a list of recent completed calls (i.e. Status = 2)
#    uses a HTTP GET
d = { 'Status':2, }
try:
示例#15
0
    def __init__(self, id, token):
        self.id = id
        self.token = token
        self.api_version = '2008-08-01'

        self.account = twilio_official.Account(id, token)
示例#16
0
文件: views.py 项目: tonomuniz/tiger
 def account(self):
     return twilio.Account(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_ACCOUNT_TOKEN)