MMSのグループメッセージを送信する

このコードスニペットでは、Messages API を使用して MMS グループメッセージを送信する方法をご紹介します。

重要: 現在、MMSの送信に対応しているのは、US Short Codes、10DLC番号、SMS Enabled Toll Free Numbersのみです。USショートコードの場合、MMSメッセージは米国内のAT&T、T-Mobile(旧Sprint)、Verizonネットワークに送信できます。 10DLC番号の設定について詳しくはこちら (注:このページはSMS APIを参照していますが、10 DLCガイドラインのセクションの内容はMessages APIにも適用されます)。

メッセージのスループット、配信可能性、SMSメッセージ量は、使用する番号の種類によって異なる場合があります。この点、およびMMS全般についての詳細は Vonage MMS概要ページその Vonage 10DLCの概要ページそして Vonage電話番号概要ページ.

各コード・スニペットで使用されているすべての変数の説明を以下に示します:

キー説明
MESSAGES_API_URL

There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was https://api.nexmo.com/v0.1/messages, the new one is https://api.nexmo.com/v1/messages. For sandbox testing the Messages API endpoint is https://messages-sandbox.nexmo.com/v0.1/messages or https://messages-sandbox.nexmo.com/v1/messages, depending on which version you have set in the sandbox dashboard.

MESSAGES_TO_NUMBER

The number you are sending the to in E.164 format. For example 447700900000.

MMS_SENDER_ID

The alphanumeric string that represents the name or number of the organization sending the message.

SECOND_MESSAGES_TO_NUMBER

The phone number of the second recipient.

注: 先頭の + または 00 電話番号を入力する場合は、14155550105のように国番号から入力してください。

前提条件

申込書をお持ちでない場合は、ひとつ作るウェブフックの設定 もご確認ください。

コードを書く

send-mms-group-message.sh に以下を追加する:

curl -X POST "${MESSAGES_API_URL}" \
  -H "Authorization: Bearer "$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "to": "'${MESSAGES_TO_NUMBER}'",
    "from": "'${MMS_SENDER_ID}'",
    "channel": "mms",
    "message_type": "text",
    "text": "This is an MMS group message sent via the Vonage Messages API.",
    "mms": {
      "participants": [
        '${SECOND_MESSAGES_TO_NUMBER}'
      ]
    }
  }'

curl -X POST "${MESSAGES_API_URL}" \
  -H "Authorization: Bearer "$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "to": "'${SECOND_MESSAGES_TO_NUMBER}'",
    "from": "'${MMS_SENDER_ID}'",
    "channel": "mms",
    "message_type": "text",
    "text": "This is an MMS group message sent via the Vonage Messages API.",
    "mms": {
      "participants": [
        '${MESSAGES_TO_NUMBER}'
      ]
    }
  }'

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

bash send-mms-group-message.sh

試してみる

このコードを実行すると、グループの参加者2人全員にMMSのグループメッセージが送信されます。