'How to create custom Controller using Spring?

I want to make a telegram bot using Java and Spring. I need to create my own Controller, similar to RestController, which allows me to make my own Mapping (like GetMapping), only for the chat command, respectively. As an argument, I want to be able to receive a message from Update (which has already been parsed, removing the command, because it is already specified in the Mapping), userID, chatID, and so on. That is, I need some kind of middle layer that will convert Update to these arguments that I want. Does Spring allow you to do this? If not, is it possible to at least get Update as an argument?

I know there is a HandleInterceptor but it uses HttpRequest which is not exactly what I need.

Possible implementation of what I want is something like this:

@TelegramController
public class ListController {
    private final ListService listService;
    private final SendMessageService sendMessageService;

    public ListController(ListService listService, SendMessageService sendMessageService) {
        this.listService = listService;
        this.sendMessageService = sendMessageService;
    }

    @CommandMapping("/addlist")
    public TalkState addList(String message, User user) {
        listService.addList(message, user.getId());
        return TalkState.CONTINUE;
    }

    @CallbackQueryMapping
    public TalkState addList(@RequestParam("inline_message_id") String inlineMessageId, @RequestParam("data") String data) {
        listService.addList(message, userId);
        sendMessageService.send("Your data: " + data);
        return TalkState.STOP;
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source