wechaty/go-wechaty

[BUG] PuppetService unMarshal err: json: cannot unmarshal object into Go struct field BaseEventPayload.Data of type string

SolLupus opened this issue · 3 comments

docker-compose
services: wechaty_puppet_service: image: wechaty/wechaty:0.65 container_name: wechaty_puppet_service_token_gateway environment: - WECHATY_LOG=verbose - WECHATY_PUPPET=wechaty-puppet-wechat - WECHATY_PUPPET_SERVER_PORT=30001 - WECHATY_TOKEN=insecure_3d415ebb-7a6f-4cba-b602-1f4ae400f011 - WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=true - WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT=true ports: - "30001:30001" restart: always privileged: true tty: true

go-wechaty example-ding-dong-bot
`package main

import (
"fmt"
"log"
"net/url"
"os"
"time"

"github.com/mdp/qrterminal/v3"
"github.com/wechaty/go-wechaty/wechaty"
wp "github.com/wechaty/go-wechaty/wechaty-puppet"
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
"github.com/wechaty/go-wechaty/wechaty/user"

)

func main() {
var bot = wechaty.NewWechaty(wechaty.WithPuppetOption(wp.Option{
Endpoint: "127.0.0.1:30001",
Token: "insecure_3d415ebb-7a6f-4cba-b602-1f4ae400f011",
Timeout: time.Duration(2 * time.Minute),
}))

bot.OnScan(onScan).OnLogin(func(ctx *wechaty.Context, user *user.ContactSelf) {
	fmt.Printf("User %s logined\n", user.Name())
}).OnMessage(onMessage).OnLogout(func(ctx *wechaty.Context, user *user.ContactSelf, reason string) {
	fmt.Printf("User %s logouted: %s\n", user, reason)
})

bot.DaemonStart()

}

func onMessage(ctx *wechaty.Context, message *user.Message) {
log.Println(message)

if message.Self() {
	log.Println("Message discarded because its outgoing")
	return
}

if message.Age() > 2*60*time.Second {
	log.Println("Message discarded because its TOO OLD(than 2 minutes)")
	return
}

if message.Type() != schemas.MessageTypeText || message.Text() != "#ding" {
	log.Println("Message discarded because it does not match #ding")
	return
}

// 1. reply text 'dong'
_, err := message.Say("dong")
if err != nil {
	log.Println(err)
	return
}
log.Println("REPLY with text: dong")

// // 2. reply image(qrcode image)
// fileBox := filebox.FromUrl("https://wechaty.github.io/wechaty/images/bot-qr-code.png")
// _, err = message.Say(fileBox)
// if err != nil {
// 	log.Println(err)
// 	return
// }

// log.Printf("REPLY with image: %s\n", fileBox)

// 3. reply url link
// urlLink := user.NewUrlLink(&schemas.UrlLinkPayload{
// 	Description:  "Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go",
// 	ThumbnailUrl: "https://wechaty.js.org/img/icon.png",
// 	Title:        "wechaty/go-wechaty",
// 	Url:          "https://github.com/wechaty/go-wechaty",
// })
// _, err = message.Say(urlLink)
// if err != nil {
// 	log.Println(err)
// 	return
// }
// log.Printf("REPLY with urlLink: %s\n", urlLink)

}

func onScan(ctx *wechaty.Context, qrCode string, status schemas.ScanStatus, data string) {
if status == schemas.ScanStatusWaiting || status == schemas.ScanStatusTimeout {
qrterminal.GenerateHalfBlock(qrCode, qrterminal.L, os.Stdout)

	qrcodeImageUrl := fmt.Sprintf("https://wechaty.js.org/qrcode/%s", url.QueryEscape(qrCode))
	fmt.Printf("onScan: %s - %s\n", status, qrcodeImageUrl)
	return
}
fmt.Printf("onScan: %s\n", status)

}
`

When i scan the QR code, this error come out.

onScan: ScanStatusTimeout - https://wechaty.js.org/qrcode/https%3A%2F%2Flogin.weixin.qq.com%2Fl%2FYcb-89xQoA%3D%3D
onScan: ScanStatusScanned
time="2024-09-12 17:46:05.890" level=error msg="PuppetService unMarshal err: json: cannot unmarshal object into Go struct field BaseEventPayload.Data of type string\n" module=wechaty-puppet-service
onScan: ScanStatusConfirmed
time="2024-09-12 17:46:07.890" level=error msg="PuppetService unMarshal err: json: cannot unmarshal object into Go struct field BaseEventPayload.Data of type string\n" module=wechaty-puppet-service
time="2024-09-12 17:46:09.376" level=error msg="PuppetService unMarshal err: json: cannot unmarshal object into Go struct field BaseEventPayload.Data of type string\n" module=wechaty-puppet-service

有没有试试最新的 wechaty/wechaty docker 镜像

有,也会出现相同的错误 , 还是说 wechaty-puppet-wechat 已经不能绕过微信登陆了,因为我是用2017年注册以后的账号进行登录的

"json: cannot unmarshal" 不是根本原因,你可以看下 docker 容器的日志,应该是 wechaty-puppet-wechat 这个 puppet 不能用了,我看到很久没有更新了