akshaydoshi2 / flutter_sim_data

MIT License
1 stars 3 forks source link

[Question] run action after sending sms #6

Open aeq-dev opened 3 days ago

aeq-dev commented 3 days ago

Hello, Thanks for this awesome package :) Please I'm facing an issue when I call an api after each sms sent (success or failed), the sms sent but the api point never called, Here my code :

 for (var sms in pendingSMS) {
        try {
          // Send SMS
          bool sent = await _sendSingleSMS(
            sms: sms,
            subscriptionId: defaultSim.subscriptionId,
          );

          // Update status based on send result
          if (sent) {
            await _apiService.updateSMSStatus(sms.id, 'sent');
          } else {
            await _apiService.updateSMSStatus(sms.id, 'failed');
          }
        } catch (e) {
          print('Failed to send SMS to ${sms.phone}: $e');
          // Ensure status update happens even if sending fails
          await _apiService.updateSMSStatus(sms.id, 'failed');
          // Don't rethrow here to allow processing of remaining SMS
        }
      }
    } catch (e) {
      print('Error in processing SMS: $e');
      rethrow;
    }

What I'm missing ? Thanks :)

akshaydoshi2 commented 3 days ago

Hey, Thank you for using the package! To better assist you, could you please provide a minimal reproducible example that I can run to investigate the issue? It’s a bit challenging to deduce the behavior from the code snippet shared, as the implementations are not included

aeq-dev commented 3 days ago

Hi ! Thanks for quick reply, Okey so for _sendSingleSMS : I'm using flutter_sim_data: ^1.0.5 and updateSMSStatus: it's my own server api point. So what I'm doing here : Get pending sms list from my api server Then send sms for each item using this package and finally update the sms status using api server

akshaydoshi2 commented 2 days ago

Hey, so since I don’t have the exact implementation of _sendSingleSMS, my guess is that the issue might be due to the sendSMS function. While it has a return type of Future<bool?>, it may not be returning the actual status of the sent SMS at the moment. This issue has already been addressed in an open PR #4 , but I haven’t had the chance to review and merge it yet. I’ll prioritize it and get it resolved as soon as possible.

aeq-dev commented 2 days ago

Here's it :

Future<bool> _sendSingleSMS({
    required SMS sms,
    required int subscriptionId,
  }) async {
    try {
      await _simDataPlugin.sendSMS(
        phoneNumber: sms.phone,
        message: sms.message,
        subId: subscriptionId,
      );
      return true;
    } catch (e) {
      print('SMS sending failed: $e');
      return false;
    }
  }
aeq-dev commented 2 days ago

I mean if we could have a callback after sending sms, something like this :

 await _simDataPlugin.sendSMS(
        phoneNumber: sms.phone,
        message: sms.message,
        subId: subscriptionId,
      )->then(
      // Do something
      );
aeq-dev commented 11 hours ago

Any chance to help me please ? :)