Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Lebed-kun opened this issue Nov 19, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Lebed-kun
Copy link

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 Lebed-kun added the bug Something isn't working label Nov 19, 2022
@Lebed-kun Lebed-kun changed the title Help! Cannot use peer retrieved from ContactsResolveUsername, as an argument to MessagesGetHistory Cannot use peer retrieved from ContactsResolveUsername, as an argument to MessagesGetHistory Nov 19, 2022
@farhad-arjmand
Copy link

farhad-arjmand commented Feb 18, 2023

Same problem.

@celestix
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants