Script widget | Get phone number


I would like to get the incoming phone number and use it in the same script widget.
I’m assuming this possible, and it is probably quite easy but I have not found any documentation for it.

What would be the process to gather that phone number?

Hi @mab
Try using a webhook and listen for “caller connected” event, it should give you the incoming phone number.

1 Like

In addition to the webhook option Harsh mentioned, if you do want to keep your code in the Flow using the Script widget, you can see an example on this support article.

1 Like

To capture the incoming phone number in a script widget, you would typically rely on the capabilities of the platform or service through which you’re receiving the phone call. The specifics can vary based on the telephony service or platform you’re using. Here are general steps you might consider:

  1. Telephony Provider Documentation:
  • Check the documentation of your telephony provider or platform. Providers like Twilio, Nexmo, or others may offer specific APIs or methods to retrieve the incoming phone number during a call.
  1. Use Event Listeners:
  • Many telephony APIs provide event listeners or webhooks that trigger when certain events occur during a call. Look for events related to incoming calls, and check if the phone number is included in the event payload.
  1. Scripting Language:
  • If you’re using a scripting language within the widget, you would typically write code to handle incoming events. This might involve parsing data from the telephony provider’s webhook or response.
  1. Test and Debug:
  • Set up a testing environment to simulate incoming calls and check how the telephony platform sends data related to the incoming phone number. This will help you understand the structure of the data you need to capture.

Here’s a general example using JavaScript (assuming your telephony provider exposes data in this way):

javascriptCopy code

// Example JavaScript code in your script widget
// This assumes your telephony provider sends data through an event object

// Event handler for incoming calls
function handleIncomingCall(event) {
    // Check if the event contains caller information
    if (event.callerNumber) {
        // Access the caller's phone number
        var incomingPhoneNumber = event.callerNumber;
        // Now you can use the incomingPhoneNumber in your script
        console.log("Incoming Phone Number: " + incomingPhoneNumber);