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

I'm having issue with teledart.onMessage(entityType: '*').listen((message) is not executing when running as Release and the app is in Background state for iOS #269

Open
sotheavuthnguon opened this issue Mar 19, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sotheavuthnguon
Copy link

Describe the bug

  • I enable the capabilities Background fetch and Background processing in Xcode:
Screenshot 2024-03-19 at 11 09 33 in the morning



  • Click on "Join Telegram" button to add the telegram bot to the telegram group and start listening to the onMessage method
ElevatedButton(
              onPressed: () async {
                const token = "BOT_TOKEN";
                final username = (await Telegram(token).getMe()).username!;
                final teledart = TeleDart(token, Event(username));
                teledart.start();
                teledartStartListening(teledart);
                String url =
                    "https://t.me/$username?startgroup=$username&admin=manage_chat,change_info,delete_messages,restrict_members,invite_users,pin_messages,manage_video_chats";
                await launchUrl(Uri.parse(url), mode: LaunchMode.platformDefault);
              },
              child: const Text("Join Telegram"),
            )


void teledartStartListening(TeleDart teledart) async {
  teledart.onMessage(entityType: '*').listen((message) async {
    debugPrint('Received message => ${message.text}');
    final textMessage = message.text;
    if (textMessage?.compareTo("111111") == 0) {
      teledart.stop();

      message.reply("Congratulations", parseMode: "HTML");
      // After verify OTP on telegram success we need to call to make update to back-end server.
    } else {
      if (textMessage == "" &&
          message.from != null &&
          message.from?.isBot == true &&
          (message.chat.type.toUpperCase() == "group".toUpperCase() ||
              message.chat.type.toUpperCase() == "supergroup".toUpperCase())) {
        message.reply("Hello", parseMode: "HTML");
      } else {
        message.reply("Hello", parseMode: "HTML");
      }
    }
  });
}

I cannot receive the messages when running as Release and the app is in Background state, but when running as Debug, I can receive the messages as normal.

Expected behavior

I would like the behavior that we can still receiving messages in Telegram when running as Release and the app is in Background state. Thanks.

@sotheavuthnguon sotheavuthnguon added the bug Something isn't working label Mar 19, 2024
@sotheavuthnguon sotheavuthnguon changed the title I'm having issue with teledart.onMessage(entityType: '*').listen((message) is not executing when running as Release and the app is in Background state I'm having issue with teledart.onMessage(entityType: '*').listen((message) is not executing when running as Release and the app is in Background state for iOS Mar 19, 2024
@DinoLeung
Copy link
Owner

Not a iOS expert here, would be good if someone can contribute to this issue.
My understanding is that the teledart stuff need to be run in the background thread, so the instance will not be destroy once the on pressed event is finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants