Search code examples
jsonpostvoipvoicevonage

Nexmo Voice API - connect two users and play a different talk action to each user


I'm making an outbound call to a customer using POST https://api.nexmo.com/v1/calls/.

I pass in this NCCO which plays the talk Hello customer, please wait while we connect you to the customer and connects to a salesperson (SALESPERSON_PHONE_NUMBER).

What I want to do is play a different talk to the salesperson only when they answer, something like outbound call to customer for Example Company

[
    {
        "action": "talk",
        "text": "Hello customer, please wait while we connect you."
    },
    {
        "action": "connect",
        "timeout": 20,
        "from": "MY_NEXMO_PHONE_NUMBER",
        "endpoint": [
            {
                "type": "phone",
                "number": "SALESPERSON_PHONE_NUMBER"
            }
        ]
    }
]

How can I play a different talk message to the salesperson only? I could not see anything in the documentation.


Solution

  • The connect NCCO action has an onAnswer option. From the documentation:

    onAnswer - A JSON object containing a required url key. The URL serves an NCCO to execute in the number being connected to, before that call is joined to your existing conversation. Optionally, the ringbackTone key can be specified with a URL value that points to a ringbackTone to be played back on repeat to the caller, so they do not hear just silence. The ringbackTone will automatically stop playing when the call is fully connected. Example: {"url":"https://example.com/answer", "ringbackTone":"http://example.com/ringbackTone.wav" }. Please note, the key ringback is still supported.
    

    So if you change your NCCO to look something like this, the salesperson will hear the talk action in the second NCCO, while the caller hears music.

    [
        {
            "action": "talk",
            "text": "Hello customer, please wait while we connect you."
        },
        {
            "action": "connect",
            "timeout": 20,
            "from": "MY_NEXMO_PHONE_NUMBER",
            "endpoint": [
                {
                    "type": "phone",
                    "number": "SALESPERSON_PHONE_NUMBER",
                    "onAnswer": {
                       "url":"https://example.com/answer",
                       "ringbackTone":"http://example.com/ringbackTone.wav"
                    }
                }
            ]
        }
    ]
    
    

    https://example.com/answer should be

     [{
            "action": "talk",
            "text": "Hello salesperson, please wait while we connect you."
        }]