Closed marekhudyma closed 1 year ago
That is normal, you can't request the otp every time or you'll get rate limited on that number. Use registered() instead on unregistered() if you are sure that the number is registered already. I have changed the behaviour of unregistered to not ask an otp if you are registered on the main branch, but I haven't pushed out a release with this patch yet
1) in ideal word, the library should not throw an exception for it, but handle and inform me politly. That's why I created an issue.
2) What does it mean that my number is registered. I passed the code and I run it again with .registered()
, but I still have Exception in thread "main" java.lang.IllegalStateException: Expected session to be already registered
.
I use phone number that never got WhatsApp installed as an application. Is it the reason?
1) in ideal word, the library should not throw an exception for it, but handle and inform me politly. That's why I created an issue. 2) What does it mean that my number is registered. I passed the code and I run it again with
.registered()
, but I still haveException in thread "main" java.lang.IllegalStateException: Expected session to be already registered
. I use phone number that never got WhatsApp installed as an application. Is it the reason?
The problem is that you are using new connection() which will create a new session, that's why it's throwing an error. Use lastConnection() or knownConnection(UUID): a new connection will obviously be unregistered. Also the exception is thrown because the response is unexpected. Sure I could probably word the exception better, but it shouldn't be a log warning most definitely.
I used this code:
Whatsapp.mobileBuilder()
.lastConnection()
.registered()
.addLoggedInListener(() -> System.out.println("Connected"))
.addDisconnectedListener(reason -> System.out.printf("Disconnected: %s%n", reason))
.addListener(new Listener() {
@Override
public void onNewMessage(Whatsapp whatsapp, MessageInfo info) {
System.out.println("----");
if (info.message().content() instanceof TextMessage textMessage) {
System.out.println("xxx" + textMessage.text().toLowerCase());
whatsapp.sendMessage(info.chatJid(), "Hello ! ");
}
}
})
.connect()
.join();
And this is throwing: Exception in thread "main" java.lang.IllegalStateException: Expected session to be already registered
.
I do not understand, how the library should know about connection number/id? Does it save it somewhere?
PS. I send you an email some days ago with proposal to improve examples ;)
I used this code:
Whatsapp.mobileBuilder() .lastConnection() .registered() .addLoggedInListener(() -> System.out.println("Connected")) .addDisconnectedListener(reason -> System.out.printf("Disconnected: %s%n", reason)) .addListener(new Listener() { @Override public void onNewMessage(Whatsapp whatsapp, MessageInfo info) { System.out.println("----"); if (info.message().content() instanceof TextMessage textMessage) { System.out.println("xxx" + textMessage.text().toLowerCase()); whatsapp.sendMessage(info.chatJid(), "Hello ! "); } } }) .connect() .join();
And this is throwing:
Exception in thread "main" java.lang.IllegalStateException: Expected session to be already registered
. I do not understand, how the library should know about connection number/id? Does it save it somewhere?PS. I send you an email some days ago with proposal to improve examples ;)
Read the documentation about how serialization works. The reason why that's popping up is that it's using the last connection you created, so make sure that it's registered.
Also I can't find your email
I send an email to the one from your profile: al..@g...com
at 6th of April, subject "Project - WhatsApp4j".
Check your spam ;)
I use:
The code worked for me, but after third (or fourth) run of the code:
I got an exception: