News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
How to create forward call optionally based on incoming number?
Tags: rest api
Aug 16, 2019 at 8:30am   •   2 replies  •  0 likes
top notch

Hello,

Now i can get the incoming number using webhook, and I want to make optional forwarding call.

If the incoming number is 1111, then it will make forward call,

If the incoming number is 2222, then don't forward and disconnect.

It must be dynamic and programmatic.(Prefer to use Node.js).

So it means, specific people can contact me.

Please provide me any sample code or guide.

Thanks in advance.

2 Answers
answered on Aug 16, 2019 at 10:35pm  

Thank you so much!!!


 0
answered on Aug 16, 2019 at 10:17am  

You can use the Call Control API to forward a call to another number. Assumed that you got the incoming call event via webhook. Parse the notification payload to get the call information from the "activeCalls"
try the code below: (assumed that platform is the platform instance you get from the RingCentral JavaScript SDK)

for (var call of activeCalls){
  if (call.telephonyStatus == "Ringing" && call.direction == "Inbound"){
    console.log("CALLER ID: " + call.from)
    if (call.from == "1111"){
      forwardCall(call, "number to forward the call to")
    }else if (call.from == "2222"){
      disconnect(call)
    }
    break
  }
}

function forwardCall(call, toNumber){
  var endpoint = '/restapi/v1.0/account/accountId/telephony/sessions/'
  endpoint += call.telephonySessionId
  endpoint += '/parties/' + call.partyId + '/forward'
  platform.post(endpoint, {"phoneNumber":toNumber} )
    .then(function(resp){
      console.log(resp)
      var json = resp.json()
      console.log(JSON.stringify(json))
    })
    .catch(function(e){
      console.log(e)
    })
}

function rejectCall(call){
  var endpoint = '/restapi/v1.0/account/accountId/telephony/sessions/'
  endpoint += call.telephonySessionId
  endpoint += '/parties/' + call.partyId + '/reject'
  platform.post(endpoint)
    .then(function(resp){
      console.log(resp)
      var json = resp.json()
      console.log(JSON.stringify(json))
    })
    .catch(function(e){
      console.log(e)
    })
}

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us