アカウントの設定
Webhookが使用するコールバックURLなど、アカウントの設定をプログラムで構成することができます。
例
この例では、Vonage番号がSMSを受信したときに呼び出されるURLを設定する方法を示します。
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
SMS_CALLBACK_URL | The publicly-accessible URL that Vonage should send information to when your Vonage number receives an SMS |
Write the code
Add the following to configure-account.sh:
curl -X POST "https://rest.nexmo.com/account/settings" -u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d "moCallBackUrl=$ACCOUNT_SMS_CALLBACK_URL"Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named configure-account.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to configure-account.js:
vonage.accounts.updateAccountCallbacks({
moCallBackUrl: SMS_CALLBACK_URL,
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named ConfigureAccount and add the following code to the main method:
val client = Vonage {
apiKey(VONAGE_API_KEY)
apiSecret(VONAGE_API_SECRET)
}Write the code
Add the following to the main method of the ConfigureAccount class:
val settings = client.account.updateSettings(incomingSmsUrl = ACCOUNT_SMS_CALLBACK_URL)
println("moCallBackUrl is now ${settings.incomingSmsUrl}")Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.account with the package containing ConfigureAccount:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named ConfigureAccount and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the ConfigureAccount class:
SettingsResponse response = client.getAccountClient().updateSmsIncomingUrl(ACCOUNT_SMS_CALLBACK_URL);
System.out.println("SMS Callback URL is now " + response.getIncomingSmsUrl());Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.account with the package containing ConfigureAccount:
Prerequisites
Install-Package VonageCreate a file named ChangeAccountSettings.cs and add the following code:
using Vonage;
using Vonage.Request;
using Vonage.Accounts;Add the following to ChangeAccountSettings.cs:
var client = new VonageClient(credentials);
Write the code
Add the following to ChangeAccountSettings.cs:
var response = await client.AccountClient.ChangeAccountSettingsAsync(request);
Prerequisites
composer require vonage/clientCreate a file named configure-account.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);Write the code
Add the following to configure-account.php:
$response = $client->account()->updateConfig([
"sms_callback_url" => SMS_CALLBACK_URL
]);
print_r($response->toArray());Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvWrite the code
Add the following to configure-account.py:
from vonage import Auth, Vonage
from vonage_account import SettingsResponse
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
settings: SettingsResponse = client.account.update_default_sms_webhook(
mo_callback_url=ACCOUNT_SMS_CALLBACK_URL
)
print(settings)Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named configure-account.rb and add the following code:
Run your code
Save this file to your machine and run it:
この例では、新しいURLに更新された後のアカウントの現在の設定を出力しています。