Messages API サンドボックス
Messages API Sandboxは、Vonage Messages APIを使って特定のメッセージングチャンネルからのメッセージ送信を簡単にお試しいただけるサービスです。プロバイダーの外部アカウント(WhatsAppビジネスアカウント等)は必要ありません。つまり、Vonageアカウントを使ってメッセージAPIのこれらのチャンネルをすぐに試すことができます。
- バイバー
- フェイスブックメッセンジャー
- インスタグラム
注:インスタグラム・チャンネル自体は現在アーリーアクセス中であり、すべてのお客様が一般的に利用できるわけではありません。しかし、このチャンネルはサンドボックスを使用して誰でも試すことができます。
サンドボックスを使用して特定のチャンネルのメッセージ送信を試すには、まずそのチャンネルに関連するあなたの番号またはIDを、そのチャンネルで許可された番号/IDのリストに追加する必要があります。の指示に従ってサンドボックスにメッセージを送信する必要があります。 ダッシュボード あなたの番号またはIDが許可リストに載るように。
ご注意ください:
- 許可リストされた Numbers と ID は特定の Vonage API キーに関連付けられています。異なるVonage APIキーで同じ番号/IDを許可リストに追加した場合(例:別のVonage Dashboardアカウント経由)、その番号/IDは以前に追加されたAPIキーのSandbox許可リストから削除されます。
- サンドボックスは本番のMessages APIとは異なるAPIエンドポイントを使用します。サンドボックス経由でMessages APIを試す場合は、サンドボックスのエンドポイントを使用していることを確認してください。
- サンドボックス しさく たとえば、Messages APIを最初に使用する場合などです。本番稼働前に統合をテストするためのQA環境やステージング環境の一部として使用することは意図されていません。すでにMessages APIをアプリケーションに統合することを決定している場合は、特定のチャネルのダッシュボードの指示に従って、独自のアカウントを設定することをお勧めします。
注意: Sandboxを使用する場合、メッセージの送信には本番エンドポイント経由でメッセージを送信する場合と同じメッセージングワークフローの制約が適用されます。例えば、WhatsApp メッセージを送信する際には 24時間通信ウィンドウそのため、WhatsAppサンドボックスへの登録を許可する際、テンプレート以外のメッセージを送信する場合、WhatsAppサンドボックスの番号から許可リストに登録した番号へそのウィンドウ内でメッセージを送信する必要があります(現在、WhatsAppテンプレートはメッセージサンドボックスでは使用できません)。
Messages API サンドボックス価格
Messages API Sandboxは無料でご利用いただけます。毎月100メッセージ/月の公正使用制限が適用されます。これを超えた場合、メッセージリクエストは 429 HTTPエラー.
レートリミット
Messages API Sandboxには、1秒間に1メッセージというレート制限がある。
サンドボックスの設定
サンドボックスにチャンネルを設定するには、以下の手順に従ってください(各チャンネルを個別に設定する必要があることに注意してください)。
- に行く。 Messages API サンドボックス ダッシュボードの
- に複数のAPIキーがある場合は APIキー ドロップダウンリストで、設定するサンドボックスに関連付けるAPIキーを選択します。
- をクリックする。 サンドボックスに追加 リンクをクリックし、ダッシュボードの指示に従ってください。
ウェブフックの設定
インバウンドメッセージとメッセージステータスのWebhookは、アカウントレベルのWebhookやVonage ApplicationのWebhookとは別にSandbox用に設定する必要があります。
- アプリケーションを入力します。 インバウンド ウェブフックURL。受信Webhookは、受信メッセージが転送されるURLです。
- アプリケーションを入力します。 ステータス ウェブフックのURLです。ステータスウェブフックは、メッセージステータスの更新を受け取るURLです。
- をクリックする。 ウェブフックの保存 ボタンをクリックする。

