Callback Configurations

    Plivo sends HTTP webhooks as callbacks during different states of a call and to many URLs, such as answer_url, fallback_url, hangup_url, action, and callback_url. To enable users to optimize for lower latency and build fault tolerance into webhook interactions, Plivo offers optional parameters that let developers configure timeouts (the timeframe Plivo has to wait to receive a response from your application server), retry policy, and edge region from which the webhook request is sent to the URL. Regions correspond to Plivo points of presence (PoP).

    Callback retry scenarios

    Having the ability to configure callback retries and timeouts improves reliability and event recovery by letting you:

    • Configure a custom timeout based on your use case.
    • Set higher timeouts during network problems on your application server.
    • Set shorter timeouts during an outage on your application server to ensure faster failover to your fallback URL.
    • Enable retries during client-side service interruptions and delays.

    Configuration mechanism

    To set callback configurations for any given URL (answer_url, fallback_url, , ring_url, etc.), you need to append configuration parameters to it in the form of URL extensions (or ”fragments”) as key-value pairs.

    • The first key-value pair should start with #
    • Key and value should be separated by =
    • Key-value pairs should be separated by &

    For example:

    https://example.com/answer_url?query=123#param1=2500&param2=5500
    
    Note: If you don’t append any parameters, the default values from the tables below will apply.

    Timeouts

    When Plivo sends an HTTP callback to your webhook URLs during events, you should capture the request (POST or GET based on the type you’ve defined for the URL) and respond with a 200 OK response. When you process the callback, you can store the data in your database.

    Plivo automatically retries webhooks for a certain timeframe if an HTTP 200 status code is not returned. The timeframe Plivo has to wait to receive a response from your application server is called a timeout. This table shows the allowed and default timeouts available for webhook URLs.

    ParameterNameDescriptionAllowed ValuesDefault
    ctConnection timeoutThe time in milliseconds (ms) for Plivo to wait while establishing a TCP connection100 – 100002000
    rtRead timeoutThe time in milliseconds for Plivo to wait:

    — to start receiving a response after sending the initial request

    — for delay between packets
    100 – 4000040000
    ttTotal timeoutUpper limit on total time allowed for all timeouts, including retries on a given URL (not including fallback URL)100 – 5500055000

    Examples

    1. https://example.com/answer_url?query=123#ct=2000
      Connection timeout of two seconds

    2. https://example.com/answer_url?query=123#ct=2000&rt=3000
      Connection timeout of two seconds and a read timeout of three seconds

    Retries

    Plivo lets you configure the number of retries it makes for different webhook URLs and the policy it should use depending on HTTP failure status codes.

    ParamNameDescriptionAllowed ValuesDefault
    rcRetry countNumber of retry attempts to be made to the same URL if the initial connection fails (not including to fallback URL)0 – 51
    rpRetry policyType of failure to retry on:

    4xx → only on 4xx responses

    5xx → only on 5xx responses

    ct → TCP/TLS connection failures within the connection timeout

    rt → no response received within the read timeout

    all → all the above
    Comma-separated list of values — for example, rp=ct,rtct,rt
    Note: If a partial response is received from your app server, Plivo will not make a retry attempt.

    Examples

    1. https://example.com/answer_url?query=123#rt=3000&rp=ct,rt
      Retry on both connect and read timeout, and reduce the read timeout to three seconds.

    2. https://example.com/answer_url?query=123#rc=3&ct=2000
      Retry on connection failure, but with a two-second connection timeout. If there is no connection in two seconds, retry three times, for a total of four attempts to connect.

    Edge Region

    An edge region is the geographical region from which Plivo initiates an HTTP webhook to the answer_url, fallback_url, hangup_url, action, or callback_url URLs. Plivo maintains edge clusters in six regions:

    • North California (United states)
    • North Virginia (United States)
    • Sydney (Australia)
    • Frankfurt (Germany)
    • Singapore
    • São Paulo (Brazil)

    To ensure minimum latency, Plivo automatically chooses the nearest region for all callbacks we initiate, but developers can configure the region for each URL using the er parameter:

    ParamNameDescriptionAllowed ValuesDefault
    erEdge RegionSpecifies the edge region where webhooks get initiated from. This parameter needs to be either a selection strategy or a specific region.
    Region Selection Strategies:
    nearest → selects the region geographically closest to the location of the URL.
    local → selects the same region as the media server where the call media is hosted.
    Specific region:
    n_california,n_virginia,sydney,frankfurt,singapore,sao_paulo
    • nearest
    • local
    • n_california
    • n_virginia
    • sydney
    • frankfurt
    • sao_paulo
    nearest

    Examples

    1. https://example.com/answer_url?query=123#er=n_california
      The HTTP webhook to this URL from Plivo will be initiated from Plivo’s North California edge region.

    2. https://example.com/answer_url?query=123#er=nearest
      The HTTP webhook to this URL from Plivo will be initiated from the Plivo’s edge region that is nearest to the location of the URL.

    Applicable URLs

    Callback retries apply to this list of URLs associated with Plivo’s Voice applications on the console, API requests, and XML elements:

    Voice applications on console

    • Primary Answer URL
    • Fallback Answer URL
    • Hangup URL

    API

    Make a call:

    • answer_url
    • ring_url
    • hangup_url
    • fallback_url
    • machine_detection_url

    Transfer a call:

    • aleg_url
    • bleg_url

    Record a call:

    • transcription_url
    • callback_url

    Record a conference:

    • transcription_url
    • callback_url

    XML

    Dial:

    • action
    • confirmSound
    • dialMusic
    • callbackUrl

    Conference:

    • action
    • callbackUrl
    • waitSound

    GetInput:

    • action
    • interimSpeechResultsCallback

    GetDigits:

    • action

    Record:

    • action
    • transcriptionUrl
    • callbackUrl

    Redirect

    Inapplicable URLs

    Callback retry parameters don’t apply to any of these audio URLs:

    API

    Play audio on a call
    Play audio to a conference member

    XML

    PreAnswer XML
    Play XML

    These URLs use our standard configuration values:

    • Connection timeout: 2 seconds
    • Read timeout: 120 seconds
    • Retry count: 1
    • Retry policy: all