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

Add constants for chat actions #179

Merged
merged 2 commits into from
Jul 12, 2024
Merged

Add constants for chat actions #179

merged 2 commits into from
Jul 12, 2024

Conversation

megum1n
Copy link
Contributor

@megum1n megum1n commented Jul 12, 2024

What

Add constants for chat actions to avoid typos.
https://core.telegram.org/bots/api#sendchataction

Impact

  • Are your changes backwards compatible? Y
  • Have you included documentation, or updated existing documentation? N/A
  • Do errors and log messages provide enough context? Y

Copy link
Owner

@PaulSonOfLars PaulSonOfLars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for your contribution! Can definitely see the value in this, so appreciate the input :)

One issue though; this isn't generating from the spec. Would it be possible to change that? Thanks in advance!

Comment on lines 127 to 139
chatActions := []string{
"typing",
"upload_photo",
"record_video",
"upload_video",
"record_voice",
"upload_voice",
"upload_document",
"choose_sticker",
"find_location",
"record_video_note",
"upload_video_note",
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for this list to be obtained from the type spec?
For example, by using some regexes on the sendChatAction method's "action" field description?

If the list is defined manually, then it might as well not be generated; it's just a manually written list, and any changes on telegrams side wouldn't reflect.
I know it's done this way for formatting consts, but that was intended as an exception; parsemodes aren't expected to change, and are relatively short list!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulSonOfLars I agree, let's try to actually generate it.
I decided not to create universal function in this case because it would require a lot of input.

func generateConstsFromMethodFieldDescription(d APIDescription, methodName string, fieldName string, regexp string) (string, error) {
    ...
}

Please let me know if current code sucks.

Copy link
Owner

@PaulSonOfLars PaulSonOfLars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff, exactly what I was thinking of!

@PaulSonOfLars PaulSonOfLars enabled auto-merge (squash) July 12, 2024 21:00
@PaulSonOfLars PaulSonOfLars merged commit 00c0e11 into PaulSonOfLars:v2 Jul 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants