首頁  >  文章  >  後端開發  >  喵喵對話數據

喵喵對話數據

PHPz
PHPz轉載
2024-02-10 10:10:08672瀏覽

喵喵對話數據

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: %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.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 方法的返回類型,檢查幾種類型,然後滾動瀏覽一些列出/記錄的方法,以粗略了解如何獲取所有數據可能需要...

以上是喵喵對話數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除