Numbersインサイト・アドバンストWebhook
2027年2月4日をもって、VonageはVonage Number Insightsを終了いたします。継続的なサポートを確保し、よりスケーラブルで将来性のあるソリューションを提供するため、当社の強化されたソリューションへの移行をお勧めします: Vonage Identity Insights API.Vonage Identity Insight APIは、複数の電話番号関連データセットを1つの柔軟なAPIに統合し、電話番号に関するリアルタイムの情報を要求したり、番号のフォーマット、キャリアの詳細、SIMスワップ、加入者照合などのインサイトを1回の呼び出しで自由に組み合わせて取得できるようにします。
をご確認ください。 Numbersインサイト移行ガイドAPIの相違点、必要な変更点、スムーズな移行のためのベストプラクティスに関する詳細なガイダンスを提供しています。
このコードスニペットでは、Number Insight Advanced APIへの非同期呼び出しによって返されるデータを受信するWebhookハンドラのコードを示します。詳細は Numbersインサイトアドバンス コードスニペットで、インサイトデータの最初のリクエストのコードを学びます。
コード例を実行する前に、変数のプレースホルダーを置き換えてください:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on |
VONAGE_API_SECRET | Your Vonage API secret (also available on |
INSIGHT_NUMBER | The number you want to retrieve insight information for. |
前提条件
npm install @vonage/server-sdkni-advanced-async.js という名前のファイルを作成し、以下のコードを追加する:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});コードを書く
ni-advanced-async.js に以下を追加する:
vonage.numberInsight.asyncAdvancedLookup(
INSIGHT_NUMBER,
INSIGHT_CALLBACK_URL,
)
.then((result) => console.log(result))
.catch((error) => console.error(error));コードを実行する
このファイルをあなたのマシンに保存し、実行する:
前提条件
build.gradle に以下を追加する:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'
implementation 'io.ktor:ktor-server-netty'
implementation 'io.ktor:ktor-serialization-jackson'コードを書く
AdvancedInsightWebhook ファイルのmain メソッドに以下を追加する:
embeddedServer(Netty, port = 8000) {
routing {
post ("/webhooks/insight") {
val insightDetails = Jsonable.fromJson(call.receive(), AdvancedInsightResponse::class.java)
println(insightDetails)
call.respond(204)
}
}
}.start(wait = true)コードを実行する
Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''以下のgradle コマンドを実行し、com.vonage.quickstart.kt.numberinsight をAdvancedInsightWebhook を含むパッケージに置き換えてアプリケーションを実行する:
前提条件
build.gradle に以下を追加する:
implementation 'com.vonage:server-sdk:9.3.1'
implementation 'com.sparkjava:spark-core:2.9.4'コードを書く
AsyncInsightTrigger ファイルのmain メソッドに以下を追加する:
port(3000);
Spark.post("/webhooks/insight", (req, res) -> {
AdvancedInsightResponse response = Jsonable.fromJson(req.body());
System.out.println("Country: " + response.getCountryName());
res.status(204);
return "";
});コードを実行する
Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''以下のgradle コマンドを実行し、com.vonage.quickstart.insight をAsyncInsightTrigger を含むパッケージに置き換えてアプリケーションを実行する:
前提条件
Install-Package VonageNumberInsightsController.cs という名前のファイルを作成し、以下のコードを追加する:
using Vonage.Utility;
using System;コードを書く
NumberInsightsController.cs に以下を追加する:
var insights = await WebhookParser.ParseWebhookAsync<AdvancedInsightsResponse>
(Request.Body, Request.ContentType);
Console.WriteLine($"Advanced insights received: {insights.RequestId} " +
$"that number's carrier is {insights.CurrentCarrier.Name} " +
$"and it's ported status is: {insights.Ported}");
return NoContent();
}
}
}前提条件
composer require vonage/clientコードを書く
index.php に以下を追加する:
$handler = function (Request $request, Response $response) {
$params = $request->getParsedBody();
error_log($params['status_message']);
error_log($params['country_code']);
error_log($params['current_carrier']['name']);
return $response->withStatus(204);
};コードを実行する
このファイルをあなたのマシンに保存し、実行する:
前提条件
pip install fastapi[standard]コードを書く
main.py に以下を追加する:
from fastapi import FastAPI, Request
app = FastAPI()
@app.post('/webhooks/insight')
async def display_advanced_number_insight_info(request: Request):
data = await request.json()
print(data)コードを実行する
このファイルをあなたのマシンに保存し、実行する:
前提条件
gem install sinatra sinatra/multi-route jsonコードを書く
ni-advanced-async.rb に以下を追加する:
require 'sinatra'
require 'sinatra/multi_route'
require 'json'
helpers do
def parsed_body
json? ? JSON.parse(request.body.read) : {}
end
def json?
request.content_type == 'application/json'
end
end
route :post, '/webhooks/insight' do
puts params.merge(parsed_body)
status 200
end
set :port, 3000コードを実行する
このファイルをあなたのマシンに保存し、実行する:
APIからのレスポンスには以下のデータが含まれている:
{
"status": 0,
"status_message": "Success",
"lookup_outcome": 0,
"lookup_outcome_message": "Success",
"request_id": "75fa272e-4743-43f1-995e-a684901222d6",
"international_format_number": "447700900000",
"national_format_number": "07700 900000",
"country_code": "GB",
"country_code_iso3": "GBR",
"country_name": "United Kingdom",
"country_prefix": "44",
"request_price": "0.03000000",
"remaining_balance": "10.000000",
"current_carrier": {
"network_code": "23420",
"name": "Hutchison 3G Ltd",
"country": "GB",
"network_type": "mobile"
},
"original_carrier": {
"network_code": "23410",
"name": "Telefonica UK Limited",
"country": "GB",
"network_type": "mobile"
},
"valid_number": "valid",
"reachable": "reachable",
"ported": "ported",
"roaming": { "status": "not_roaming" }
}
返される各フィールドの説明と、可能なすべての値については Numbers Insight API ドキュメント