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電話番号概要ページ.
例
各コード・スニペットで使用されているすべての変数の説明を以下に示します:
| キー | 説明 |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_APPLICATION_PRIVATE_KEY_PATH | Private key path. |
VONAGE_PRIVATE_KEY_PATH | Private key path. |
FROM_NUMBER | The phone number you are sending the MMS from. (US Short Code, 10DLC number, or SMS Enabled Toll Free Number) |
VONAGE_NUMBER | Refer to |
VONAGE_FROM_NUMBER | Refer to |
TO_NUMBER | The number you are sending the to in E.164 format. For example |
IMAGE_URL | The URL of the media you want to send. Accepted file formats are |
注: 先頭の + または 00 電話番号を入力する場合は、14155550105のように国番号から入力してください。
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
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.
Create a file named send-mms.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const { Channels } = require('@vonage/messages');
/**
* It is best to send messages using JWT instead of basic auth. If you leave out
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens
*
* @link https://developer.vonage.com/en/messages/technical-details#authentication
*/
const vonage = new Vonage(
{
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
},
{
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
},
);Write the code
Add the following to send-mms.js:
vonage.messages.send({
messageType: 'image',
channel: Channels.MMS,
image: {
url: MESSAGES_IMAGE_URL,
},
to: MESSAGES_TO_NUMBER,
from: MMS_SENDER_ID,
})
.then(({ messageUUID }) => console.log(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:
Create a class named SendMmsImage and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.mms with the package containing SendMmsImage:
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:
Create a class named SendMmsImage and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the SendMmsImage class:
var response = client.getMessagesClient().sendMessage(
MmsImageRequest.builder()
.from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER)
.url(MESSAGES_IMAGE_URL)
.build()
);
System.out.println("Message sent successfully. ID: "+response.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:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.mms with the package containing SendMmsImage:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-mms.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);Write the code
Add the following to send-mms.php:
$image = new \Vonage\Messages\MessageObjects\ImageObject(
MESSAGES_IMAGE_URL,
'A MMS image message, with caption, sent using the Vonage Messages API'
);
$mms = new \Vonage\Messages\Channel\MMS\MMSImage(
TO_NUMBER,
FROM_NUMBER,
$image
);
$client->messages()->send($mms);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.
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.
Create a file named send-mms.rb and add the following code:
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、宛先番号にMMSメッセージが送信されます。