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.Sender
JID
JID.AD
我根本沒有使用過這個模塊,我只是簡單地瀏覽了文檔,但據我了解,這個模塊允許您編寫一個處理程序,它將接收您收到的所有內容的類型events.Message
。通過檢查evt.Info.IsGroup
,您可以了解我們發送的消息是在群聊中,還是在您的個人對話中。根據evt.Info.Sender
和evt.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類型沒有立即出現在文檔中,但我在 repo 中偶然發現了它。
無論哪種方式,我都不太確定你想做什么,以及你是如何/為什么被困住的。查找此信息所需要做的就是檢查ParseWebMessage您提到的方法的返回類型,檢查幾種類型,并滾動瀏覽一些列出/記錄的方法以大致了解如何獲取所有數據可能需要...
- 1 回答
- 0 關注
- 321 瀏覽
添加回答
舉報