Integrating with the Vonage Server SDKs
The Vonage Cloud Runtime SDK allows you to use the providers to listen for incoming calls, messages, and more. You can use the Vonage APIs to extend your application. For example, you can make outbound calls or send SMS messages. To do so, you can use the Vonage Server SDKs in your chosen programming language. The following credentials are available on your application's environment when you are debugging or deploying with Vonage Cloud Runtime:
- API Key (
VCR_API_ACCOUNT_ID) - API Secret (
VCR_API_ACCOUNT_SECRET) - Application ID (
VCR_API_APPLICATION_ID) - Application Private Key (
VCR_PRIVATE_KEY)
Using the above credentials and the Vonage Server SDKs you can create client objects which can make API calls to the Vonage APIs. For example using the Node Server SDK:
import { Vonage } from '@vonage/server-sdk';
const vonage = new Vonage(
{
apiKey: process.env.VCR_API_ACCOUNT_ID,
apiSecret: process.env.VCR_API_ACCOUNT_SECRET,
applicationId: process.env.VCR_API_APPLICATION_ID,
privateKey: process.env.VCR_PRIVATE_KEY
}
);
Now this vonage object can be used to make requests to the Vonage APIs.
Making a Phone Call
Here is an example using the Node Server SDK to make a call on Vonage Cloud Runtime:
import { Vonage } from '@vonage/server-sdk';
const vonage = new Vonage(
{
applicationId: process.env.VCR_API_APPLICATION_ID,
privateKey: process.env.VCR_PRIVATE_KEY
}
);
const call = await vonage.voice.createOutboundCall({
to: [toNumber],
from: vonageNumber,
ncco: [
{
action: 'talk',
text: 'Hello from Vonage Cloud Runtime!'
},
]
});
To learn more about using the Voice API, view the Voice API Documentation.
Send an SMS Message
Here is an example using the Node Server SDK to send an SMS on Vonage Cloud Runtime:
import { Vonage } from '@vonage/server-sdk';
const vonage = new Vonage(
{
applicationId: process.env.VCR_API_APPLICATION_ID,
privateKey: process.env.VCR_PRIVATE_KEY
}
);
await vonage.messages.send({
text: 'Hello from Vonage Cloud Runtime!',
messageType: 'text',
to: toNumber,
from: vonageNumber,
channel: 'sms'
});
To learn more about using the Messages API, view the Messages API Documentation.