from zang.exceptions.zang_exception import ZangException
from zang.configuration.configuration import Configuration
from zang.connectors.connector_factory import ConnectorFactory

from docs.examples.credentials import sid, authToken
url = 'https://api.zang.io/v2'


configuration = Configuration(sid, authToken, url=url)
smsMessagesConnector = ConnectorFactory(configuration).smsMessagesConnector

# send sms message
try:
    smsMessage = smsMessagesConnector.sendSmsMessage(
        to='(XXX) XXX-XXXX',
        body='Hello from Zang!',
        from_='(XXX) XXX-XXXX')
    view = vars(smsMessage)
    print('\n')
    for item in view:
        print (item , ' : ' , view[item])
except ZangException as e:
    print(e)


# view sms message
try:
    smsMessage = smsMessagesConnector.viewSmsMessage(smsMessage.sid)
    print(smsMessage.status)
except ZangException as e:
    print(e)
Beispiel #2
0
from datetime import date

from zang.exceptions.zang_exception import ZangException
from zang.configuration.configuration import Configuration
from zang.connectors.connector_factory import ConnectorFactory

from docs.examples.credentials import sid, authToken
url = 'http://api.zang.io/v2'

configuration = Configuration(sid, authToken, url=url)
smsMessagesConnector = ConnectorFactory(configuration).smsMessagesConnector

# send sms message
try:
    smsMessage = smsMessagesConnector.sendSmsMessage(
        to='(XXX) XXX-XXXX',
        body='Hello from Avaya CPaaS!',
        from_='(XXX) XXX-XXXX')
    print(smsMessage)
except ZangException as e:
    print(e)

# view sms message
try:
    smsMessage = smsMessagesConnector.viewSmsMessage('SmsMessageSID')
    print(smsMessage.status)
except ZangException as e:
    print(e)

# list sms messages
try:
    smsMessages = smsMessagesConnector.listSmsMessages(
    play_alert(all_zones, alert_sound, alert_volume=50, alert_duration=2, fade_back=True)

#call phone through SIP
def call_phone():
    os.system('sh /home/pi/doorbell/phone-zang.sh')

#here is the logic for the doorbell
if __name__=='__main__':
     whiteOn()
     while True:
         input_state = GPIO.input(23)
         if input_state == False:
            print('Someone is at the door!\r')
	    # outbound SMS is here using Zang
	    try:
    		smsMessage = smsMessagesConnector.sendSmsMessage(
        		to='14168305230',
        		body='Someone is at the door!',
        		from_='16477992796')
    	      	print(smsMessage)
	    except ZangException as e:
              	print(e)
            cyanOn()
       #sonos play sound for doorbell and calling using Zang SIP domain (code found inside phone-zang.sh) 
	    p3 = Process(target = call_phone)
	    p2 = Process(target = play_doorbell)
	    p3.start()
            p2.start()
	    time.sleep(5)
            whiteOn()