def monitor(): account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['AUTH_TOKEN'] sync_service_sid = os.environ['TWILIO_SYNC_SERVICE_SID'] client = Client(account_sid, auth_token) global manager_sid manager_sid = request.values.get('CallSid') print(manager_sid + ' is the manager_sid') new_data = {'manager_sid': manager_sid} document = client.sync \ .services(sync_service_sid) \ .documents("AgentData") \ .update(data=new_data) response = VoiceResponse() dial = Dial() dial.conference('AgentConference', muted=True, beep=False, status_callback="/statuscallback", status_callback_event="start end join leave mute hold") response.append(dial) return str(response)
def conference_call(request): response = VoiceResponse() room_name = request.POST['roomName'] dial = Dial() dial.conference(room_name) response.append(dial) return HttpResponse(response.to_xml(), content_type='text/xml')
def voice_four(request): """ Play voice 4 and do actions accordingly """ call_sid = None choice = None call_from = None if request.method == 'POST': call_sid = request.POST.get('CallSid', None) choice = request.POST.get('Digits', None) call_from = request.POST.get('From', None) if request.method == 'GET': call_sid = request.GET.get('CallSid', None) choice = request.GET.get('Digits', None) call_from = request.GET.get('From', None) twiml = VoiceResponse() if choice: call_detail = CallDetail.objects.get(call_sid=call_sid) call_detail.went_conference = True call_detail.save() if int(choice) == 1: client.calls.create(to=num_sendCallTo, from_=num_sendCallTo, url=BASE_URL + '/Conference/' + call_sid, status_callback=BASE_URL+'/ConferenceStatus/' + call_sid, status_callback_method='POST', status_callback_event=["completed", "no-answer", "busy", "failed"]) dial = Dial() dial.conference(call_sid, wait_url='http://roelofvandijk.com/mp33/IVR/CallingInformation.mp3', status_callback=BASE_URL+'/AddDrop?CallSid=' + call_sid + '&From='+call_from, status_callback_method='POST', status_callback_event=['start', 'join', 'end'], end_conference_on_exit=True, max_participants=2, start_conference_on_enter=True) twiml.append(dial) return HttpResponse(str(twiml)) twiml.hangup() return HttpResponse(str(twiml)) return HttpResponse(str(twiml))
def conference(request, name, muted=None, beep=None, start_conference_on_enter=None, end_conference_on_exit=None, wait_url=None, wait_method='POST', max_participants=None): """ See: http://www.twilio.com/docs/api/twiml/conference. Usage:: # urls.py urlpatterns = patterns('', # ... url(r'^conference/(?P<name>\w+)/$', 'django_twilio.views.conference', {'max_participants': 10}), # ... ) """ r = VoiceResponse() dial = Dial() dial.conference(name=name, muted=muted, beep=beep, startConferenceOnEnter=start_conference_on_enter, endConferenceOnExit=end_conference_on_exit, waitUrl=wait_url, waitMethod=wait_method, ) r.append(dial) return r
def conference(request, name, muted=None, beep=None, start_conference_on_enter=None, end_conference_on_exit=None, wait_url=None, wait_method='POST', max_participants=None): """ See: http://www.twilio.com/docs/api/twiml/conference. Usage:: # urls.py urlpatterns = patterns('', # ... url(r'^conference/(?P<name>\w+)/$', 'django_twilio.views.conference', {'max_participants': 10}), # ... ) """ r = VoiceResponse() dial = Dial() dial.conference( name=name, muted=muted, beep=beep, startConferenceOnEnter=start_conference_on_enter, endConferenceOnExit=end_conference_on_exit, waitUrl=wait_url, waitMethod=wait_method, ) r.append(dial) return r
def gatherDigits(To, digit): # If they pressed a correct option group = get_group_by_did(To) try: if group and digit in [1, 2, 3, 4]: mp3 = get_selected_language_mp3(group, digit) conference_name = get_conference_name(group, digit) # Build TWIML response = VoiceResponse() play = Play(mp3) response.append(play) dial = Dial() dial.conference(muted=True, beep=False, end_conference_on_exit=False, start_conference_on_enter=False, max_participants=250, trim="do-not-trim", wait_url="/conference/onHold", wait_method="GET", name=conference_name) response.append(dial) return str(response) except KeyError: pass response = VoiceResponse() response.say("That is not a valid option") # this should take you back to the first URL and function initialCall response.redirect("/conference/join", method="GET") return str(response)
def voice_reply(): response = VoiceResponse() dial = Dial() dial.conference('NYU') response.append(dial) return str(response)
def generate_connect_conference(call_sid, wait_url, start_on_enter, end_on_exit): twiml_response = VoiceResponse() dial = Dial() dial.conference(call_sid, start_conference_on_enter=start_on_enter, end_conference_on_exit=end_on_exit, wait_url=wait_url) return str(twiml_response.append(dial))
def transferToManager(): # create TwiML that dials manager to customer conference as a participant response = VoiceResponse() dial = Dial() dial.conference(request.values.get('conference')) response.append(dial) return Response(str(response), mimetype='text/xml')
def conf_handle(): resp = VoiceResponse() dial = Dial() dial.conference("TEST", wait_url="/call-agent", status="end", end_conference_on_exit=True, status_callback="/pop-first") resp.append(dial) return str(resp)
def handle_start_conference(from_phone, target_phone): print("Starting conference") response = VoiceResponse() call_into_conference(target_phone) dial = Dial() conference_name = "{0}-{1}".format(from_phone, target_phone) conferences_by_target["+" + target_phone] = conference_name dial.conference(conference_name, start_conference_on_enter=True, end_conference_on_exit=True) response.append(dial) return str(response)
def test_add_conference(self): """ add a conference to a dial """ d = Dial() d.conference('My Room') r = VoiceResponse() r.append(d) assert_equal( self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Conference>My Room</Conference></Dial></Response>' )
def whisper(): response = VoiceResponse() dial = Dial() dial.conference('AgentConference', beep=False, coach=agent_sid, status_callback="/statuscallback", status_callback_event="start end join leave mute hold") response.append(dial) return str(response)
def test_conference(self): d = Dial() d.conference('TestConferenceAttributes', beep=False, wait_url='', start_conference_on_enter=True, end_conference_on_exit=True) r = VoiceResponse() r.append(d) assert_equal( self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Conference beep="false" endConferenceOnExit="true" startConferenceOnEnter="true" waitUrl="">TestConferenceAttributes</Conference></Dial></Response>' )
def call(): """Returns TwiML for a moderated conference call""" # Start our TwiML response response = VoiceResponse() # Start with a <Dial> verb dial = Dial() # If the caller is our MODERATOR, then start the conference when they # join and end the conference when they leave if request.values.get('From') == MODERATOR: dial.conference('My conference', startConferenceOnEnter=True, endConferenceOnExit=True) else: # Otherwise have the caller join as a regular participant dial.conference('My conference', startConferenceOnEnter=False) return str(response.append(dial))
def join(): if os.environ.get('FLASK_ENV') != 'development': if not validate_request(): logging.info('Request failed validation') return abort(400) pin_entered = request.form.get('Digits') response = VoiceResponse() dial = Dial() if pin_entered == os.environ.get('PHONE_CONF_LEADER_PIN'): dial.conference(os.environ.get('PHONE_CONF_ROOM_NUMBER'), start_conference_on_enter=True) response.append(dial) elif pin_entered == os.environ.get('PHONE_CONF_PARTICIPANT_PIN'): dial.conference(os.environ.get('PHONE_CONF_ROOM_NUMBER'), start_conference_on_enter=False) response.append(dial) else: response.say('Invalid pin entered.') return str(response)
def bridge(): ptoken = request.args['ptoken'] pprint.pprint(request.form) answeredBy = request.args.get('AnsweredBy') or request.form.get( 'AnsweredBy') print(answeredBy) response = VoiceResponse() if answeredBy in ("human", "unknown"): response.play("%s/media/welcome_please_wait.mp3" % config.WEB_DOMAIN_PROD, action="/dialstatus") dial = Dial() dial.conference(ptoken, waitUrl="%s/media/ttv_hold_music.mp3" % config.WEB_DOMAIN_PROD, waitMethod="GET") response.append(dial) else: response.hangup() return Response(str(response), mimetype='text/xml')
def join_conference(): for key in request.form: pprint(key) account_sid = request.form['AccountSid'] user = User.query.filter_by(twilio_account_sid=account_sid).first() response = VoiceResponse() dial = Dial() if user: greeting = response.say( 'You are entering {}\'s Conference Room'.format(user.first_name)) dial.conference( 'The Marae', status_callback=url_for('main.parse_events', _external=True), status_callback_event='start end join leave mute hold speaker', record='record-from-start', recording_status_callback=url_for('main.recording_events', _external=True)) response.append(dial) pprint(str(response)) return str(response)
def initialCall(To, conference_name): if conference_name in LANGUAGE_LIST: if 'delay' in conference_name: group_status = conferenceStatus['delay'] else: group_status = conferenceStatus['live'] if group_status == 'off-air': return str(group_is_closed()) response = VoiceResponse() dial = Dial() dial.conference(muted=True, beep=False, end_conference_on_exit=False, start_conference_on_enter=False, max_participants=250, trim="do-not-trim", wait_url="/conference/onHold", wait_method="GET", name=conference_name) response.append(dial) return str(response) print('To: {}'.format(To)) group = get_group_by_did(To) # print(group) if group: print(get_conference_status_by_group(group)) if get_conference_status_by_group(group) == 'on-air': response = VoiceResponse() gather = Gather(action="/conference/gatherDigit", method="GET", num_digits=1, timeout=30) gather.play(group['ivr_audio']) response.append(gather) return str(response) return str(group_is_closed())
def codecConference(From): conference_name = match("sip:(.*)@.*", From).group(1) if 'delay' in conference_name: group_status = conferenceStatus['delay'] else: group_status = conferenceStatus['live'] if group_status == 'off-air': return str(group_is_closed()) response = VoiceResponse() dial = Dial() dial.conference(muted=False, beep=False, end_conference_on_exit=False, start_conference_on_enter=True, max_participants=250, trim="do-not-trim", name=conference_name) response.append(dial) return str(response)
def incoming(): """Handle incoming calls from any number, agent or otherwise.""" from_number = request.form["From"] call_sid = request.form["CallSid"] if from_number in AGENT_NUMBERS: return handle_agent(from_number, call_sid) response = VoiceResponse() dial = Dial() try: # If an agent is available immediately, connect the customer to them. available_agent = AGENT_QUEUE.popitem(last=False) dial.conference(available_agent[1]) except KeyError: # Otherwise, place them in a conference called `Waiting Room` with the # other customers currently on hold. CUSTOMER_QUEUE[from_number] = call_sid dial.conference('Waiting Room') response.append(dial) return Response(str(response), 200, mimetype="application/xml")
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial( record='record-from-ringing-dual', recording_status_callback='www.myexample.com' ) dial.conference('myteamroom') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('Customer Waiting Room', beep='false', end_conference_on_exit='true') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference( 'EventedConf', status_callback='https://myapp.com/events', status_callback_event='start end join leave mute hold' ) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('moderated-conference-room', start_conference_on_enter=False) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference( 'NoMusicNoBeepRoom', beep=False, wait_url='http://your-webhook-host.com', start_conference_on_enter=True, end_conference_on_exit=True ) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('Room 1234') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('SimpleRoom', muted='true') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference( 'Customer Waiting Room', beep=False, end_conference_on_exit=True ) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('SimpleRoom', muted=True) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial( action='handleLeaveConference.php', method='POST', hangup_on_star=True, time_limit=30 ) dial.conference('LoveTwilio') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference( 'moderated-conference-room', start_conference_on_enter=True, end_conference_on_exit=True ) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('Customer Waiting Room', beep=False, end_conference_on_exit=True) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial(record='record-from-ringing-dual', recording_status_callback='www.myexample.com') dial.conference('myteamroom') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial(action='handleLeaveConference.php', method='POST', hangup_on_star=True, time_limit=30) dial.conference('LoveTwilio') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('moderated-conference-room', start_conference_on_enter='false') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('EventedConf', status_callback='https://myapp.com/events', status_callback_event='start end join leave mute hold') response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference( 'moderated-conference-room', start_conference_on_enter=True, end_conference_on_exit=True) response.append(dial) print(response)
from twilio.twiml.voice_response import Conference, Dial, VoiceResponse response = VoiceResponse() dial = Dial() dial.conference('Customer Waiting Room', beep=False) response.append(dial) print(response)