ウェブフックの再試行
インバウンドとステータスのWebhookは、Messages APIサンドボックスで通知ごとに再試行されます。ウェブフックへの200以外のレスポンスは、5、10、20、40、80、160、320、640、そして24時間900秒ごとに、Vonageに定期的な再試行を促します。
Messages APIサンドボックス経由でテストメッセージを送信する。
電話番号または受信者IDが許可リストに登録されたら、Messages API Sandboxエンドポイントを使用してテストメッセージを送信する必要があります。その際 from リクエストの値は、特定のVonage Sandbox外部アカウントに関連するIDまたは番号でなければなりません。テスト目的のために from フィールドは、以下のコード・スニペットですでに入力されている。 ダッシュボード.の値を置き換える必要があることに注意してください。 to フィールドに、特定のVonage Sandbox外部アカウントで許可リストに登録されている番号または受信者IDを入力してください。
以下の例では Sandbox を使って WhatsApp テキストメッセージを送信していますが、他のチャンネルでも同じ一般的なアプローチが使えます。標準のメッセージエンドポイントではなく、サンドボックスエンドポイントを使用していることに注意してください(サーバーSDKを使用する場合、デフォルトエンドポイントをオーバーライドする必要があります)。
各コード・スニペットで使用されているすべての変数の説明を以下に示します:
| キー | 説明 |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_PRIVATE_KEY | Private key for the Vonage Application. |
MESSAGES_SANDBOX_URL | For sandbox testing the base URL is |
MESSAGES_SANDBOX_HOST | For sandbox testing the hostname is |
WHATSAPP_SENDER_ID | The WhatsApp number that has been allocated to you by Vonage. For sandbox use this is the number shown as the |
MESSAGES_TO_NUMBER | The number you are sending the to in E.164 format. For example |
注: 先頭の + または 00 電話番号を入力する場合は、447700900000のように国番号から入力してください。
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Write the code
Add the following to send-text.sh:
curl -X POST $MESSAGES_SANDBOX_URL \
-H "Authorization: Bearer "$JWT\
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{
"to": "'${MESSAGES_TO_NUMBER}'",
"from": "'${WHATSAPP_SENDER_ID}'",
"channel": "whatsapp",
"message_type": "text",
"text": "This is a WhatsApp text message sent using the Vonage Messages API."
}'Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
npm install @vonage/server-sdk @vonage/messagesCreate a file named send-text.js and add the following code:
const vonage = new Vonage(
{
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
},
{
apiHost: MESSAGES_SANDBOX_URL,
},
);Write the code
Add the following to send-text.js:
vonage.messages.send({
to: MESSAGES_TO_NUMBER,
from: WHATSAPP_SENDER_ID,
channel: Channels.WHATSAPP,
messageType: 'text',
text: 'This is a WhatsApp text message sent using the Vonage Messages API.',
})
.then((resp) => console.log(resp.messageUUID))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named SendWhatsappText and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the SendWhatsappText class:
println(client.messages.send(
whatsappText {
to(MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER)
from(MESSAGES_SANDBOX_WHATSAPP_NUMBER)
text("Hello from $WHATSAPP_SENDER_ID!")
},
sandbox = true
))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.messages.sandbox.whatsapp with the package containing SendWhatsappText:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Write the code
Add the following to the main method of the SendWhatsappText class:
System.out.println(VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build()
.getMessagesClient()
.useSandboxEndpoint()
.sendMessage(WhatsappTextRequest.builder()
.from(MESSAGES_SANDBOX_WHATSAPP_NUMBER)
.to(MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER)
.text("Hello from Vonage, "+System.getenv("NAME"))
.build()
).getMessageUuid()
);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.messages.sandbox.whatsapp with the package containing SendWhatsappText:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Install-Package VonageWrite the code
Add the following to SendWhatsAppText.cs:
// Set "Url.Api" to "https://messages-sandbox.nexmo.com" in appsettings.json
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var vonageClient = new VonageClient(credentials);
var request = new WhatsAppTextRequest
{
To = messagesSandboxAllowListedToNumber,
From = messagesSandboxWhatsAppNumber,
Text = "A WhatsApp text message sent using the Vonage Messages API via the Messages Sandbox"
};
var response = await vonageClient.MessagesClient.SendAsync(request);Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
composer require vonage/clientCreate a file named send-text.php and add the following code:
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client(
$keypair,
[
'base_api_url' => MESSAGES_SANDBOX_URL
]
);Write the code
Add the following to send-text.php:
$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppText(
MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER,
MESSAGES_SANDBOX_WHATSAPP_NUMBER,
'This is a WhatsApp text message sent using the Vonage PHP SDK via the Messages Sandbox via the Messages Sandbox'
);
$response = $client->messages()->send($message);Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
pip install vonage python-dotenvCreate a file named send-text.py and add the following code:
client = Vonage(
auth=Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
),
http_client_options=HttpClientOptions(api_host=MESSAGES_SANDBOX_HOST),
)Write the code
Add the following to send-text.py:
message = WhatsappText(
to=MESSAGES_TO_NUMBER,
from_=WHATSAPP_SENDER_ID,
text="This is a WhatsApp text message sent using the Vonage Messages API via the Messages Sandbox",
)
response = client.messages.send(message)Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
gem install vonageCreate a file named send-text.rb and add the following code:
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、WhatsAppメッセージが相手先の番号に送信されます。
次のステップ
Messages API Sandboxでこれらのチャンネルを試してみたところで、次はMessages APIそのものを使ってビルドするための手順を紹介しよう:
ソーシャル・チャンネルの設定
具体的な手順はチャンネルによって異なる。チャンネルは 外部アカウント のページを参照するか、または最初にチャネル固有の「Getting Started」ドキュメントを参照してください:
ソーシャル・チャンネルについて
各ソーシャルチャネルとその仕組みの詳細については、チャネル別のドキュメントをお読みください: