Dart Requires Chilkat v11.0.0+
Dart
Check message delivery status with Twilio
See more Twilio Examples
Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.
Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Load an API key for the Twilio account from private application configuration.
final http = CkHttp();
http.requireSslCertVerify = true;
http.basicAuth = true;
http.login = 'YOUR_API_KEY_SID';
http.password = 'YOUR_API_KEY_SECRET';
final url = CkStringBuilder();
url.append('https://api.twilio.com/2010-04-01/Accounts/');
url.append('YOUR_ACCOUNT_SID');
url.append('/Messages');
url.append('/');
url.append('YOUR_MESSAGE_SID');
url.append('.json');
final resp = CkHttpResponse();
final reply = CkJsonObject();
success = true;
try {
http.httpNoBody('GET', url.getAsString(), resp);
} on ChilkatException {
success = false;
}
if (resp.statusCode == 0) {
print('No HTTP response from Twilio.');
return;
}
var parsed = true;
try {
reply.load(resp.bodyStr);
} on ChilkatException {
parsed = false;
}
if ((!success) || (resp.statusCode != 200)) {
print('Twilio returned HTTP ${resp.statusCode}');
if ((parsed) && (reply.jsonTypeOf('code') == 2)) {
print('Twilio error: ${reply.intOf('code')} ${reply.stringOf('message')}');
}
return;
}
if (!parsed) {
print('Expected a JSON response from Twilio.');
return;
}
if (reply.jsonTypeOf('status') != 1) {
print('Message status missing from response.');
return;
}
print('Delivery status: ${reply.stringOf('status')}');
if ((reply.stringOfEquals('status', 'failed', true)) || (reply.stringOfEquals('status', 'undelivered', true))) {
if (reply.jsonTypeOf('error_code') == 2) {
print('Delivery error code: ${reply.intOf('error_code')}');
}
if (reply.jsonTypeOf('error_message') == 1) {
print(reply.stringOf('error_message'));
}
}
}