diff --git a/api/methods.gen.go b/api/methods.gen.go index bee9774..f557beb 100644 --- a/api/methods.gen.go +++ b/api/methods.gen.go @@ -27,7 +27,7 @@ type GetUpdatesParams struct { // Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only. Timeout *int64 `json:"timeout,omitempty"` // A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used.Please note that this parameter doesn't affect updates created before the call to getUpdates, so unwanted updates may be received for a short period of time. - AllowedUpdates []string `json:"allowed_updates,omitempty"` + AllowedUpdates []UpdateType `json:"allowed_updates,omitempty"` } // GetUpdates calls the getUpdates Telegram Bot API method. @@ -54,7 +54,7 @@ type SetWebhookParams struct { // The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. MaxConnections *int64 `json:"max_connections,omitempty"` // A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used.Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. - AllowedUpdates []string `json:"allowed_updates,omitempty"` + AllowedUpdates []UpdateType `json:"allowed_updates,omitempty"` // Pass True to drop all pending updates DropPendingUpdates *bool `json:"drop_pending_updates,omitempty"` // A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. diff --git a/api/types.gen.go b/api/types.gen.go index 649ffbb..34f56dc 100644 --- a/api/types.gen.go +++ b/api/types.gen.go @@ -91,7 +91,7 @@ type WebhookInfo struct { // Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery MaxConnections *int64 `json:"max_connections,omitempty"` // Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_member - AllowedUpdates []string `json:"allowed_updates,omitempty"` + AllowedUpdates []UpdateType `json:"allowed_updates,omitempty"` } // This object represents a Telegram user or bot. diff --git a/cmd/genapi/emitter.go b/cmd/genapi/emitter.go index c61344a..f5964ca 100644 --- a/cmd/genapi/emitter.go +++ b/cmd/genapi/emitter.go @@ -835,6 +835,20 @@ func goFieldX(plan *enumPlan, enumParent, overrideParent string, f spec.Field) s if name := fieldTypeOverride(overrideParent, f.Name); name != "" { return fmt.Sprintf("%s %s %s", f.Name, name, tag) } + // Pinned companion-enum retype: allowed_updates is an Array of String + // in the upstream spec, but the Go API exposes a hand-curated + // UpdateType (api/enums.go) since the values are not enumerated + // inline by Telegram. Retype []string → []UpdateType wherever the + // wire field is allowed_updates so callers can pass typed constants + // (api.UpdateMessage, ...) without string casts. Wire format is + // unchanged: UpdateType is a typed string, marshals identically. + if f.JSONName == "allowed_updates" && + f.Type.Kind == spec.KindArray && + f.Type.ElemType != nil && + f.Type.ElemType.Kind == spec.KindPrimitive && + f.Type.ElemType.Name == "string" { + return fmt.Sprintf("%s []UpdateType %s", f.Name, tag) + } return fmt.Sprintf("%s %s %s", f.Name, goType(f.Type, !f.Required), tag) } diff --git a/transport/longpoll.go b/transport/longpoll.go index 8ee3d17..19b7c43 100644 --- a/transport/longpoll.go +++ b/transport/longpoll.go @@ -72,11 +72,7 @@ func (p *LongPoller) Run(ctx context.Context) error { params.Timeout = &to } if len(p.AllowedTypes) > 0 { - allowed := make([]string, len(p.AllowedTypes)) - for i, t := range p.AllowedTypes { - allowed[i] = string(t) - } - params.AllowedUpdates = allowed + params.AllowedUpdates = p.AllowedTypes } ups, err := api.GetUpdates(ctx, p.Bot, params) if err != nil {