otpiq_flutter 0.0.1
otpiq_flutter: ^0.0.1 copied to clipboard
Unofficial Flutter SDK for OTPIQ SMS, WhatsApp, and Telegram messaging API.
example/main.dart
// ignore_for_file: avoid_print
import 'package:otpiq_flutter/otpiq_flutter.dart';
void main() async {
// Initialize the Otpiq SDK with your project API key
final otpiq = Otpiq(apiKey: 'your_api_key_here');
// Configure the global WhatsApp credentials once after initialization
otpiq.setWhatsAppConfig(
const OtpiqWhatsAppConfig(
whatsappAccountId: 'account_id',
whatsappPhoneId: 'phone_id',
),
);
try {
// 1. Get Project Info
print('Fetching project info...');
final projectInfo = await otpiq.getProjectInfo();
print('Project Name: ${projectInfo.projectName}');
print('Remaining Credit: ${projectInfo.credit} IQD');
print('JSON: $projectInfo\n');
// 2. Send an OTP Verification SMS
// Note: Since we set the WhatsApp config globally on otpiq, we don't
// need to pass it into each individual SmsVerificationRequest.
print('Sending verification SMS...');
final verificationRequest = SmsVerificationRequest(
phoneNumber: '964750123456',
verificationCode: '123456',
senderId: 'OTPIQ', // Optional custom sender ID
provider: OtpiqProvider.whatsappSms, // Optional fallback provider
);
final sendResponse = await otpiq.sendSms(verificationRequest);
print('SMS task created successfully!');
print('SMS ID: ${sendResponse.smsId}');
print('Cost: ${sendResponse.cost} IQD');
print('Remaining Credit: ${sendResponse.remainingCredit} IQD');
print('JSON: $sendResponse\n');
// 3. Track the SMS Delivery Status
print('Tracking SMS status...');
final trackResponse = await otpiq.trackSms(sendResponse.smsId);
print('Status: ${trackResponse.status}');
print('Is Final Status: ${trackResponse.isFinalStatus}');
print('Last Channel: ${trackResponse.lastChannel}');
print('Channel Flow: ${trackResponse.channelFlow}');
print('JSON: $trackResponse');
} on ApiException catch (e) {
print('API Error: ${e.message} (Status Code: ${e.statusCode})');
if (e.data != null) {
print('Error Data: ${e.data}');
}
} catch (e) {
print('Unexpected Error: $e');
}
}