Auties00 / Cobalt

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

Implement plain string in QrHandler #407

Closed BasselAshi closed 8 months ago

BasselAshi commented 8 months ago

Problem described in Issue 406. The solution is to make the consumer directly accept the QR plain string without converting it to an ASCII matrix.

Auties00 commented 8 months ago

Looks good, but fix the Java doc please. The parameter name doesn't match

BasselAshi commented 8 months ago

Done.

nexa-backend commented 8 months ago

can i use this on version 3.5.1 ?

BasselAshi commented 8 months ago

can i use this on version 3.5.1 ?

You can manually create a QR Code consumer that received the QR code as a string that looks something like this:

class QrCodeConsumer(private val continuation: CancellableContinuation<String>) : QrHandler {
    override fun accept(qr: String) {
        if (continuation.isActive) {
            continuation.resume(qr)
        } else {
            println("New QR generated: ${qr}")
        }
    }
}
nexa-backend commented 8 months ago

can i use this on version 3.5.1 ?

You can manually create a QR Code consumer that received the QR code as a string that looks something like this:

class QrCodeConsumer(private val continuation: CancellableContinuation<String>) : QrHandler {
    override fun accept(qr: String) {
        if (continuation.isActive) {
            continuation.resume(qr)
        } else {
            println("New QR generated: ${qr}")
        }
    }
}

Whatsapp.webBuilder() .serializer(new DefaultControllerSerializer(Path.of("/Users/edy-kris/Documents/project-java/serializer"))) .newConnection(phone) .name(name) .errorHandler(ErrorHandler.toTerminal()) .autodetectListeners(true) .checkPatchMacks(true) .unregistered(QrHandler.toString(qrCodeConsumer)) .addLoggedInListener(() -> System.out.println("connected"));

            i use the consumer like you said but it still return the qrCode matrix
BasselAshi commented 8 months ago

You shouldnt be using the QrHandler at all after extending it:

.unregistered(qrCodeConsumer)