Auties00 / Cobalt

Standalone unofficial fully-featured Whatsapp Web and Mobile API for Java and Kotlin
MIT License
625 stars 183 forks source link

Whatsapp number connection #352

Closed DanielSilvaol closed 1 year ago

DanielSilvaol commented 1 year ago

Every time I manage to connect correctly with the whatsapp qrcode, but when I try to reconnect to send a message or something, it doesn't return the object with ".registered()" it always ends up coming empty, here's the problem code, is there something wrong? In this case, it returns optionalWhatsapp as false

public Whatsapp executeOnReconnection(UUID id) {
        Optional<WebOptionsBuilder> webOptionsBuilder = Whatsapp.webBuilder().newOptionalConnection(id);
        log.info(String.format("webOptionsBuilder: %s", webOptionsBuilder.isPresent()));
        if (webOptionsBuilder.isPresent()) {
            Optional<Whatsapp> optionalWhatsapp = webOptionsBuilder.get().registered();
            log.info(String.format("optionalWhatsapp: %s", optionalWhatsapp.isPresent()));
            if (optionalWhatsapp.isPresent()) {
                Whatsapp whatsapp = optionalWhatsapp.get();
                whatsapp.addDisconnectedListener(onDisconnectedActions::onDisconnected);
                whatsapp.addNewMessageListener(newMessageActions::onNewMessage);
                whatsapp.reconnect().join();
                return whatsapp;
            }
        }
        throw new RuntimeException("Timeout");
    }