arman92 / go-tl-parser Goto Github PK
View Code? Open in Web Editor NEWGenerates JSON or Go structs/methods of a Telegram .tl file
License: GNU General Public License v3.0
Generates JSON or Go structs/methods of a Telegram .tl file
License: GNU General Public License v3.0
When I'm using GetTextEntityTypeEnum()
to check if the message have a URL type.
code
for _, ent := range msgEnt {
if ent.Type.GetTextEntityTypeEnum() == "textEntityTypeUrl" {
isURL = true
}
}
Expected Behavior
GetTextEntityTypeEnum()
should not crashes.
Actual Behavior
My program crashed.
After error tracing, I found the TextEntityTypeURLType
have a incorrect string textEntityTypeURL
.
https://github.com/Arman92/go-tdlib/blob/master/types.go#L434
Acutally, it should be textEntityTypeUrl
.
https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl#L1214
Why is this happening?
I spend the very much time.....
Finally, i found the reason. Due to go-tl-parser
Line 670, the method replace Url
to URL
https://github.com/Arman92/go-tl-parser/blob/master/main.go#L670
I think go-tl-parser
should not replace any variable or string, due to this will be replace wrongly.
It's affecting SearchPublicChat
and GetChat
method.
Maybe it's same issue like #1
code:
chat, err := client.SearchPublicChat("tg_x64")
if err != nil {
fmt.Println(err.Error())
return
}
Error message:
json: cannot unmarshal object into Go struct field .last_message of type tdlib.MessageSender
Reason:
Since a public channel with linked group is allow an user reply without join group,
after SearchPublicChat
, we can receive chat JSON like this
"interaction_info": {
"@type": "messageInteractionInfo",
"view_count": 1,
"forward_count": 1,
"reply_info": {
"@type": "messageReplyInfo",
"reply_count": 1,
"recent_repliers": [{
"@type": "messageSenderUser",
"user_id": 123456789
}
],
"last_read_inbox_message_id": 0,
"last_read_outbox_message_id": 0,
"last_message_id": 1048576
}
}
ref: https://github.com/tdlib/td/blob/v1.7.0/td/generate/scheme/td_api.tl#L721
But interaction_info
do not have UnmarshalJSON
method to handle multiple messageSenderUser
, so go-tdlib can't parse correctly and return the error.
It's easy to reproduce on my example code.
As title
there's no issue on parser v1 lol
Example:
https://github.com/Arman92/go-tdlib/blob/v2/client/stickerSet.go#L14
Hi @Arman92 , I have use your awesome td-lib for some days. Today I found when I call GetInlineQueryResults methon and I got an error:
cannot unmarshal object into Go struct field InlineQueryResults.results of type tdlib.InlineQueryResult
I trace the error and found unmarshalInlineQueryResult have no used by any function of type.go and method.go. And InlineQueryResults have not implement UnmarshalJSON function.
I try to write it by hand with a simple code:
// UnmarshalJSON unmarshal to json
func (inlineQueryResults *InlineQueryResults) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
InlineQueryID JSONInt64 `json:"inline_query_id"` // Unique identifier of the inline query
NextOffset string `json:"next_offset"` // The offset for the next request. If empty, there are no more results
SwitchPmText string `json:"switch_pm_text"` // If non-empty, this text should be shown on the button, which opens a private chat with the bot and sends the bot a start message with the switch_pm_parameter
SwitchPmParameter string `json:"switch_pm_parameter"` // Parameter for the bot start message
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
inlineQueryResults.tdCommon = tempObj.tdCommon
inlineQueryResults.InlineQueryID = tempObj.InlineQueryID
inlineQueryResults.NextOffset = tempObj.NextOffset
inlineQueryResults.SwitchPmText = tempObj.SwitchPmText
inlineQueryResults.SwitchPmParameter = tempObj.SwitchPmParameter
var Results []InlineQueryResult
var tempResults []*json.RawMessage
byteResults, err := objMap["results"].MarshalJSON()
if err != nil {
return err
}
err = json.Unmarshal(byteResults, &tempResults)
if err != nil {
return err
}
for _, r := range tempResults {
fieldResult, _ := unmarshalInlineQueryResult(r)
Results = append(Results, fieldResult)
}
inlineQueryResults.Results = Results
return nil
}
and the error gone. So I think the parser may have some bugs and cause some necessary code not generated. But the parser code is a bit complex and I dont know how to fix it now. Can you check it out? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.