デバッグツール
Twilio offers several tools for investigating the interaction between Twilio and your application. If a message fails to go through, is delayed, or otherwise behaves unexpectedly, these tools should be your first stops for debugging.
Twilio Debuggerの使用方法
Found in your Twilio console, the Debugger contains a detailed log of activity within your application. This log can help you dive deeper and understand which Twilio resources were impacted (and by whom).
Debuggerにアクセスするには、Consoleナビゲーションを開いて、「Runtime」を探しクリックします。
続いて、Debuggerに移動します:
Debuggerにアクセスすると、詳細ログを閲覧できます。 「Product」列のアイコンで、どの製品がエラーまたは警告の影響を受けたか調べることができます。
Debuggerのイベントをクリックすると、タイムスタンプ、リソースのSID、Twilioによってスローされた警告またはエラー、そしてメッセージのリクエストとレスポンスの完全なコンテキストといったような、発生したエラーのメッセージのプロパティーを確認できます。
カスタムアラートを構成する
By default, Twilio will notify you via email of your 1st error on any given day. By setting your own alert triggers via the console, you can customize which error codes trigger alerts and how you receive those alerts:
メッセージログを調べる
メッセージが重複して配信されるといったような、メッセージの配信についての問題が発生したときは、メッセージログを確認することから始めるのが最良のデバッグ方法です。
Log into your Twilio account and navigate to the Programmable SMS dashboard.
そして、SMSログのリンクをクリックします:
SMSログのページにアクセスできたら、問題の発生したメッセージを探します。 日付のリンクをクリックし、このメッセージの詳細を表示させます。 200
以外のレスポンスが返されたメッセージは、黄色または赤色で表示されます。
As you can see above, each log line includes the number of message segments, the message status, TO
and FROM
numbers, as well as if any media was attached. To dig deeper into a log for a given message, click on the hyperlinked date. This will take you to the Message Details:
メッセージログの詳細ビューでは、メッセージSID(このメッセージに対するTwilioの一意な識別子)、またリソースの作成された時刻、TOおよびFROMの番号、配信ステップ、およびリクエスト調査が表示されています。
配信ステップ
The Delivery Steps section of this log will show you when the request was created, how long it was queued on Twilio's platform, and when it was sent out to our carrier partner for delivery. These factors can help you determine where an undelivered message failed, or investigate latency issues.
リクエストインスペクター
リクエスト調査では、メッセージが送受信される際に発行された全リクエストおよびレスポンスが表示されます。 リクエストの右側に色付けされたステータスで、簡単にリクエストのエラーを確認できます。
上記のレスポンスでは、メッセージに対して設定したWebhookにTwilioが接続できなかったために502
レスポンスを受信したことが確認できます。
API Explorerを使用したテスト
メッセージをデバッグする他の強力なツールは、TwilioのAPI Explorerです。 API Explorerを使用すると、Twilio Consoleから直接、極力シンプルな方法でSMSメッセージを送信することができます。 これによって、発生している問題があなたのコードに関連したものか、あるいはTwilio側で何か尋常ならざる事態が発生しているのかを切り分けるのに役立ちます。
API Explorerでメッセージを送信するには:
- API Explorerで、「メッセージを作成する」ページに移動します。
- Fill out, at the minimum, the
From
,To
andBody
fields in the form. You may include any other data that you're trying to send, such as a media URL or status callback. - 「リクエストを発行」ボタンをクリックしてページを開いたままにしておくと、レスポンスを調べることができます。
通話ログと利用状況を修正する
通話ログのConsole経由での取得時と、Usage(利用状況)APIを使用しての取得時とでは、その数量はおそらくすぐには一致しません。 ClientまたはProgrammable Voiceについては、通話ログと通話の使用状況の不一致を解消する方法の記事を用意しています。
エラーコード
All Twilio-generated error codes are documented here. Find your error code via your SMS logs and dig into causes and possible solutions.
サポートへのお問い合わせ
Twilioの送信する各メッセージはこれらのログのレコードに対応し、SMSでは「SM」、MMSでは「MM」ではじまる34文字の文字列によって識別されます。 これがメッセージSIDです。 メッセージの問題の原因を特定できない場合、 問題のメッセージのメッセージSIDを添えて、弊社の素晴らしきサポートチームにお問い合わせいただくことができます。
ヘルプが必要ですか?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.