小编Csa*_*hez的帖子

Telegram bot api 模拟用户交互

我正在使用 telegram bot api,我想在确定的时间内向用户发送消息,但机器人需要接收一条“消息”才能发送某些内容,我的问题是: 是否可以发送模拟用户交互的更新?

我的意思是这样的: 这里我创建更新来模拟用户交互(sendUpdate)是一个自定义方法,只是举例来说,这实际上不起作用

public void sendUpdate() {
    //sending the update to simulate user interaction
    Update upd = new Update();

    //method that telegram bot api uses to reply when you send a message to the bot
    onUpdateReceived(upd);
}

@Override
//Here I want to recipt my update to simulate the user interaction, and send a message witout user input
public void onUpdateReceived(Update update) {
    System.out.println(update);
    LOGGER.setLevel(Level.ALL);
    LOGGER.addHandler(new ConsoleHandler());

    LOGGER.info("2");
    if (update.hasMessage() && update.getMessage().hasText()) {
        // Set variables …
Run Code Online (Sandbox Code Playgroud)

telegram telegram-bot

5
推荐指数
1
解决办法
2156
查看次数

标签 统计

telegram ×1

telegram-bot ×1