メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

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 change its APN.

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 Commands 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 GSM/LTE module manufacturer's documentation for information about receiving SMS messages.

非同期のリソース

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 parameter, when you create the Command.

Command properties

Names in REST API format
sid
sid<DC> Not PII

The unique string that we created to identify the Command resource.

account_sid
sid<AC> Not PII

The SID of the Account that created the Command resource.

sim_sid
sid<DE> Not PII

The SID of the Sim resource that the Command was sent to or from.

command
文字列 PII MTL: 30 DAYS

メッセージがSIMに、またはSIMから送信されます。 テキストモードのメッセージでは、半角ASCII文字160字以内に収めることが必要です。 バイナリーモードのメッセージでは、base64を使用してエンコーディングされる、最大140バイトの一連のデータです。

command_mode
enum:command_mode Not PII

The mode used to send the SMS message. Can be: text or binary. The default SMS mode is text.

transport
enum:transport Not PII

The type of transport used. Can be: sms or ip.

delivery_receipt_requested
boolean Not PII

Whether to request a delivery receipt.

status
enum:status Not PII

The status of the Command. Can be: queued, sent, delivered, received, or failed. See Status Values for a description of each state.

direction
enum:direction Not PII

The direction of the Command. Can be to_sim or from_sim. The value of to_sim is synonymous with the term mobile terminated, and from_sim is synonymous with the term mobile originated.

date_created
date_time<iso8601> Not PII

The date and time in GMT when the resource was created specified in ISO 8601 format.

date_updated
date_time<iso8601> Not PII

The date and time in GMT when the resource was last updated specified in ISO 8601 format.

url
url Not PII

The absolute URL of the resource.

ステータス値

Status 概要
queued The Command is queued in our network waiting to be sent to the SIM.
sent コマンドがSIMに送信されました。
delivered コマンドがSIMに配信されました。 (to_simコマンド向け)
received コマンドがSIMから受信されました。 (from_simコマンド向け)
failed コマンドに失敗しました。

Create a Command resource

post
https://wireless.twilio.com/v1/Commands

Creating a Command resource sends the command to the SIM.

コールバック値

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 存在する場合、受信側のSIMのUniqueName(一意な名前)です。
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 theCallbackMethod parameter was set to GET, the callback parameters are delivered as a query string.

パラメーター
Names in REST API format
command
必須
post 文字列 PII MTL: 30 DAYS

The message body of the Command. Can be plain text in text mode or a Base64 encoded byte string in binary mode.

sim
オプション
post 文字列 Not PII

The sid or unique_name of the SIM to send the Command to.

callback_method
オプション
post http_method Not PII

The HTTP method we use to call callback_url. Can be: POST or GET, and the default is POST.

callback_url
オプション
post url Not PII

The URL we call using the callback_url when the Command has finished sending, whether the command was delivered or it failed.

command_mode
オプション
post enum:command_mode Not PII

The mode to use when sending the SMS message. Can be: text or binary. The default SMS mode is text.

include_sid
オプション
post 文字列 Not PII

Whether to include the SID of the command in the message body. Can be: none, start, or end, and the default behavior is none. When sending a Command to a SIM in text mode, we can automatically include the SID of the Command in the message body, which could be used to ensure that the device does not process the same Command more than once. A value of start will prepend the message with the Command SID, and end will append it to the end, separating the Command SID from the message body with a space. The length of the Command SID is included in the 160 character limit so the SMS body must be 128 characters or less before the Command SID is included.

delivery_receipt_requested
オプション
post boolean Not PII

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 true.

例 1
        
        
        
        
        Send the 'wakeup' command to the 'AliceSmithSmartMeter' SIM

        Create a text Command resource

        Send the 'wakeup' command to the 'AliceSmithSmartMeter' SIM
        例 2
              
              
              
              
              Send a binary command to the 'AliceSmithSmartMeter' SIM

              Create a binary Command resource

              Send a binary command to the 'AliceSmithSmartMeter' SIM

              Fetch a Command resource

              GET
              https://wireless.twilio.com/v1/Commands/{Sid}
              パラメーター
              Names in REST API format
              sid
              Path
              GET sid<DC> Not PII

              The SID of the Command resource to fetch.

              例 1
                    
                    
                    
                    

                    Read multiple Command resources

                    GET
                    https://wireless.twilio.com/v1/Commands
                    パラメーター
                    Names in REST API format
                    sim
                    オプション
                    GET 文字列 Not PII

                    The sid or unique_name of the Sim resources to read.

                    status
                    オプション
                    GET enum:status Not PII

                    The status of the resources to read. Can be: queued, sent, delivered, received, or failed.

                    direction
                    オプション
                    GET enum:direction Not PII

                    この方向のコマンドのみを返します。

                    transport
                    オプション
                    GET ienum:transport Not PII

                    Only return Commands with this transport value. Can be: sms or ip.

                    例 1
                          
                          
                          
                          

                          Delete a Command resource

                          削除する
                          https://wireless.twilio.com/v1/Commands/{Sid}
                          パラメーター
                          Names in REST API format
                          sid
                          Path
                          削除する sid<DC> Not PII

                          The SID of the Command resource to delete.

                          例 1
                                
                                
                                
                                

                                SIMからコマンドを受信する

                                To receive a Command from a SIM, that is, a mobile-originated Command, you should create or update an existing SIM instance and provide a CommandsCallbackUrl property, and optionally 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 このコマンドの送信元のSIMです。
                                SimUniqueName 存在する場合、送信側のSIMのUniqueName(一意な名前)です。
                                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 のいずれかです。
                                Rate this page:

                                ヘルプが必要ですか?

                                誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。