td icon indicating copy to clipboard operation
td copied to clipboard

Cannot use peer retrieved from ContactsResolveUsername, as an argument to MessagesGetHistory

Open Lebed-kun opened this issue 3 years ago • 2 comments

Though Go's linter didn't give me a hint that I was using mismatched type;

What version of gotd are you using?

0.71.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

I tried to compile this code:

api := self.client.API()
	username := fmt.Sprintf("@%v", group)
	peer, err := api.ContactsResolveUsername(
		ctx,
		username,
	)
	if err != nil {
		return err
	}

	history, err := api.MessagesGetHistory(
		ctx,
		&tgappapiextra.MessagesGetHistoryRequest{
			Peer:  peer,
			Limit: 20,
		},
	)
	if err != nil {
		return err
	}

	messages := history.String()
	fmt.Printf(
		"retrieved msgs => %v\n",
		messages,
	)

What did you expect to see?

I expect successful compilation;

What did you see instead?

An error of type mismatch:

services/my-secret-thing/index.go:60:11: cannot use peer (variable of type *tg.ContactsResolvedPeer) as type tg.InputPeerClass in struct literal:
        *tg.ContactsResolvedPeer does not implement tg.InputPeerClass (missing construct method)

What Go version and environment are you using?

Go version: go1.18.8 linux/amd64

Lebed-kun avatar Nov 19 '22 11:11 Lebed-kun

Same problem.

farhad-arjmand avatar Feb 18 '23 08:02 farhad-arjmand

This is not a bug in the library, the approach is wrong. You need to use the data retrieved from tg.ContactsResolvedPeer and fill it in tg.InputPeerClass to make it work.

celestix avatar Feb 18 '23 16:02 celestix