卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章35139本站已运行394

喵喵对话数据

喵喵对话数据

php小编子墨为大家带来了一款名为“喵喵对话数据”的神奇工具。这个工具能够帮助用户快速地进行对话数据的处理和分析,提供了便捷的对话数据管理和统计功能。用户只需输入对话文本,就能通过喵喵对话数据进行自动处理,并生成各种有用的统计信息,如对话频率、关键词分析等。这个工具操作简单,功能强大,非常适合需要对对话数据进行分析的用户使用。

问题内容

我正在尝试使用 whatsmeow 为 whatsapp 构建一个 tui 客户端。

经过半天的搜索和阅读文档,我仍然找不到获取单个联系人的对话数据的方法。如有任何帮助,我们将不胜感激。

我找到了 parsewebmessage,但我不太确定如何使用它。

chatJID, err := types.ParseJID(conv.GetId())
for _, historyMsg := range conv.GetMessages() {
    evt, err := cli.ParseWebMessage(chatJID, historyMsg.GetMessage())
    yourNormalEventHandler(evt)
}

事实上,我什至不确定这是否是我正在寻找的

解决方法

嗯,您基本上链接到了包含您正在查找的信息的文档部分。 parsewebmessage 调用的返回类型是 events.message,记录在 此处。它包含类型为 messageinfoinfo 字段(同样, 记录在此处)。反过来,这个 messageinfo 类型嵌入 messagesource 类型 请参阅此处的文档,如下所示:

type messagesource struct {
    chat     jid  // the chat where the message was sent.
    sender   jid  // the user who sent the message.
    isfromme bool // whether the message was sent by the current user instead of someone else.
    isgroup  bool // whether the chat is a group chat or broadcast list.

    // when sending a read receipt to a broadcast list message, the chat is the broadcast list
    // and sender is you, so this field contains the recipient of the read receipt.
    broadcastlistowner jid
}

因此,要获取发送给定消息的联系人,给定您的代码 evt, err := cli.parsewebmessage(),您需要检查:

evt, err := cli.parsewebmessage(chatjid, historymsg.getmessage())
if err != nil {
    // handle error, of course
}
fmt.printf("sender id: %snsent in chat: %sn", evt.info.sender, evt.info.chat)
if evt.info.isgroup {
    fmt.printf("%s is a group chatn", evt.info.chat)
}

您还可以通过简单地执行以下操作来跳过发送的消息:

if evt.info.isfromme {
    continue
}

evt.info.chatevt.info.sender 字段的类型均为 jid ,记录在此处。此 id 类型本质上有 2 种变体:用户和服务器 jid 以及 ad-jid(用户、代理和设备)。您可以通过检查 jid.ad 标志来区分两者。

我根本没有使用过这个模块,我只是简单地浏览了文档,但据我了解,这个模块允许您编写一个处理程序,它将接收您收到的所有内容的 events.message 类型。通过检查evt.info.isgroup,你可以弄清楚我们发送的消息是在群聊中,还是在你们的个人对话中的事情。根据evt.info.senderevt.info.chat,您可以查出​​消息是谁发送的。 evt.info.sender 作为 jid 反过来允许您调用 getuserinfo 方法,传入 jid,返回一个 userinfo 对象如此处记录,显示名称、图片、状态等...

所以我猜你正在寻找类似的东西:

// some map of all messages from a given person, sent directly to you
contacts := cli.GetAllContacts() // returns map[JID]ContactInfo
personMsg := map[string][]*events.Message
evt, err := cli.ParseWebMessage(chatJID, historyMsg.GetMessage())
if err != nil {
    // handle
}
if !evt.Info.IsFromMe && !evt.Info.IsGroup {// not a group, not sent by me
    info, _ := cli.GetUserInfo([]types.JID{evt.Info.Sender})
    if contact, ok := contacts[info[evt.Info.Sender]; ok {
        msgs, ok := personMsg[contact.PushName]
        if !ok {
            msgs := []*events.Message{}
        }
        personMsg[contact.PushName] = append(msgs, evt)
    }
}

注意 contatinfo 类型没有立即出现在文档中,但我偶然发现了它 在仓库中。

无论哪种方式,我不太确定你想做什么,以及你如何/为什么被卡住。找到此信息所需要做的就是检查您提到的 parsewebmessage 方法的返回类型,检查几种类型,然后滚动浏览一些列出/记录的方法,以粗略了解如何获取所有数据可能需要...

卓越飞翔博客
上一篇: Go 中的 YAML 自定义标签
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