tulir/whatsmeow

The verification code cannot appear.

Opened this issue · 5 comments

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.

`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 {}

}
`

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

我试过你的代码,看来你用的是这个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.

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)
} 
...

Considering closing this issue.