Register to receive incoming Call events

In this building block you will see how to register for incoming Call events.

Example

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Register to receive incoming call Events" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Install dependencies

npm install nexmo-stitch

Write the code

Add the following to RegisterToIncomingEvents.js:

Copy to Clipboard
application.on("member:call", (member, call) => {

View full source

Run your code

Save this file to your machine and run it:

Load in your browser

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Register to receive incoming call Events" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
val listener = NexmoIncomingCallListener<NexmoCall> {
    override fun onIncomingCall(call: NexmoCall) {
        TODO("Handle incoming call")
    }
}

NexmoClient.get().addIncomingCallListener(listener)

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Register to receive incoming call Events" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
NexmoIncomingCallListener listener = new NexmoIncomingCallListener() {

    @Override
    public void onIncomingCall(NexmoCall nexmoCall) {
        //Handle incoming call
    }
};

NexmoClient.get().addIncomingCallListener(listener);

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Register to receive incoming call Events" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
extension ViewController: NXMClientDelegate {
    
    // ...

    func incomingCall(_ call: NXMCall) {
        // handle an incoming call
        ...
    }

}

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Register to receive incoming call Events" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
@implementation ViewController
...

// implement NXMClientDelegate
// ...

- (void)incomingCall:(nonnull NXMCall *)call {
    // handle an incoming call
}

@end

View full source

Try it out

When you run the code you register to receive an incoming Call's Events.