Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The verification code cannot appear. #678

Open
ghost opened this issue Oct 23, 2024 · 5 comments
Open

The verification code cannot appear. #678

ghost opened this issue Oct 23, 2024 · 5 comments

Comments

@ghost
Copy link

ghost commented Oct 23, 2024

Hi, hello, I'm encountering a bit of an issue while using Whatsmeow. I've followed the example code, and I'm seeing the log message "19:11:13.070 [Client/Socket DEBUG] Dialing wss://web.whatsapp.com/ws/chat", but there's been no further progress since then. No verification code has appeared. Have I made a mistake somewhere? I really need your assistance with this.

@ghost
Copy link
Author

ghost commented Oct 23, 2024

`package main

import (
"context"
"fmt"
_ "github.com/mattn/go-sqlite3"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log"
"os"
"os/signal"
"syscall"
)

func eventHandler(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
fmt.Println("Received a message!", v.Message.GetConversation())
}
}

func main() {
// |------------------------------------------------------------------------------------------------------|
// | NOTE: You must also import the appropriate DB connector, e.g. github.com/mattn/go-sqlite3 for SQLite |
// |------------------------------------------------------------------------------------------------------|

dbLog := waLog.Stdout("Database", "DEBUG", true)
container, err := sqlstore.New("sqlite3", "file:examplestore.db?_foreign_keys=on", dbLog)
if err != nil {
	println(err)
	//panic(err)
}
// If you want multiple sessions, remember their JIDs and use .GetDevice(jid) or .GetAllDevices() instead.
deviceStore, err := container.GetFirstDevice()
if err != nil {
	println(err)

	//panic(err)
}
clientLog := waLog.Stdout("Client", "DEBUG", true)
client := whatsmeow.NewClient(deviceStore, clientLog)
client.AddEventHandler(eventHandler)

if client.Store.ID == nil {
	// No ID stored, new login
	qrChan, _ := client.GetQRChannel(context.Background())

	err = client.Connect()

	if err != nil {
		//panic(err)
	}

	for evt := range qrChan {

		if evt.Event == "code" {
			// Render the QR code here
			// e.g. qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
			// or just manually `echo 2@... | qrencode -t ansiutf8` in a terminal
			fmt.Println("QR code:", evt.Code)
		} else {
			fmt.Println("Login event:", evt.Event)
		}
	}
} else {
	// Already logged in, just connect
	err = client.Connect()
	if err != nil {
		//panic(err)
	}
}

// Listen to Ctrl+C (you can also do something else that prevents the program from exiting)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c

client.Disconnect()

select {}

}
`

@SoursopID
Copy link

I tried your code, it seems you are using the qrcode method. But you didn't print it using qrterminal here.

@ghost
Copy link
Author

ghost commented Oct 24, 2024

我试过你的代码,看来你用的是这个qrcode方法。但是你没有用qrterminal这里打印它。

Thank you very much for your reply. I don't quite understand what you mean by "printing" in qrterminal. Could you please explain it to me? I copied the example code, and I'm very grateful for your help.

@SoursopID
Copy link

You need to generate evt.Code and print it on terminal

import(
    "github.com/mdp/qrterminal"
)

... 
if evt.Event == "code" {
    qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
} 
...

@SoursopID
Copy link

Considering closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant