亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Whatsmeow 對話數據

Whatsmeow 對話數據

Go
婷婷同學_ 2023-03-21 10:34:07
我正在嘗試使用whatsmeow為 WhatsApp構建一個tui 客戶端。翻了半天文檔,還是沒找到獲取個別聯系人對話數據的方法。任何幫助表示贊賞。我找到了ParseWebMessage但我不確定如何使用它。chatJID, err := types.ParseJID(conv.GetId())for _, historyMsg := range conv.GetMessages() {    evt, err := cli.ParseWebMessage(chatJID, historyMsg.GetMessage())    yourNormalEventHandler(evt)}事實上,我什至不確定這是否是我要找的
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

好吧,您基本上鏈接到了文檔中包含您要查找的信息的部分。ParseWebMessage調用的返回類型events.Message記錄在此處。它包含一個Info類型字段MessageInfo(再次記錄在此處)。反過來,這種MessageInfo類型嵌入了MessageSource類型see docs here看起來像這樣:

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: %s\nSent in Chat: %s\n", evt.Info.Sender, evt.Info.Chat)

if evt.Info.IsGroup {

    fmt.Printf("%s is a group chat\n", evt.Info.Chat)

}

您也可以通過簡單地執行以下操作來跳過您發送的消息:


if evt.Info.IsFromMe {

    continue

}

和字段都是類型,記錄在這里evt.Info.Chat。這種 ID 類型基本上有 2 種變體:用戶和服務器 JID 以及 AD-JID(用戶、代理和設備)。您可以通過檢查標志來區分兩者。evt.Info.SenderJIDJID.AD

我根本沒有使用過這個模塊,我只是簡單地瀏覽了文檔,但據我了解,這個模塊允許您編寫一個處理程序,它將接收您收到的所有內容的類型events.Message。通過檢查evt.Info.IsGroup,您可以了解我們發送的消息是在群聊中,還是在您的個人對話中。根據evt.Info.Senderevt.Info.Chat,您可以計算出消息的發送者。作為evt.Info.SenderJID 反過來允許您調用方法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類型沒有立即出現在文檔中,但我在 repo 中偶然發現了它。


無論哪種方式,我都不太確定你想做什么,以及你是如何/為什么被困住的。查找此信息所需要做的就是檢查ParseWebMessage您提到的方法的返回類型,檢查幾種類型,并滾動瀏覽一些列出/記錄的方法以大致了解如何獲取所有數據可能需要...


查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 321 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號