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)
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
docker-compose `services: wechaty_puppet_service: image: wechaty/wechaty:0.65 container_name: wechaty_puppet_service_token_gateway environment:
go-wechaty example-ding-dong-bot `package main
import ( "fmt" "log" "net/url" "os" "time"
)
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), }))
}
func onMessage(ctx wechaty.Context, message user.Message) { log.Println(message)
}
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)
} `
When i scan the QR code, this error come out.