Command Resource
The Command resource enables you to exchange simple machine-to-machine messages with SMS-capable devices. For example, you could use a Command resource to instruct a device to take a sensor reading.
While SMS is used as the transport, the SIM does not require an addressable phone number to receive a Command. This is the major distinction from Twilio’s Messages resource, which can be used for conversational messaging.
Any SMS message sent from a SIM to a pre-determined phone number — see Receive a Command from a SIM — is interpreted as a Command and sent to the Command callback URL of the Sim resource.
Commands can be sent and received using the SMS text mode or binary (PDU) mode. Text-mode Commands have a maximum length of 160 single-byte characters. Binary-mode Commands have a maximum length of 140 bytes.
To receive and process a Command sent to your device, you will interface with the modem directly, probably using AT commands. You should consult with the module manufacturer's documentation for information about receiving SMS messages.
Asynchronous resources
The Command resource performs asynchronous operations. To receive an asynchronous notification when a Command resource has finished updating, provide a callback URL, and optionally a callback method, GET
or POST
, when you create the Command.
Retention period
Commands are retained for 30 days from the time they are created. Commands older than 30 days will no longer be readable from this resource.
Command properties
Resource Properties in REST API format | |
---|---|
sid
|
The unique string that we created to identify the Command resource. |
account_sid
|
The SID of the Account that created the Command resource. |
sim_sid
|
The SID of the Sim resource that the Command was sent to or from. |
command
|
メッセージがSIMに、またはSIMから送信されます。 テキストモードのメッセージでは、半角ASCII文字160字以内に収めることが必要です。 バイナリーモードのメッセージでは、base64を使用してエンコーディングされる、最大140バイトの一連のデータです。 |
command_mode
|
The mode used to send the SMS message. Can be: |
transport
|
The type of transport used. Can be: |
delivery_receipt_requested
|
Whether to request a delivery receipt. |
status
|
The status of the Command. Can be: |
direction
|
The direction of the Command. Can be |
date_created
|
The date and time in GMT when the resource was created specified in ISO 8601 format. |
date_updated
|
The date and time in GMT when the resource was last updated specified in ISO 8601 format. |
url
|
The absolute URL of the resource. |
Status values
Status | 概要 |
---|---|
queued |
The Command is queued in our network waiting to be sent to the SIM. |
sent |
コマンドがSIMに送信されました。 |
delivered |
The Command has been delivered to the SIM. For to_sim Commands only. |
received |
The Command has been received from the SIM. For from_sim Commands only. |
failed |
The Command has failed to be transmitted. |
Create a Command resource
https://wireless.twilio.com/v1/Commands
Creating a Command resource sends the command
to the SIM.
Callback values
Outgoing Command delivery is asynchronous, so we recommend that you pass a callback URL when you create the new Command.
When you providea callback URL, we call it when the attempt to send the Command completes.
We send these parameters to the callback URL:
パラメーター | 概要 |
---|---|
CommandSid |
このコールバックが参照しているコマンドです。 |
CommandStatus |
コマンドの現在のステータスです。 |
SimSid |
このコマンの送信先のSIMです。 |
SimUniqueName |
The receiving SIM’s UniqueName, if it has one. |
ErrorCode |
エラーの発生時、エラーコードが提供されます。 |
ErrorMessage |
エラーの発生時、エラーメッセージが提供されます。 |
ApiVersion |
最初のリクエストが発行されたAPIのバージョンです。 |
AccountSid |
The SID of the Account that this Command belongs to. |
CommandMode |
SMSの送信にどのモードが使用されたかを表す文字列です。 text あるいは binary のいずれかです。 |
If the CallbackMethod
parameter was set to POST,
or not provided, the callback parameters are delivered as HTML form parameters. If the CallbackMethod
parameter was set to GET
, the callback parameters are delivered as a query string.
パラメーター
Parameters in REST API format | |
---|---|
command
必須
|
The message body of the Command. Can be plain text in text mode or a Base64 encoded byte string in binary mode. |
sim
オプション
|
The |
callback_method
オプション
|
The HTTP method we use to call |
callback_url
オプション
|
The URL we call using the |
command_mode
オプション
|
The mode to use when sending the SMS message. Can be: |
include_sid
オプション
|
Whether to include the SID of the command in the message body. Can be: |
delivery_receipt_requested
オプション
|
Whether to request delivery receipt from the recipient. For Commands that request delivery receipt, the Command state transitions to 'delivered' once the server has received a delivery receipt from the device. The default value is |
例 1
例 2
Fetch a Command resource
https://wireless.twilio.com/v1/Commands/{Sid}
パラメーター
Parameters in REST API format | |
---|---|
sid
Path
|
The SID of the Command resource to fetch. |
例 1
Read multiple Command resources
https://wireless.twilio.com/v1/Commands
The maximum PageSize
you can request when reading Commands is 100.
パラメーター
Parameters in REST API format | |
---|---|
sim
オプション
|
The |
status
オプション
|
The status of the resources to read. Can be: |
direction
オプション
|
この方向のコマンドのみを返します。 |
transport
オプション
|
Only return Commands with this transport value. Can be: |
例 1
Delete a Command resource
https://wireless.twilio.com/v1/Commands/{Sid}
パラメーター
Parameters in REST API format | |
---|---|
sid
Path
|
The SID of the Command resource to delete. |
例 1
SIMからコマンドを受信する
To receive a Command from a SIM — called a “mobile-originated” Command — you should create or update an existing Sim instance and provide a CommandsCallbackUrl
property. Optionally, you may also include a CommandsCallbackMethod
property.
When a SIM sends an SMS message to the reserved phone number 2936
, a Command resource will be created, and your Commands Callback URL will be invoked. The callback request will include the following parameters.
パラメーター | 概要 |
---|---|
CommandSid |
The SID of this Command. |
SimSid |
The SIM this Command was sent by. |
SimUniqueName |
The sending SIM’s friendly name, if it has one. |
Command |
コマンドメッセージの本文です。 text モードでは、この値は160文字以内(日本語を含む場合70文字以内)のテキストです。 binary モードの場合、この値は最大サイズが140バイトの、Base64でエンコーディングされた文字列です。 |
Status |
Will always be the string received . |
ApiVersion |
最初のリクエストが発行されたAPIのバージョンです。 |
AccountSid |
The SID of the Account that this Command belongs to. |
CommandMode |
どのモードでSMSが受信されたかを表す文字列です。 text あるいは binary のいずれかです。 |
ヘルプが必要ですか?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.