Voximplant. Blog

Phone number connected to IVR

With VoxImplant you can buy a phone number and connect it to IVR built using VoxEngine scenario in minutes. There are 2 ways of buying a phone number – using VoxImplant Control Panel or using HTTP API. After logging into the Control Panel click on the Phone Numbers menu item, you can buy phone number(s) there. Now we can build our simple IVR scenario that will handle incoming calls to this phone number, say something to the caller and record his message.

Open Scenarios section of the Control Panel and click “Create scenario” button to start writing new scenario:

  1. VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
  2. e.call.answer(); // answer incoming call
  3. e.call.addEventListener(CallEvents.Connected, handleCallConnected);
  4. e.call.addEventListener(CallEvents.Disconnected, function(e) { VoxEngine.terminate(); });
  5. });
  6.  
  7. function handleCallConnected(e) {
  8. e.call.say("Hello, welcome to VoxImplant! Please leave your message.", Language.US_ENGLISH_FEMALE);
  9. e.call.addEventListener(CallEvents.PlaybackFinished, handleIntroPlayed);
  10. }
  11.  
  12. function handleIntroPlayed(e) {
  13. e.call.record();
  14. setTimeout(VoxEngine.terminate, 30000); // record voice message - 30 sec.
  15. }

Save your scenario, you can call it SimpleIVR, after that we should connect phone number to the scenario. To make it happen we need to create new VoxImplant application in the Applications section of the Control Panel, let’s call it ivr (full name will look like ivr.your_acc_name.voximplant.com , where your_acc_name – your VoxImplant account name). Next step is to connect Rule that will forward calls to the scenario: click edit app button, open Rules tab and click “Add rule” button. Let’s call it Incoming, put the phone number you’ve bought to the Pattern field and drag’n’drop our SimpleIVR scenario to the Assigned column. Save the rule and try to call your phone number. You should hear the prompt (“Hello, welcome to VoxImplant! Please leave your message.”) and then you can say something – it will be recorded. You can check call history and listen to the records in Calls section of the Control Panel.

Forwarding the call after IVR playback

Let’s assume you have a business with one manager answering all calls, but you want to look like a big company. We can modify our previous scenario a little to forward the call to the manager after IVR playback:

  1. VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
  2. e.call.answer(); // answer incoming call
  3. e.call.addEventListener(CallEvents.Connected, handleCallConnected);
  4. e.call.addEventListener(CallEvents.Disconnected, function(e) { VoxEngine.terminate(); });
  5. });
  6.  
  7. function handleCallConnected(e) {
  8. e.call.say("Hello, welcome to VoxImplant! Please wait for an operator.", Language.US_ENGLISH_FEMALE);
  9. e.call.addEventListener(CallEvents.PlaybackFinished, handleIntroPlayed);
  10. }
  11.  
  12. // Now we will call to operator and connect two calls
  13. function handleIntroPlayed(e) {
  14. var fwdCall = VoxEngine.callPSTN('manager's number');
  15. VoxEngine.easyProcess(e.call, fwdCall);
  16. }

easyProcess is a helper function that simplify the process for developers, if you want to learn more what’s hidden behind the helper check this link.

Tagged in , , , , ,

Comments