Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sms can't get #64

Open
this-sunil opened this issue Dec 9, 2024 · 0 comments
Open

sms can't get #64

this-sunil opened this issue Dec 9, 2024 · 0 comments

Comments

@this-sunil
Copy link

this-sunil commented Dec 9, 2024

void sendSms() async {

  TwilioResponse twilioResponse = await twilioFlutter.sendSMS(

    toNumber: widget.phone,
    fromNumber: BaseApi.messageServiceId,
    // Ensure this is in E.164 format
    messageBody: "Don't Share OTP with Anyone",

  );

  print("Send OTP ${twilioResponse.responseCode} and Success => ${twilioResponse.responseState.name} \nError => ${twilioResponse.errorData}");

  if (twilioResponse.responseCode == 201) {

    //getSms();
    if (twilioResponse.metadata != null && twilioResponse.metadata!.isNotEmpty) {
      // Accessing the first item in the list
      var firstSms = twilioResponse.metadata!;
      print("First SMS SID: ${firstSms['sid']}");
     getSms();
    } else {
      print("No SMS data available.");
    }

    /*TwilioResponse response = await twilioFlutter.sendVerificationCode(verificationServiceId:BaseApi.accountSID,
        recipient: '${twilioResponse.metadata!["0"]["sid"]}',
        verificationChannel: VerificationChannel.SMS
    );*/

    CustomService.success(context, "SMS sent successfully");
  } else {
    CustomService.failure(context, "Failed to send SMS: ${twilioResponse.errorData}");
  }

} perfectly work but sms not getting void getSms() async {
try {
// Fetch the list of SMS messages
final twilioResponse = await twilioFlutter.getSmsList();

  // Check if the response contains messages
  if (twilioResponse.metadata != null && twilioResponse.metadata!.isNotEmpty) {
    // Get the first SMS message from the list
    final firstSms = twilioResponse.metadata!;

    // Get the SID of the first SMS
    String firstSmsSid = firstSms['sid'];

    print("First SMS SID: $firstSmsSid");

    // Fetch the details of the SMS using the SID
    final smsDetails = await twilioFlutter.getSMS(firstSmsSid);

    // Print the details of the SMS
    final keys = smsDetails.metadata!.map((key, value) => value);
    print("Keys: ${keys}");

  } else {
    print("No SMS messages found.");
  }
} catch (e) {
  print("Error fetching SMS details: $e");
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant