Module vonage.voice
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_vonage.voice_1.1.0.png)
ballerinax/vonage.voice Ballerina library
Overview
This is a generated connector for Vonage Voice API v1.3.6 OpenAPI specification. The Voice API lets you create outbound calls, control in-progress calls and get information about historical calls. More information about the Voice API can be found at https://developer.nexmo.com/voice/voice-api/overview.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
- Create Vonage account
- Obtain tokens
- Log into Vonage API Dashboard by visiting https://dashboard.nexmo.com/
- Go to https://dashboard.nexmo.com/getting-started/voice and follow the guidelines to create an application.
- Use the
Application ID
and thePrivate key
of the created application to generate aJWT token
. You can generate a JWT using the online tool. - Learn more about how Vonage APIs use JWTs.
Quickstart
To use the Vonage Voice connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
First, import the ballerinax/vonage.voice
module into the Ballerina project.
import ballerinax/vonage.voice as vv;
Step 2: Create a new connector instance
You can initialize the client as follows. You can now provide the JWT obtained above in the configuration.
Create a voice:ClientConfig
with the JWT token obtained, and initialize the connector with it.
vv:ClientConfig config = { auth: { token: "JWT" } } vv:Client baseClient = check new Client(config);
Step 3: Invoke connector operation
-
Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to create an outbound call using the connector. You can now make a call from your own machine. Vonage will call you and read out a text-to-speech message.
Create an outbound call
public function main() { vv:EndpointPhoneTo endpointPhoneTo = { 'type: "phone", number: "9477.....96" }; vv:EndpointPhoneFrom endpointPhoneFrom = { 'type: "phone", number: "9477.....96" }; vv:NCCO ncco = { action: "talk", text: "This is a text to speech call from Vonage" }; vv:CreateCallRequestNcco payload = { to: [endpointPhoneTo], 'from: endpointPhoneFrom, ncco: [ncco] }; vv:CreateCallResponse|error response = baseClient->createCall(payload); if (response is vv:CreateCallResponse) { log:printInfo(response.toString()); } else { log:printError(response.message()); } }
Following is an example on how to get details of your calls using the connector.
Get details of your calls
public function main() { vv:GetCallsResponse|error response = baseClient->getCalls(); if (response is vv:CreateCallResponse) { log:printInfo(response.toString()); } else { log:printError(response.message()); } }
-
Use
bal run
command to compile and run the Ballerina program.