Closed kitsuniru closed 2 months ago
Expectation: 1) "Halo!" arrives with a keyboard (+) 2) We press on "Send my number" (+) 3) Number sended and printed out in logs (-)
Hey, thanks for bringing this up. I'll investigate this quickly and get back to you as soon as I can. Thanks :)
Yep, I'm back :)
I just tried your code. Actually, there's a small mistake or I should say one line that you've missed.
For menus to work - I mean to make them interactive, you should attach the menu to your bot. Here's how to:
bot.attachMenu(menu);
So, in best practice your code should be something like:
import 'dart:io';
import 'package:televerse/televerse.dart';
void main(List<String> arguments) async {
final bot = Bot(
Platform.environment["BOT_TOKEN"]!,
loggerOptions: LoggerOptions(),
);
// Create the menu outside the 'start' handler
final menu = KeyboardMenu(
resizeKeyboard: true,
oneTimeKeyboard: true,
).requestContact("Send my number", (ctx) {
final phone = ctx.message?.contact?.phoneNumber;
print('Got number: $phone');
});
// ✨ Important: Attach the menu to the bot to make it interactive
bot.attachMenu(menu);
bot.command("start", (ctx) async {
// Use the Menu :)
await ctx.reply(
"Halo!",
replyMarkup: menu,
);
});
await bot.start();
}
Creating and attaching menu inside handlers can cause to memory leaks - as they would be created and redundantly attached every time the "start" handler is called.
Please let me know if this still not working.
Hope this helps :)
Btw, just bringing to your attention, please feel free to join our Telegram group if you're stuck at any point with your bot development - you're most likely to get your questions answered much quicker there. (Completely optional, but feel free to).
Happy Televersing! 🚀
Yeah, that works, thank you!
Hi!
requestContact
inKeyboardMenu
doesn't works, it just ignores handler callback and does literally nothing