Giter Club home page Giter Club logo

go-tl-parser's Issues

Incorrect behaviour with keyword uppercase replacement

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.

Some type can not unmarshal correctly.

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.

Parser v2 still cannot unmarshal correctly.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.