Set up Mediator Callbacks Using CarrierX Portal

Most of the events associated with your partner account and your rented phone numbers (DIDs) can send callbacks. You can specify URL addresses where you have some service installed which can process these callbacks.

The callbacks contain the detailed data about the event. The data depends on the event that triggers the callback.

You can set callback URLs for four main events:

In this quick start guide we will see how to set up the system behavior to send callbacks when the rented phone number associated with the Mediator endpoint sends or receives calls.

I. Navigate to Callbacks Tab

You can set the Mediator callbacks in the Callbacks tab of the Global Settings section of CarrierX portal.

To get there, log in to the portal. On the left-side menu, locate and click the Configure menu. Click Global Settings.

Select Global Settings

Then select the Callbacks tab.

Select Callbacks

Click Edit.

Click Edit

Click Add Callback.

Click Add Callback

Now you can select the event type that will trigger the callback and enter the URLs for your selected callbacks.

Add Callback

II. Create Callbacks for Mediator

In this section, we will set up a callback for the Mediator endpoint through the portal.

Select the app_mediator callback event type from the list.

Select Mediator

Then enter the URL to your web service that is going to process the callback, e.g., https://example.com/mediator-callback-url.

Enter URL

Click Update to save the results.

Click Update

The callback will be available in the list of the created callbacks.

View Callback

III. Receive and Parse App Mediator Object

As you know, you can use the Mediator endpoint as a binding or a dialout.

Now if you use the Mediator endpoint, your service located at the URL you entered will receive the callback like this:

{
    "attributes": {
        "hide_origination_did": "true"
    },
    "date_insert": "2021-11-01T08:57:01.222Z",
    "date_start": "2021-11-01T08:53:59.000Z",
    "date_stop": "2021-11-01T08:54:30.000Z",
    "date_talk": "2021-11-01T08:54:11.000Z",
    "direction": "outbound",
    "dr_sid": "c8b57f49-a4a6-471d-8d88-3e2d331a963f",
    "dtmf": null,
    "duration": 31,
    "endpoint_sid": "222ba470-c546-4e53-9059-75c5e9df671f",
    "endpoint_type": "mediator",
    "event_type": "dialout",
    "number_dst": "15186859809",
    "number_redirect": "12092551158",
    "number_src": "15187147330",
    "partner_sid": "cee93bf3-5746-43fe-a1a2-822c05fef687",
    "reference_sid": "de016d1f-9030-4108-a674-d5827949c0b4",
    "type": "mediator",
    "version": 2
}

You can now parse it and use for your own purposes.

App Mediator Object Fields

The object in the callback has the following fields.

Attribute Data Type Description
attributes object The additional call attributes specified when creating the binding or the dialout. Refer to the section below for more information about available attributes and their details.
date_insert string The date and time when the record about the call was inserted into the database.
date_start string The date and time when the call started.
date_stop string The date and time when the call ended.
date_talk string The date and time when the destination number answered the call.
direction string The direction of the call. This is normally set to inbound for the calls that use the Mediator endpoint as a binding to show that the rented DID receives the call from the source number and redirects it to the destination phone number. For the calls that use the Mediator endpoint as a dialout, this field is set to outbound to show that the rented DID sends voice calls to both the numbers before connecting them with each other.
dr_sid string The secure ID of the call detail record which the system uses to identify the record among other call detail records.
dtmf string The DTMF sequence that was sent to the called party. This field will only have some value if you use the Mediator endpoint as a binding and specify a DTMF sequence for it. With dialouts this field is always set to null.
duration integer The call duration. Normally, it is calculated as (date_stop) − (date_start) and measured in seconds.
endpoint_sid string The secure ID of the Mediator endpoint used for the call.
endpoint_type string The type of the endpoint that triggered the callback. Here, it is always equal to mediator.
event_type string The type of the Mediator endpoint used for the call. Is set to binding for the Mediator endpoint used to redirect the call from the source to the destination phone number, and to dialout for the Mediator endpoint used to call the two phone numbers one by one before connecting them with each other.
number_dst string The destination phone number (if the Mediator endpoint is used as a binding) or the second called number (if the Mediator endpoint is used as a dialout).
number_redirect string The rented DID which the system uses for the Mediator endpoint.
number_src string The source phone number (if the Mediator endpoint is used as a binding) or the first called number (if the Mediator endpoint is used as a dialout).
partner_sid string The secure ID of the partner with which the Mediator endpoint is associated.
reference_sid string The reference secure ID of the binding (binding_sid) or the dialout (dialout_sid) that was used to make the call.
type string The type of the endpoint used for the call. Here, it is always equal to mediator.
version integer The version of the API used to send the callback.

Additional Object Attributes

When you create a binding or a dialout, you can provide the following additional preset attributes for the Mediator endpoint:

{
    "attributes": {
        "announce": "https://example.com/url/to/audio-announce.mp3",
        "cnam": "John Smith",
        "fix_anonymous_cid": true,
        "hide_origination_did": true,
        "ringback": "moh",
        "sip_header_*": "X-Custom-Header",
        "use_call_confirmation": "https://example.com/url/to/call-confirmation"
    }
}

IV. Next Steps

You successfully created callbacks for Mediator endpoint events associated with your partner account.

Now you can try and use your Mediator endpoint, and your web services will receive the callbacks triggered by the endpoint events.