-
This is a dumb newbie question, however, I am at my wits end. public Ability saysHelloWorld() {
return Ability.builder()
.name("hello") // Name and command (/hello)
.info("Says hello world!") // Necessary if you want it to be reported via /commands
.privacy(PUBLIC) // Choose from Privacy Class (Public, Admin, Creator)
.locality(ALL) // Choose from Locality enum Class (User, Group, PUBLIC)
.input(0) // Arguments required for command (0 for ignore)
.action(ctx -> {
/*
ctx has the following main fields that you can utilize:
- ctx.update() -> the actual Telegram update from the basic API
- ctx.user() -> the user behind the update
- ctx.firstArg()/secondArg()/thirdArg() -> quick accessors for message arguments (if any)
- ctx.arguments() -> all arguments
- ctx.chatId() -> the chat where the update has emerged
NOTE that chat ID and user are fetched no matter what the update carries.
If the update does not have a message, but it has a callback query, the chatId and user will be fetched from that query.
*/
// Custom sender implementation
sender.send("Hello World!", ctx.chatId());
})
.build(); My issue is with So, the question is: how exactly do I send a message back to the user? Very basic info that I am SOMEHOW missing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey! Glad you're using the AbilityBot API. The ExampleBots repo is hella old and things have changed a bit here and there. The MessageSender is supposed to be a replica of the DefaultAbsMethod methods, so that's why the easy-access HOWEVER AbilityBot has a utility message sender called Here's how you can send a message inside the action lambda: MessageSender sender.execute(new SendMessage().setChatId(ctx.getChatId()).setText("Hello World!")); SilentSender silent.send("Hello World!", ctx.getChatId()); |
Beta Was this translation helpful? Give feedback.
Hey! Glad you're using the AbilityBot API. The ExampleBots repo is hella old and things have changed a bit here and there. The MessageSender is supposed to be a replica of the DefaultAbsMethod methods, so that's why the easy-access
send
method has been removed.HOWEVER
AbilityBot has a utility message sender called
SilentSender
. That class has asend
method that you can leverage. However, no errors will be thrown. If the method fails, it will return an empty optional.Here's how you can send a message inside the action lambda:
MessageSender
SilentSender