0

I have an 'incoming call' web-hook for a contact centre application that I'm working on and it basically speaks a few words to the caller ("Welcome to x company etc..") and then adds them to a call queue.

I'm able to add further web-hooks for the 'action' and 'wait' events for the queue which let me check the progress of the call in the queue, however I'm struggling to find a way to handle calls that hang up before entering the queue. An example would be if someone hangs up while the system is speaking "Welcome to x company etc..".

I know that I could automatically add them to the queue and play the welcome message in the 'wait url' web-hook however this message would get repeated on a loop.

dmulter
  • 2,608
  • 3
  • 15
  • 24
andrewm
  • 2,552
  • 5
  • 33
  • 63

2 Answers2

2

Twilio developer evangelist here.

You can get webhooks for call statuses of incoming calls. You just need to add a URL to your phone number for "Call status changes".

You will then get a webhook when the call completes, allowing you to track its progress.

Alternatively, like you said you could play the message as part of the waitUrl when <Enqueue>ing the call. You wouldn't have to have it repeat though, you can actually return TwiML as the response to the waitUrl. That TwiML can include <Redirect> so you could read out the welcome message then redirect to a playlist of music that then loops, for example.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • That's perfect thanks, I somehow didn't spot that 'call status changes' input box, I'm going to have a play around with both options you've mentioned and see what works best – andrewm Nov 01 '17 at 08:28
0

A more simpler way from my side as coded here is to use a while loop and query twilio api for the call status from call sid

account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
auth_token  = os.environ.get('TWILIO__AUTH_TOKEN')
client = Client(account_sid, auth_token)


while True:
    r = client.calls(sid).fetch()
    c = to_dict(r)
    print(f'{datetime.now().strftime("%Y%m%d_%H%M%S")} from={c["from"]} to={c["to"]}  status={c["status"]}')
    #       ts  .                    .                .

    stop = c["status"] not in ['queued', 'ringing', 'in-progress']  # stop by :completed
    if stop: break

    time.sleep(3)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Nam G VU
  • 33,193
  • 69
  • 233
  • 372