wechaty / go-wechaty

Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go
https://github.com/wechaty/go-wechaty-getting-started
Apache License 2.0
472 stars 89 forks source link

grpc链接超时问题 #164

Open Guwengo opened 2 months ago

Guwengo commented 2 months ago

docker我已经启动了使用puppet_padlocal也申请了token,也扫码正常了,部署再我的腾讯云服务器上,本地启动项目后提示grpc链接问题.超时! 我有个疑问环境变量我设置了token了,wechaty.NewWechaty()的时候他怎么知道我服务器地址,通过token去哪里查询码?谁知道大体原理和我说一下,捋一下思路.

下面是官网示例 使用puppet_padlocal链接云服务要单独设置什么吗?

package main

import (
    "fmt"
    "github.com/wechaty/go-wechaty/wechaty"
    "github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
    "github.com/wechaty/go-wechaty/wechaty/user"
)

func main() {
    wechaty.NewWechaty().
        OnScan(func(context *wechaty.Context, qrCode string, status schemas.ScanStatus, data string) {
            fmt.Printf("Scan QR Code to login: %s\nhttps://wechaty.github.io/qrcode/%s\n", status, qrCode)
        }).
        OnLogin(func(context *wechaty.Context, user *user.ContactSelf) {
            fmt.Printf("User %s logined\n", user)
        }).
        OnMessage(func(context *wechaty.Context, message *user.Message) {
            fmt.Printf("Message: %s\n", message)
        }).DaemonStart()
}
dosubot[bot] commented 2 months ago

To address the gRPC connection timeout issue when using puppet_padlocal with Wechaty in Go, it's important to understand how the server address is dynamically discovered using the token. The process involves making an HTTP GET request to https://api.chatie.io/v0/hosties/__token__ to retrieve the server address associated with your token. Ensure your token is correctly set in the WECHATY_PUPPET_SERVICE_TOKEN environment variable for this discovery process to work.

If you're encountering timeouts, check the following:

For customizing the gRPC connection timeout, you can use the WithTimeout(duration time.Duration) function to set a desired timeout period. Additionally, adjusting the GrpcReconnectInterval can help manage connection stability across varying network conditions.

If you continue to face issues, ensure all configurations are correct and consider network conditions or server response times as potential factors.

#### Details **Sources** - [wechaty-puppet-service/puppet_service.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/puppet_service.go) - [wechaty-puppet-service/grpc.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/grpc.go) - [wechaty-puppet-service/envvars.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/envvars.go) - [wechaty-puppet-service/ca.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/ca.go) - [wechaty-puppet-service/resolver.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/resolver.go) - [wechaty-puppet-service/options.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet-service/options.go) - [wechaty/wechaty.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty/wechaty.go) - [wechaty-puppet/option.go](https://github.com/wechaty/go-wechaty/blob/master/wechaty-puppet/option.go)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

huan commented 2 months ago

You are welcome to join the Wechaty Discord Server: there is a #go channel for discussing the Go Wechaty related questions.

Join Discord at https://discord.gg/7q8NBZbQzt