Arman92 / go-tdlib

Golang Telegram TdLib JSON bindings
GNU General Public License v3.0
436 stars 100 forks source link

json unmarshal loss field value #86

Open FunkyYang opened 3 years ago

FunkyYang commented 3 years ago

when I receive a message from tdlib,I saw the original string contains textEntityTypeTextUrl,but when I use tdlib.UpdateNewMessage to umarshal it,I can't find which field contains textEntityTypeTextUrl,so any one could help

FunkyYang commented 3 years ago

and message type is updateNewMessage

FunkyYang commented 3 years ago

this is the code

                               ack := &tdlib.UpdateNewMessage{}
                if err := json.Unmarshal(update.Raw, ack); err != nil {
                    log.Printf("解码失败,原因:%s", err.Error())
                    continue
                }
                log.Printf("会话id:%d", ack.Message.ChatID)
                switch ack.Message.Content.(type) {
                case *tdlib.MessageText:
                    content := ack.Message.Content.(*tdlib.MessageText)
                    if content.Text != nil {
                        log.Printf("内容:%s", content.Text.Text)
                        entityes := content.Text.Entities
                        for _, e := range entityes {
                            log.Printf("offset:%d,length:%d,type:%v", e.Offset, e.Length, e.Type)
                            switch e.Type.(type) {
                            case *tdlib.TextEntityTypeTextURL:
                                eType := e.Type.(*tdlib.TextEntityTypeTextURL)
                                log.Printf("URL:%s", eType.URL)
                            }
                        }
                    }
                default:
                }
FunkyYang commented 3 years ago

I can't get e.Type

er-azh commented 3 years ago

the issue is in the code generator. the parser runs replaceKeyWords on enum type names and this causes words like Url to become URL. but tdlib returns the original types in the @type field so when the library tries to compare textEntityTypeTextUrl with textEntityTypeTextURL this happens. link to what causes this

I actually re-wrote the entire codegen and parser parts but they're private for now (I'm planning on open-sourcing it)