Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当OnMessage接收到的Message的Type是MessageTypeLocation,怎么获取到Location信息呢? #161

Closed
jmjoy opened this issue Mar 27, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@jmjoy
Copy link

jmjoy commented Mar 27, 2024

我看Text是空的,也没有ToLocation之类的方法,怎么能获取到Location的经纬度?

@jmjoy jmjoy added the enhancement New feature or request label Mar 27, 2024
Copy link

dosubot bot commented Mar 27, 2024

嘿,@jmjoy,又见面了!希望你今天心情不错 😜

在go-wechaty中,当OnMessage接收到的MessageTypeMessageTypeLocation时,获取经纬度信息的方法并不直接。根据提供的上下文,Message结构体中并没有直接的方法或属性可以让你直接获取位置消息的经纬度。

在go-wechaty中,MessageTypeLocation消息的位置信息通常会被封装在特定于位置消息的有效负载中。由于提供的代码中没有直接访问位置信息(如经纬度)的方法,你需要扩展Message结构体的功能,或者使用底层的Puppet接口来访问包含位置信息的原始消息数据。

如果wechaty-puppet接口或者你正在使用的特定puppet支持位置消息,它可能会提供一个类似于MessageFileMessageContactMessageURLMessageMiniProgram的方法来获取位置详情。你需要查看puppet的文档或源代码以找到这样的方法。

在没有直接方法的情况下,一种方法是在Message结构体中实现一个新的方法,该方法使用GetPuppet()方法来访问puppet的API,以获取包含MessageTypeLocation消息的位置详情的原始消息数据。这种方法需要了解puppet的API以及它如何存储或提供位置数据的访问。

鉴于提供的上下文的限制,以下是你可能开始实现这样一个方法的假设示例,假设puppet的API有一个名为MessageLocation的方法,该方法返回位置详情:

// ToLocation retrieves the location information from a location type message.
func (m *Message) ToLocation() (*LocationPayload, error) {
    if m.Type() != schemas.MessageTypeLocation {
        return nil, errors.New("message not a location type")
    }
    locationPayload, err := m.GetPuppet().MessageLocation(m.id)
    if err != nil {
        return nil, err
    }
    return locationPayload, nil
}

这个示例假设存在一个LocationPayload结构体来保存位置数据,以及puppet接口中的一个MessageLocation方法,这些在提供的上下文中都不存在。你需要根据你正在使用的puppet的实际能力和API来调整这种方法。

来源:

Sources

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.

If you want to continue the conversation, start your reply with @dosu-bot.

@dchaofei
Copy link
Collaborator

dchaofei commented Mar 28, 2024

暂时还不支持 MessageTypeLocation 类型的消息处理, 不过我刚提了一个 pr:#162 去支持,还没来得及测试

@dchaofei
Copy link
Collaborator

dchaofei commented Apr 1, 2024

已在 v0.4.12 版本支持

@dchaofei dchaofei closed this as completed Apr 1, 2024
@jmjoy
Copy link
Author

jmjoy commented Apr 2, 2024

感谢大佬!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants