最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - telegram bot on Liferay - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a bot in telegram based on a portlet. Liferay latest version.

public class TelegramBotPortlet extends MVCPortlet {
    
    @Override
    public void render(RenderRequest renderRequest, RenderResponse renderResponse)
            throws IOException, PortletException {
        //ApiContextInitializer.init();
        TelegramBotUtil telegramBotUtil = new TelegramBotUtil();
        //telegramBotUtil.
        super.render(renderRequest, renderResponse);
    }
    
    @Override
    protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
            throws IOException, PortletException {
        
        TelegramBotUtil telegramBotUtil = new TelegramBotUtil();
        
        super.doDispatch(renderRequest, renderResponse);
    }
    
    @ProcessAction(name = "sendMessage")
    public void sendMessage(ActionRequest actionRequest, ActionResponse actionResponse) {
        String message = ParamUtil.getString(actionRequest, "message");
        String chatId = "-100000000000000";
        
        TelegramBotUtil bot = new TelegramBotUtil();
        bot.sendMessageToChat(chatId, message);
    }
}

and

public class TelegramBotUtil extends TelegramLongPollingBot {

    private static final String BOT_TOKEN = "1111111:AAAAAAAAAAAAAAAAAAAAAAAAAA";
    private static final String BOT_USERNAME = "aaaa_bot";

    @Override
    public void onUpdateReceived(Update update) {
        System.out.println("!!!!!!!!!!!!!!!!!!!!");
        _log.info("!!!!!!!!!!");
    }

    @Override
    public String getBotUsername() {
        _log.info("getBotUsername");
        return BOT_USERNAME;
    }
    
    @Override
    public String getBotToken() {
        _log.info("getBotToken");
        return BOT_TOKEN;
    }

    public void sendMessageToChat(String chatId, String text) {
        SendMessage message = new SendMessage();
        message.setChatId(chatId);
        message.setText(text);
    
        try {
            execute(message);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
    
    
    private static final Log _log = LogFactoryUtil.getLog(TelegramBotUtil.class);
}

My onUpdateReceived method doesn't work here. It doesn't react to anything at all. What could be the reason?

Maybe the reason is "The constructor TelegramLongPollingBot() is deprecated"? It seems to require creating a constructor with two parameters.

发布评论

评论列表(0)

  1. 暂无评论