MCPcopy Create free account
hub / github.com/asternic/wuzapi / myEventHandler

Method myEventHandler

wmiau.go:696–1590  ·  view source on GitHub ↗
(rawEvt interface{})

Source from the content-addressed store, hash-verified

694 } else {
695 client.SetProxyAddress(parsed.String(), whatsmeow.SetProxyOptions{})
696 log.Info().Msg("HTTP/HTTPS proxy configured for WhatsApp connection")
697 }
698
699 if webhookUseProxy {
700 webhookClient.SetProxy(proxyURL)
701 log.Info().Msg("Proxy configured for webhook delivery client")
702 } else {
703 log.Info().Msg("Webhook delivery client bypassing proxy")
704 }
705 }
706 }
707 clientManager.SetHTTPClient(userID, webhookClient)
708
709 // Initialize S3 client if configured (needed when user reconnects after container restart - connectOnStartup only runs for connected=1)
710 GetS3Manager().EnsureClientFromDB(userID)
711
712 if client.Store.ID == nil {
713 // No ID stored, new login
714 qrChan, err := client.GetQRChannel(context.Background())
715 if err != nil {
716 // This error means that we're already logged in, so ignore it.
717 if !errors.Is(err, whatsmeow.ErrQRStoreContainsID) {
718 log.Error().Err(err).Msg("Failed to get QR channel")
719 return
720 }
721 } else {
722 err = client.Connect() // Must connect to generate QR code
723 if err != nil {
724 log.Error().Err(err).Msg("Failed to connect client")
725 return
726 }
727
728 myuserinfo, found := userinfocache.Get(token)
729
730 for evt := range qrChan {
731 if evt.Event == "code" {
732 // Display QR code in terminal (useful for testing/developing)
733 // Skip in stdio mode to avoid breaking JSON-RPC
734 if *logType != "json" && s.mode != Stdio {
735 qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
736 fmt.Println("QR code:\n", evt.Code)
737 }
738 // Store encoded/embeded base64 QR on database for retrieval with the /qr endpoint
739 image, _ := qrcode.Encode(evt.Code, qrcode.Medium, 256)
740 base64qrcode := "data:image/png;base64," + base64.StdEncoding.EncodeToString(image)
741 sqlStmt := `UPDATE users SET qrcode=$1 WHERE id=$2`
742 _, err := s.db.Exec(sqlStmt, base64qrcode, userID)
743 if err != nil {
744 log.Error().Err(err).Msg(sqlStmt)
745 } else {
746 if found {
747 v := updateUserInfo(myuserinfo, "Qrcode", base64qrcode)
748 userinfocache.Set(token, v, cache.NoExpiration)
749 log.Info().Str("qrcode", base64qrcode).Msg("update cache userinfo with qr code")
750 }
751 }
752
753 //send QR code with webhook

Callers

nothing calls this directly

Calls 12

processMediaMethod · 0.95
updateUserInfoFunction · 0.85
ensureS3ClientForUserFunction · 0.85
signalKillFunction · 0.85
sendEventWithWebHookFunction · 0.85
SendPresenceMethod · 0.80
StringMethod · 0.80
GetMethod · 0.80
syncHistoryForChatMethod · 0.80
GetPollOptionsMethod · 0.80
saveMessageToHistoryMethod · 0.80
trimMessageHistoryMethod · 0.80

Tested by

no test coverage detected