def mute(): participant = request.json['participant'] mute_on = request.json['muteOn'] conf_sid = request.json['conferenceSid'] client = Client(current_user.twilio_account_sid, current_user.twilio_auth_token) participant = client.conferences('StusConference') \ .participants(participant) \ .update(muted=mute_on) return participant.muted, 200
def barge(): print("posted to barge doc") print(conference_sid + ' is my conference and ' + manager_sid + ' is the manager sid') account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['AUTH_TOKEN'] client = Client(account_sid, auth_token) participant = client.conferences(conference_sid) \ .participants(manager_sid) \ .update(muted="False") return ''
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .participants('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .update(muted=True) print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) client.conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \ .participants("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \ .delete()
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) conference = client.conferences('CFbbe46ff1274e283f7e3ac1df0072ab39') \ .update(announce_url='http://www.myapp.com/announce') print(conference.friendly_name)
def parse_events(): account_sid = request.form['AccountSid'] TWILIO_SYNC_SERVICE_SID = current_app.config['TWILIO_SYNC_SERVICE_SID'] user = User.query.filter_by(twilio_account_sid=account_sid).first() pprint(user) pprint(user.sync_map_sid) TWILIO_SYNC_MAP_SID = user.sync_map_sid request_dict = {} request_dict = request.form.to_dict() pprint(request_dict) event = request_dict['StatusCallbackEvent'] pprint(event) if 'CallSid' in request_dict: call_sid = request_dict['CallSid'] else: call_sid = None conference_sid = request_dict['ConferenceSid'] muted = False if 'Muted' not in request_dict or request_dict[ 'Muted'] == 'false' else True pprint(event) client = Client(current_app.config['TWILIO_ACCOUNT_SID'], current_app.config['TWILIO_AUTH_TOKEN']) if event == 'participant-join': call = client.calls(call_sid).fetch() pprint(call) pprint("CALL DETAILS {}".format(call.from_formatted)) participant_number = call.from_formatted if call.direction == "inbound" else call.to_formatted data = { "conferenceSid": conference_sid, "callSid": call_sid, "participantNumber": participant_number, "direction": call.direction, "muted": False, "speaking": False, "dropped": False } conference_id = UserConference.query.filter_by( call_sid=conference_sid).first() print(conference_id) if conference_id is None: user = User.query.filter_by(twilio_account_sid=account_sid).first() conference_data = UserConference(call_sid=conference_sid, name="The Marae", account_sid=account_sid) db.session.add(conference_data) db.session.commit() user.conferences.append(conference_data) conference_id = UserConference.query.filter_by( call_sid=conference_sid).first() user.send_sms( "Your conference has started! {} is already in The Marae {}". format(participant_number, url_for('main.index', _external=True))) participant = Participant(number=data['participantNumber'], direction=data['direction'], call_sid=data['callSid']) db.session.add(participant) db.session.commit() conference_id.participants.append(participant) print("DATA >>> {}".format(data)) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items \ .create(key=call_sid, data=data) print("MAP ITEM >>> {}".format(map_item)) return "OK", 200 elif event == 'participant-speech-start': print("{} >>> SPEAKING!".format(call_sid)) current_data = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .fetch() new_data = current_data.data new_data["speaking"] = True data = json.dumps(new_data) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .update(data=str(data)) return "OK", 200 elif event == 'participant-speech-stop': print("{} >>> STOPPED SPEAKING!".format(call_sid)) current_data = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .fetch() new_data = current_data.data new_data["speaking"] = False data = json.dumps(new_data) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .update(data=str(data)) return "OK", 200 elif event == 'participant-leave': print("{} >>> LEFT THE CONFERENCE!".format(call_sid)) participant = Participant.query.filter_by(call_sid=call_sid).first() print("PARTICIPANT >>> ") print(participant) client = Client(user.twilio_account_sid, user.twilio_auth_token) call = client.calls(call_sid).fetch() print("DURATION >>> ") print(call.duration) participant.duration = call.duration db.session.add(participant) db.session.commit() current_data = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .fetch() new_data = current_data.data new_data["speaking"] = False new_data["muted"] = False new_data["dropped"] = True data = json.dumps(new_data) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .update(data=str(data)) return "OK", 200 elif event == 'conference-end': print("conference-end!") conference_data = UserConference.query.filter_by( call_sid=conference_sid).first() user = User.query.filter_by(twilio_account_sid=account_sid).first() client = Client(user.twilio_account_sid, user.twilio_auth_token) twilio_conference = client.conferences(conference_sid).fetch() conference_data.region = twilio_conference.region start_time = datetime.strptime(conference_data.date_created, '%Y-%m-%d %H:%M:%S.%f') conference_data.duration = round( (datetime.utcnow() - start_time).total_seconds()) db.session.add(conference_data) db.session.commit() print(twilio_conference.region) delete_map_items() return "ITEMS DELETED", 200 elif event == 'participant-mute': print("{} >>> MUTED!".format(call_sid)) current_data = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .fetch() new_data = current_data.data new_data["muted"] = True data = json.dumps(new_data) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .update(data=str(data)) return "OK", 200 elif event == 'participant-unmute': print("{} >>> UNMUTED!".format(call_sid)) current_data = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .fetch() new_data = current_data.data new_data["muted"] = False data = json.dumps(new_data) map_item = client.sync.services(TWILIO_SYNC_SERVICE_SID) \ .sync_maps(TWILIO_SYNC_MAP_SID) \ .sync_map_items(call_sid) \ .update(data=str(data)) return "OK", 200 else: print("EVENT >>> {}".format(event)) return "OK", 200
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('AgentConf12') \ .participants \ .create(from_='+18180021216', to='+15624421212') print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences("CFbbe4632a3c49700934481addd5ce1659") \ .participants("CA386025c9bf5d6052a1d1ea42b4d16662") \ .update(hold=False, hold_url="http://www.myapp.com/hold") print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) conference = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch() print(conference.friendly_name)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants('CA386025c9bf5d6052a1d1ea42b4d16662') \ .fetch() print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \ .participants("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \ .fetch() print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participants = client.conferences("CFbbe4632a3c49700934481addd5ce1659") \ .participants \ .list() for record in participants: print(record.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences("AgentConf12").participants \ .create( from_="+18180021216", to="+15624421212" ) print(participant.call_sid)
import logging #write requests & responses from Twilio to log file, useful for debugging: logging.basicConfig( level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename= '/usr/local/twilio/python3/sdkv6x/conferences/logs/twilio_conferences.log', filemode='a') # Your Account Sid and Auth Token from twilio.com/console & stored in Mac OS ~/.bash_profile in this example account_sid = os.environ.get('$TWILIO_ACCOUNT_SID') auth_token = os.environ.get('$TWILIO_AUTH_TOKEN') client = Client(account_sid, auth_token) # A list of conference parameters & their permissable values, comment out (#) those lines not required conference = client.conferences('CFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') \ .update(status='completed') #Optional, init, in-progress, or completed. completed will end the conference. #print list of all conference properties to console, useful for learning info available you can work with print(conference.account_sid) print(conference.date_created) print(conference.date_updated) print(conference.friendly_name) print(conference.region) print(conference.sid) print(conference.status) print(conference.uri) #create variable for this conference cdr = (conference.sid) #open *.log file with cdr var as filename... f = open(
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participants = client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants \ .list(limit=20) for record in participants: print(record.call_sid)
level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename= '/usr/local/twilio/python3/sdkv6x/conferences/logs/twilio_conferences.log', filemode='a') # Your Account Sid and Auth Token from twilio.com/console & stored in Mac OS ~/.bash_profile in this example account_sid = os.environ.get('$TWILIO_ACCOUNT_SID') auth_token = os.environ.get('$TWILIO_AUTH_TOKEN') client = Client(account_sid, auth_token) # A list of conference participant parameters & their permissable values, comment out (#) those lines not required participant = client.conferences('CFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') \ .participants('CAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') \ .update(announce_method='GET', # Optional, GET or POST (default) announce_url ='https://api.twilio.com/cowbell.mp3', # Optional, URL containing Play or Say MP3, WAV OR TwiMl hold='true', # Optional, or false hold_method='GET', # Optional, GET or POST (default) hold_url='https://api.twilio.com/cowbell.mp3', # Optional, URL containing Play, Redirect or Say MP3, WAV OR TwiMl muted='true') # Optional, or false #print list of all conference participant properties to console, useful for learning info available you can work with? print(participant.account_sid) print(participant.call_sid) print(participant.conference_sid) print(participant.date_created) print(participant.date_updated) print(participant.end_conference_on_exit) print(participant.from_) print(participant.hold) print(participant.muted) print(participant.start_conference_on_enter)
# Download the Python helper library from twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/user/account account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" auth_token = "your_auth_token" client = Client(account_sid, auth_token) conference = client.conferences("CFbbe46ff1274e283f7e3ac1df0072ab39") \ .fetch() print(conference.status)
# Download the Python helper library from twilio.com/docs/python/install import os from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/user/account # To set up environmental variables, see http://twil.io/secure account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] client = Client(account_sid, auth_token) conference = client.conferences("CFbbe46ff1274e283f7e3ac1df0072ab39") \ .fetch() print(conference.status)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) conference = client.conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").fetch() print(conference.friendly_name)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .participants('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .fetch() print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants('CA386025c9bf5d6052a1d1ea42b4d16662') \ .update(hold=True, hold_url='http://www.myapp.com/hold') print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participants = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .participants \ .list(limit=20) for record in participants: print(record.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences("CFbbe4632a3c49700934481addd5ce1659") \ .participants("CA386025c9bf5d6052a1d1ea42b4d16662") \ .update(muted=False) print(participant.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .participants('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .delete()
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = '"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participants = client.conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \ .participants \ .list() for record in participants: print(record.call_sid)
# Download the Python helper library from twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/user/account account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" auth_token = "your_auth_token" client = Client(account_sid, auth_token) client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants("CA386025c9bf5d6052a1d1ea42b4d16662") \ .delete()
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) recording = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .recordings('REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .update(status='in-progress') print(recording.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) participant = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .participants \ .create(from_='+15017122661', to='+15558675310') print(participant.call_sid)
# Download the Python helper library from twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/user/account account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" auth_token = "your_auth_token" client = Client(account_sid, auth_token) # A list of participant objects with the properties described above participants = client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants \ .list() for participant in participants: print(participant.muted)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) conference = client.conferences('CFbbe46ff1274e283f7e3ac1df0072ab39').fetch() print(conference.friendly_name)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) recording = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .recordings('REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .update(status='stopped') print(recording.call_sid)
# Download the helper library from https://www.twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' client = Client(account_sid, auth_token) recording = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \ .recordings('Twilio.CURRENT') \ .update(status='paused') print(recording.call_sid)
# Download the Python helper library from twilio.com/docs/python/install from twilio.rest import Client # Your Account Sid and Auth Token from twilio.com/user/account account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" auth_token = "your_auth_token" client = Client(account_sid, auth_token) participant = client.conferences('CFbbe4632a3c49700934481addd5ce1659') \ .participants("CA386025c9bf5d6052a1d1ea42b4d16662") \ .update(muted="True") print(participant.muted)