Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA Telegram bots api获取更新时出错:冲突:被其他长轮询或webhook终止_Java_Telegram Bot_Telegram Webhook - Fatal编程技术网

JAVA Telegram bots api获取更新时出错:冲突:被其他长轮询或webhook终止

JAVA Telegram bots api获取更新时出错:冲突:被其他长轮询或webhook终止,java,telegram-bot,telegram-webhook,Java,Telegram Bot,Telegram Webhook,我在Spring框架中使用JAVA Telegram Bot API,我的HomeController中有一个方法,我有一个类处理来自用户的所有传入消息。我在spring日志中得到了这些错误,然后从telegram bot API得到了重复的响应。问题是什么 @PostConstruct public void initBots() { ApiContextInitializer.init(); TelegramBotsApi botsApi = ne

我在Spring框架中使用JAVA Telegram Bot API,我的HomeController中有一个方法,我有一个类处理来自用户的所有传入消息。我在spring日志中得到了这些错误,然后从telegram bot API得到了重复的响应。问题是什么

  @PostConstruct
    public void initBots() {
        ApiContextInitializer.init();
        TelegramBotsApi botsApi = new TelegramBotsApi();
        BotService botService = new BotService();
        try {
            botsApi.registerBot(botService);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
[abrsystem1_bot电报连接]org.Telegram.telegrambots.logging.BotLogger.severe 博茨瓦纳 org.telegram.telegrambots.exceptions.TelegramApiRequestException: 获取更新时出错:[409]冲突:已被其他长轮询终止 或webhook在 org.telegrame.telegrambots.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:119) 在 org.telegram.telegrambots.updatesReceiver.DefaultBotsSession$ReaderThread.getUpdatesFromServer(DefaultBotsSession.java:255) 在 org.telegrame.telegrambots.updatesReceiver.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:186)

@覆盖
收到更新资料时的公共作废(更新){
试一试{
if(update.hasMessage()&&update.getMessage().hasText()){
字符串message_text=update.getMessage().getText();
串井;
long chat_id=update.getMessage().getChatId();
if(message_text.equals(“/start”)){
试一试{
SendMessage=新建SendMessage()
.setChatId(聊天室id)
.setText(wellcome_text);
ReplyKeyboardMarkup keyboardMarkup=新建ReplyKeyboardMarkup();
列表键盘=新建ArrayList();
KeyboardRow=新的KeyboardRow();
添加((新键盘按钮().setText(“正确”);
键盘。添加(行);
键盘标记。设置键盘(键盘);
message.setReplyMarkup(键盘标记);
试一试{
执行(消息);
}捕获(e){
e、 printStackTrace();
}
}捕获(例外e){
e、 printStackTrace();
}
}else if(消息文本等于(“消息”){
SendMessage SendMessage=新建SendMessage();
sendMessage.setChatId(chat_id).setText(“chatط㶈㶈㶈㶈㶦㶦㶦㶦㶦㶦㶦㶦㶦”);
试一试{
执行(发送消息);
removeMarker(聊天室id);
showContactInfo(聊天室id,更新);
}捕获(例外情况除外){
例如printStackTrace();
}
}else if(消息文本等于(“文本”)){
}否则{
showUnknownCommand(聊天室id);
}
}else if(update.getMessage().getContact()!=null&&update.getMessage().getChat()!=null){
long chat_id=update.getMessage().getChatId();
showContactInfo(聊天室id,更新);
}
}捕获(例外e){
e、 printStackTrace();
}
}

一天后,我终于解决了我的问题!当我在我的计算机上用intellij idea调试我的项目时,我创建了许多调试实例,所以我从telegram机器人中的同一个聊天id得到了多个响应。太无聊了

@Override
public void onUpdateReceived(Update update) {
    try {

        if (update.hasMessage() && update.getMessage().hasText()) {

            String message_text = update.getMessage().getText();
            String wellcome_text = "برای ثبت نام در سایت  شماره تلفن همراه خود را به اشتراک بگذارید";

            long chat_id = update.getMessage().getChatId();
            if (message_text.equals("/start")) {

                try {
                    SendMessage message = new SendMessage()
                            .setChatId(chat_id)
                            .setText(wellcome_text);

                    ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
                    List<KeyboardRow> keyboard = new ArrayList<KeyboardRow>();
                    KeyboardRow row = new KeyboardRow();
                    row.add((new KeyboardButton().setText("اشتراک شماره موبایل").setRequestContact(true)));
                    keyboard.add(row);
                    keyboardMarkup.setKeyboard(keyboard);
                    message.setReplyMarkup(keyboardMarkup);

                    try {
                        execute(message);
                    } catch (TelegramApiException e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else if (message_text.equals("تایید مشخصات کاربری")) {
                SendMessage sendMessage = new SendMessage();
                sendMessage.setChatId(chat_id).setText("اطلاعات مورد تایید قرار گرفت");

                try {
                    execute(sendMessage);
                    removeMarker(chat_id);
                    showContactInfo(chat_id, update);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else if (message_text.equals("تغییر مشخصات")) {

            } else {
                showUnknownCommand(chat_id);
            }
        } else if (update.getMessage().getContact() != null && update.getMessage().getChat() != null) {

            long chat_id = update.getMessage().getChatId();
            showContactInfo(chat_id, update);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}