Search code examples
apitestingtwiliobackendtwilio-studio

How to record a voicemail if a number is not picked up on Twilio Studio?


I am currently using Twilio Studio to build a customer service process that allows clients to make calls to a Twilio number, which redirects to representatives.

How can I allow clients to send a voice message (voicemail) if the call is not picked up or if the call is not within working hours. Thanks!


Solution

  • Twilio developer evangelist here.

    With the Connect Call To widget you can connect further widgets after either the call ending or the caller hanging up. In your case, you need to decide whether the call ended successfully or because the call wasn't picked up. You can do this by adding a Split Based On widget after the Connected Call Ended transition and testing on the DialCallStatus.

    DialCallStatus can be any of completed, answered, busy, no-answer, failed, or canceled. In your case you are looking for "no-answer". You can use the Split widget to direct the flow onto the Record Voicemail widget when that happens.

    As for calls not within working hours, that is a bit more complicated. To get the current time and compare to working hours will require you to run some code. You can do this with a Twilio Function, for example. There is an example application in the Twilio Code Exchange that implements this functionality but you would need to adjust it to use within your Studio Flow.