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

gen: sugared RPC request builder #146

Closed
tdakkota opened this issue Feb 11, 2021 · 2 comments
Closed

gen: sugared RPC request builder #146

tdakkota opened this issue Feb 11, 2021 · 2 comments
Labels
area: gen Codegen issues enhancement New feature or request epic Feature that is too big for single issue stale

Comments

@tdakkota
Copy link
Member

tdakkota commented Feb 11, 2021

For now use to make request we have to write something like:

	_, err = invoker.MessagesSendMedia(ctx, &tg.MessagesSendMediaRequest{
		Peer: &tg.InputPeerChannel{
			ChannelID:  ch.ID,
			AccessHash: ch.AccessHash,
		},
		Media: &tg.InputMediaUploadedDocument{
			File: f,
			Attributes: []tg.DocumentAttributeClass{
				&tg.DocumentAttributeFilename{FileName: "video.mp4"},
			},
		},
		RandomID: id,
	})

and there are some problems

  • You need to write MessagesSendMedia(ctx, ...) instead of

    messages := client.Messages(tgs.Ctx(ctx))
    messages.SendMedia(...).Do()

    or

    messages := client.Messages()
    messages.SendMedia(...).DoCtx(ctx)
  • You need to write types tg.InputMediaUploadedDocument or tg.MessagesSendMediaRequest instead of pretty methods like SendMedia or UploadedDocument.

  • You need to fill fields like RandomID manually, but it can be filled automatically using given RandomIDSource

  • Field Peer can be using different structures, so we can use mappers from gen: mappers for similar types #144 to provide multiple filling methods

  • Some classes in schema have a empty constructor which can be used by default, for example InputMessagesFilterEmpty

  • We can use zero values as valid fields in some cases even if these fields required by schema, for example message.sendMedia does not really require non-empty message field.

Finally, the sugared RPC call would be like

rpc.Messages(tgs.Ctx(ctx), tgs.ID(rand.Reader)).
  SendMedia().
  PeerChannel(id, hash).
  MediaDocument(f).Do()
@tdakkota tdakkota added enhancement New feature or request area: gen Codegen issues epic Feature that is too big for single issue labels Feb 11, 2021
@stale
Copy link

stale bot commented Feb 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 21, 2022
@tdakkota
Copy link
Member Author

We decided that making it is better to make user-friendly helpers for concreate workflows rather than just sugaring Telegram API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: gen Codegen issues enhancement New feature or request epic Feature that is too big for single issue stale
Projects
None yet
Development

No branches or pull requests

1 participant