SMS の受信

SMS を受信する要件は以下のとおりです。

Prerequisites

Add the following to build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'
implementation 'io.ktor:ktor-server-netty'
implementation 'io.ktor:ktor-serialization-jackson'

Write the code

Add the following to the main method of the ReceiveMessage class:

View full source

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.sms with the package containing ReceiveMessage:

gradle run -Pmain=com.vonage.quickstart.kt.sms.ReceiveMessage

Nexmo Dashboard で Web フックエンドポイントを設定します

Nexmo が Web フックにアクセスできるようにするには、Nexmo アカウントでアクセス方法を設定する必要があります。

Web フックはコードスニペットの /webhooks/inbound-sms にあります。Ngrok を使用している場合、Nexmo Dashboard の API 設定ページで設定が必要な Web フックは「https://demo.ngrok.io/webhooks/inbound-sms」フォームを取ります。「demo」部分を Ngrok から提供されるサブドメインに置き換えて、 着信メッセージ用 Web フックの URL というラベルが付いたフィールドにエンドポイントを入力します。

試行手順

上記準備を完了して Nexmo の番号を SMS に送信すると、その番号はコンソールに記録されるようになります。メッセージオブジェクトには次のプロパティが含まれます。