diff --git a/client/authorization.go b/client/authorization.go index 588c1de..c31005f 100644 --- a/client/authorization.go +++ b/client/authorization.go @@ -57,19 +57,29 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization switch state.AuthorizationStateType() { case TypeAuthorizationStateWaitTdlibParameters: - _, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters) + _, err := client.SetTdlibParameters(&SetTdlibParametersRequest{ + Parameters: <-stateHandler.TdlibParameters, + }) return err case TypeAuthorizationStateWaitEncryptionKey: - _, err := client.CheckDatabaseEncryptionKey(nil) + _, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{}) return err case TypeAuthorizationStateWaitPhoneNumber: - _, err := client.SetAuthenticationPhoneNumber(<-stateHandler.PhoneNumber, false, false) + _, err := client.SetAuthenticationPhoneNumber(&SetAuthenticationPhoneNumberRequest{ + PhoneNumber: <-stateHandler.PhoneNumber, + AllowFlashCall: false, + IsCurrentPhoneNumber: false, + }) return err case TypeAuthorizationStateWaitCode: - _, err := client.CheckAuthenticationCode(<-stateHandler.Code, <-stateHandler.FirstName, <-stateHandler.LastName) + _, err := client.CheckAuthenticationCode(&CheckAuthenticationCodeRequest{ + Code: <-stateHandler.Code, + FirstName: <-stateHandler.FirstName, + LastName: <-stateHandler.LastName, + }) return err case TypeAuthorizationStateWaitPassword: @@ -162,15 +172,19 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta switch state.AuthorizationStateType() { case TypeAuthorizationStateWaitTdlibParameters: - _, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters) + _, err := client.SetTdlibParameters(&SetTdlibParametersRequest{ + Parameters: <-stateHandler.TdlibParameters, + }) return err case TypeAuthorizationStateWaitEncryptionKey: - _, err := client.CheckDatabaseEncryptionKey(nil) + _, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{}) return err case TypeAuthorizationStateWaitPhoneNumber: - _, err := client.CheckAuthenticationBotToken(<-stateHandler.Token) + _, err := client.CheckAuthenticationBotToken(&CheckAuthenticationBotTokenRequest{ + Token: <-stateHandler.Token, + }) return err case TypeAuthorizationStateWaitCode: diff --git a/client/function.go b/client/function.go index ff14d6b..2092db0 100755 --- a/client/function.go +++ b/client/function.go @@ -55,16 +55,19 @@ func (client *Client) GetAuthorizationState() (AuthorizationState, error) { } } +type SetTdlibParametersRequest struct { + // Parameters + Parameters *TdlibParameters `json:"parameters"` +} + // Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters -// -// @param parameters Parameters -func (client *Client) SetTdlibParameters(parameters *TdlibParameters) (*Ok, error) { +func (client *Client) SetTdlibParameters(req *SetTdlibParametersRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setTdlibParameters", }, Data: map[string]interface{}{ - "parameters": parameters, + "parameters": req.Parameters, }, }) if err != nil { @@ -78,16 +81,19 @@ func (client *Client) SetTdlibParameters(parameters *TdlibParameters) (*Ok, erro return UnmarshalOk(result.Data) } +type CheckDatabaseEncryptionKeyRequest struct { + // Encryption key to check or set up + EncryptionKey []byte `json:"encryption_key"` +} + // Checks the database encryption key for correctness. Works only when the current authorization state is authorizationStateWaitEncryptionKey -// -// @param encryptionKey Encryption key to check or set up -func (client *Client) CheckDatabaseEncryptionKey(encryptionKey []byte) (*Ok, error) { +func (client *Client) CheckDatabaseEncryptionKey(req *CheckDatabaseEncryptionKeyRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkDatabaseEncryptionKey", }, Data: map[string]interface{}{ - "encryption_key": encryptionKey, + "encryption_key": req.EncryptionKey, }, }) if err != nil { @@ -101,20 +107,25 @@ func (client *Client) CheckDatabaseEncryptionKey(encryptionKey []byte) (*Ok, err return UnmarshalOk(result.Data) } +type SetAuthenticationPhoneNumberRequest struct { + // The phone number of the user, in international format + PhoneNumber string `json:"phone_number"` + // Pass true if the authentication code may be sent via flash call to the specified phone number + AllowFlashCall bool `json:"allow_flash_call"` + // Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false + IsCurrentPhoneNumber bool `json:"is_current_phone_number"` +} + // Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber -// -// @param phoneNumber The phone number of the user, in international format -// @param allowFlashCall Pass true if the authentication code may be sent via flash call to the specified phone number -// @param isCurrentPhoneNumber Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false -func (client *Client) SetAuthenticationPhoneNumber(phoneNumber string, allowFlashCall bool, isCurrentPhoneNumber bool) (*Ok, error) { +func (client *Client) SetAuthenticationPhoneNumber(req *SetAuthenticationPhoneNumberRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setAuthenticationPhoneNumber", }, Data: map[string]interface{}{ - "phone_number": phoneNumber, - "allow_flash_call": allowFlashCall, - "is_current_phone_number": isCurrentPhoneNumber, + "phone_number": req.PhoneNumber, + "allow_flash_call": req.AllowFlashCall, + "is_current_phone_number": req.IsCurrentPhoneNumber, }, }) if err != nil { @@ -147,20 +158,25 @@ func (client *Client) ResendAuthenticationCode() (*Ok, error) { return UnmarshalOk(result.Data) } +type CheckAuthenticationCodeRequest struct { + // The verification code received via SMS, Telegram message, phone call, or flash call + Code string `json:"code"` + // If the user is not yet registered, the first name of the user; 1-255 characters + FirstName string `json:"first_name"` + // If the user is not yet registered; the last name of the user; optional; 0-255 characters + LastName string `json:"last_name"` +} + // Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode -// -// @param code The verification code received via SMS, Telegram message, phone call, or flash call -// @param firstName If the user is not yet registered, the first name of the user; 1-255 characters -// @param lastName If the user is not yet registered; the last name of the user; optional; 0-255 characters -func (client *Client) CheckAuthenticationCode(code string, firstName string, lastName string) (*Ok, error) { +func (client *Client) CheckAuthenticationCode(req *CheckAuthenticationCodeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkAuthenticationCode", }, Data: map[string]interface{}{ - "code": code, - "first_name": firstName, - "last_name": lastName, + "code": req.Code, + "first_name": req.FirstName, + "last_name": req.LastName, }, }) if err != nil { @@ -174,16 +190,19 @@ func (client *Client) CheckAuthenticationCode(code string, firstName string, las return UnmarshalOk(result.Data) } +type CheckAuthenticationPasswordRequest struct { + // The password to check + Password string `json:"password"` +} + // Checks the authentication password for correctness. Works only when the current authorization state is authorizationStateWaitPassword -// -// @param password The password to check -func (client *Client) CheckAuthenticationPassword(password string) (*Ok, error) { +func (client *Client) CheckAuthenticationPassword(req *CheckAuthenticationPasswordRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkAuthenticationPassword", }, Data: map[string]interface{}{ - "password": password, + "password": req.Password, }, }) if err != nil { @@ -216,16 +235,19 @@ func (client *Client) RequestAuthenticationPasswordRecovery() (*Ok, error) { return UnmarshalOk(result.Data) } +type RecoverAuthenticationPasswordRequest struct { + // Recovery code to check + RecoveryCode string `json:"recovery_code"` +} + // Recovers the password with a password recovery code sent to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword -// -// @param recoveryCode Recovery code to check -func (client *Client) RecoverAuthenticationPassword(recoveryCode string) (*Ok, error) { +func (client *Client) RecoverAuthenticationPassword(req *RecoverAuthenticationPasswordRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "recoverAuthenticationPassword", }, Data: map[string]interface{}{ - "recovery_code": recoveryCode, + "recovery_code": req.RecoveryCode, }, }) if err != nil { @@ -239,16 +261,19 @@ func (client *Client) RecoverAuthenticationPassword(recoveryCode string) (*Ok, e return UnmarshalOk(result.Data) } +type CheckAuthenticationBotTokenRequest struct { + // The bot token + Token string `json:"token"` +} + // Checks the authentication token of a bot; to log in as a bot. Works only when the current authorization state is authorizationStateWaitPhoneNumber. Can be used instead of setAuthenticationPhoneNumber and checkAuthenticationCode to log in -// -// @param token The bot token -func (client *Client) CheckAuthenticationBotToken(token string) (*Ok, error) { +func (client *Client) CheckAuthenticationBotToken(req *CheckAuthenticationBotTokenRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkAuthenticationBotToken", }, Data: map[string]interface{}{ - "token": token, + "token": req.Token, }, }) if err != nil { @@ -319,16 +344,19 @@ func (client *Client) Destroy() (*Ok, error) { return UnmarshalOk(result.Data) } +type SetDatabaseEncryptionKeyRequest struct { + // New encryption key + NewEncryptionKey []byte `json:"new_encryption_key"` +} + // Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain -// -// @param newEncryptionKey New encryption key -func (client *Client) SetDatabaseEncryptionKey(newEncryptionKey []byte) (*Ok, error) { +func (client *Client) SetDatabaseEncryptionKey(req *SetDatabaseEncryptionKeyRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setDatabaseEncryptionKey", }, Data: map[string]interface{}{ - "new_encryption_key": newEncryptionKey, + "new_encryption_key": req.NewEncryptionKey, }, }) if err != nil { @@ -361,24 +389,31 @@ func (client *Client) GetPasswordState() (*PasswordState, error) { return UnmarshalPasswordState(result.Data) } +type SetPasswordRequest struct { + // Previous password of the user + OldPassword string `json:"old_password"` + // New password of the user; may be empty to remove the password + NewPassword string `json:"new_password"` + // New password hint; may be empty + NewHint string `json:"new_hint"` + // Pass true if the recovery email address should be changed + SetRecoveryEmailAddress bool `json:"set_recovery_email_address"` + // New recovery email address; may be empty + NewRecoveryEmailAddress string `json:"new_recovery_email_address"` +} + // Changes the password for the user. If a new recovery email address is specified, then the error EMAIL_UNCONFIRMED is returned and the password change will not be applied until the new recovery email address has been confirmed. The application should periodically call getPasswordState to check whether the new email address has been confirmed -// -// @param oldPassword Previous password of the user -// @param newPassword New password of the user; may be empty to remove the password -// @param newHint New password hint; may be empty -// @param setRecoveryEmailAddress Pass true if the recovery email address should be changed -// @param newRecoveryEmailAddress New recovery email address; may be empty -func (client *Client) SetPassword(oldPassword string, newPassword string, newHint string, setRecoveryEmailAddress bool, newRecoveryEmailAddress string) (*PasswordState, error) { +func (client *Client) SetPassword(req *SetPasswordRequest) (*PasswordState, error) { result, err := client.Send(Request{ meta: meta{ Type: "setPassword", }, Data: map[string]interface{}{ - "old_password": oldPassword, - "new_password": newPassword, - "new_hint": newHint, - "set_recovery_email_address": setRecoveryEmailAddress, - "new_recovery_email_address": newRecoveryEmailAddress, + "old_password": req.OldPassword, + "new_password": req.NewPassword, + "new_hint": req.NewHint, + "set_recovery_email_address": req.SetRecoveryEmailAddress, + "new_recovery_email_address": req.NewRecoveryEmailAddress, }, }) if err != nil { @@ -392,16 +427,19 @@ func (client *Client) SetPassword(oldPassword string, newPassword string, newHin return UnmarshalPasswordState(result.Data) } +type GetRecoveryEmailAddressRequest struct { + // The password for the current user + Password string `json:"password"` +} + // Returns a recovery email address that was previously set up. This method can be used to verify a password provided by the user -// -// @param password The password for the current user -func (client *Client) GetRecoveryEmailAddress(password string) (*RecoveryEmailAddress, error) { +func (client *Client) GetRecoveryEmailAddress(req *GetRecoveryEmailAddressRequest) (*RecoveryEmailAddress, error) { result, err := client.Send(Request{ meta: meta{ Type: "getRecoveryEmailAddress", }, Data: map[string]interface{}{ - "password": password, + "password": req.Password, }, }) if err != nil { @@ -415,18 +453,22 @@ func (client *Client) GetRecoveryEmailAddress(password string) (*RecoveryEmailAd return UnmarshalRecoveryEmailAddress(result.Data) } +type SetRecoveryEmailAddressRequest struct { + // Password of the current user + Password string `json:"password"` + // New recovery email address + NewRecoveryEmailAddress string `json:"new_recovery_email_address"` +} + // Changes the recovery email address of the user. If a new recovery email address is specified, then the error EMAIL_UNCONFIRMED is returned and the email address will not be changed until the new email has been confirmed. The application should periodically call getPasswordState to check whether the email address has been confirmed. If new_recovery_email_address is the same as the email address that is currently set up, this call succeeds immediately and aborts all other requests waiting for an email confirmation -// -// @param password Password of the current user -// @param newRecoveryEmailAddress New recovery email address -func (client *Client) SetRecoveryEmailAddress(password string, newRecoveryEmailAddress string) (*PasswordState, error) { +func (client *Client) SetRecoveryEmailAddress(req *SetRecoveryEmailAddressRequest) (*PasswordState, error) { result, err := client.Send(Request{ meta: meta{ Type: "setRecoveryEmailAddress", }, Data: map[string]interface{}{ - "password": password, - "new_recovery_email_address": newRecoveryEmailAddress, + "password": req.Password, + "new_recovery_email_address": req.NewRecoveryEmailAddress, }, }) if err != nil { @@ -459,16 +501,19 @@ func (client *Client) RequestPasswordRecovery() (*EmailAddressAuthenticationCode return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data) } +type RecoverPasswordRequest struct { + // Recovery code to check + RecoveryCode string `json:"recovery_code"` +} + // Recovers the password using a recovery code sent to an email address that was previously set up -// -// @param recoveryCode Recovery code to check -func (client *Client) RecoverPassword(recoveryCode string) (*PasswordState, error) { +func (client *Client) RecoverPassword(req *RecoverPasswordRequest) (*PasswordState, error) { result, err := client.Send(Request{ meta: meta{ Type: "recoverPassword", }, Data: map[string]interface{}{ - "recovery_code": recoveryCode, + "recovery_code": req.RecoveryCode, }, }) if err != nil { @@ -482,18 +527,22 @@ func (client *Client) RecoverPassword(recoveryCode string) (*PasswordState, erro return UnmarshalPasswordState(result.Data) } +type CreateTemporaryPasswordRequest struct { + // Persistent user password + Password string `json:"password"` + // Time during which the temporary password will be valid, in seconds; should be between 60 and 86400 + ValidFor int32 `json:"valid_for"` +} + // Creates a new temporary password for processing payments -// -// @param password Persistent user password -// @param validFor Time during which the temporary password will be valid, in seconds; should be between 60 and 86400 -func (client *Client) CreateTemporaryPassword(password string, validFor int32) (*TemporaryPasswordState, error) { +func (client *Client) CreateTemporaryPassword(req *CreateTemporaryPasswordRequest) (*TemporaryPasswordState, error) { result, err := client.Send(Request{ meta: meta{ Type: "createTemporaryPassword", }, Data: map[string]interface{}{ - "password": password, - "valid_for": validFor, + "password": req.Password, + "valid_for": req.ValidFor, }, }) if err != nil { @@ -526,18 +575,22 @@ func (client *Client) GetTemporaryPasswordState() (*TemporaryPasswordState, erro return UnmarshalTemporaryPasswordState(result.Data) } +type ProcessDcUpdateRequest struct { + // Value of the "dc" parameter of the notification + Dc string `json:"dc"` + // Value of the "addr" parameter of the notification + Addr string `json:"addr"` +} + // Handles a DC_UPDATE push service notification. Can be called before authorization -// -// @param dc Value of the "dc" parameter of the notification -// @param addr Value of the "addr" parameter of the notification -func (client *Client) ProcessDcUpdate(dc string, addr string) (*Ok, error) { +func (client *Client) ProcessDcUpdate(req *ProcessDcUpdateRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "processDcUpdate", }, Data: map[string]interface{}{ - "dc": dc, - "addr": addr, + "dc": req.Dc, + "addr": req.Addr, }, }) if err != nil { @@ -570,16 +623,19 @@ func (client *Client) GetMe() (*User, error) { return UnmarshalUser(result.Data) } +type GetUserRequest struct { + // User identifier + UserId int32 `json:"user_id"` +} + // Returns information about a user by their identifier. This is an offline request if the current user is not a bot -// -// @param userId User identifier -func (client *Client) GetUser(userId int32) (*User, error) { +func (client *Client) GetUser(req *GetUserRequest) (*User, error) { result, err := client.Send(Request{ meta: meta{ Type: "getUser", }, Data: map[string]interface{}{ - "user_id": userId, + "user_id": req.UserId, }, }) if err != nil { @@ -593,16 +649,19 @@ func (client *Client) GetUser(userId int32) (*User, error) { return UnmarshalUser(result.Data) } +type GetUserFullInfoRequest struct { + // User identifier + UserId int32 `json:"user_id"` +} + // Returns full information about a user by their identifier -// -// @param userId User identifier -func (client *Client) GetUserFullInfo(userId int32) (*UserFullInfo, error) { +func (client *Client) GetUserFullInfo(req *GetUserFullInfoRequest) (*UserFullInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "getUserFullInfo", }, Data: map[string]interface{}{ - "user_id": userId, + "user_id": req.UserId, }, }) if err != nil { @@ -616,16 +675,19 @@ func (client *Client) GetUserFullInfo(userId int32) (*UserFullInfo, error) { return UnmarshalUserFullInfo(result.Data) } +type GetBasicGroupRequest struct { + // Basic group identifier + BasicGroupId int32 `json:"basic_group_id"` +} + // Returns information about a basic group by its identifier. This is an offline request if the current user is not a bot -// -// @param basicGroupId Basic group identifier -func (client *Client) GetBasicGroup(basicGroupId int32) (*BasicGroup, error) { +func (client *Client) GetBasicGroup(req *GetBasicGroupRequest) (*BasicGroup, error) { result, err := client.Send(Request{ meta: meta{ Type: "getBasicGroup", }, Data: map[string]interface{}{ - "basic_group_id": basicGroupId, + "basic_group_id": req.BasicGroupId, }, }) if err != nil { @@ -639,16 +701,19 @@ func (client *Client) GetBasicGroup(basicGroupId int32) (*BasicGroup, error) { return UnmarshalBasicGroup(result.Data) } +type GetBasicGroupFullInfoRequest struct { + // Basic group identifier + BasicGroupId int32 `json:"basic_group_id"` +} + // Returns full information about a basic group by its identifier -// -// @param basicGroupId Basic group identifier -func (client *Client) GetBasicGroupFullInfo(basicGroupId int32) (*BasicGroupFullInfo, error) { +func (client *Client) GetBasicGroupFullInfo(req *GetBasicGroupFullInfoRequest) (*BasicGroupFullInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "getBasicGroupFullInfo", }, Data: map[string]interface{}{ - "basic_group_id": basicGroupId, + "basic_group_id": req.BasicGroupId, }, }) if err != nil { @@ -662,16 +727,19 @@ func (client *Client) GetBasicGroupFullInfo(basicGroupId int32) (*BasicGroupFull return UnmarshalBasicGroupFullInfo(result.Data) } +type GetSupergroupRequest struct { + // Supergroup or channel identifier + SupergroupId int32 `json:"supergroup_id"` +} + // Returns information about a supergroup or channel by its identifier. This is an offline request if the current user is not a bot -// -// @param supergroupId Supergroup or channel identifier -func (client *Client) GetSupergroup(supergroupId int32) (*Supergroup, error) { +func (client *Client) GetSupergroup(req *GetSupergroupRequest) (*Supergroup, error) { result, err := client.Send(Request{ meta: meta{ Type: "getSupergroup", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, + "supergroup_id": req.SupergroupId, }, }) if err != nil { @@ -685,16 +753,19 @@ func (client *Client) GetSupergroup(supergroupId int32) (*Supergroup, error) { return UnmarshalSupergroup(result.Data) } +type GetSupergroupFullInfoRequest struct { + // Supergroup or channel identifier + SupergroupId int32 `json:"supergroup_id"` +} + // Returns full information about a supergroup or channel by its identifier, cached for up to 1 minute -// -// @param supergroupId Supergroup or channel identifier -func (client *Client) GetSupergroupFullInfo(supergroupId int32) (*SupergroupFullInfo, error) { +func (client *Client) GetSupergroupFullInfo(req *GetSupergroupFullInfoRequest) (*SupergroupFullInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "getSupergroupFullInfo", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, + "supergroup_id": req.SupergroupId, }, }) if err != nil { @@ -708,16 +779,19 @@ func (client *Client) GetSupergroupFullInfo(supergroupId int32) (*SupergroupFull return UnmarshalSupergroupFullInfo(result.Data) } +type GetSecretChatRequest struct { + // Secret chat identifier + SecretChatId int32 `json:"secret_chat_id"` +} + // Returns information about a secret chat by its identifier. This is an offline request -// -// @param secretChatId Secret chat identifier -func (client *Client) GetSecretChat(secretChatId int32) (*SecretChat, error) { +func (client *Client) GetSecretChat(req *GetSecretChatRequest) (*SecretChat, error) { result, err := client.Send(Request{ meta: meta{ Type: "getSecretChat", }, Data: map[string]interface{}{ - "secret_chat_id": secretChatId, + "secret_chat_id": req.SecretChatId, }, }) if err != nil { @@ -731,16 +805,19 @@ func (client *Client) GetSecretChat(secretChatId int32) (*SecretChat, error) { return UnmarshalSecretChat(result.Data) } +type GetChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Returns information about a chat by its identifier, this is an offline request if the current user is not a bot -// -// @param chatId Chat identifier -func (client *Client) GetChat(chatId int64) (*Chat, error) { +func (client *Client) GetChat(req *GetChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -754,18 +831,22 @@ func (client *Client) GetChat(chatId int64) (*Chat, error) { return UnmarshalChat(result.Data) } +type GetMessageRequest struct { + // Identifier of the chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message to get + MessageId int64 `json:"message_id"` +} + // Returns information about a message -// -// @param chatId Identifier of the chat the message belongs to -// @param messageId Identifier of the message to get -func (client *Client) GetMessage(chatId int64, messageId int64) (*Message, error) { +func (client *Client) GetMessage(req *GetMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "getMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -779,18 +860,22 @@ func (client *Client) GetMessage(chatId int64, messageId int64) (*Message, error return UnmarshalMessage(result.Data) } +type GetRepliedMessageRequest struct { + // Identifier of the chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message reply to which get + MessageId int64 `json:"message_id"` +} + // Returns information about a message that is replied by given message -// -// @param chatId Identifier of the chat the message belongs to -// @param messageId Identifier of the message reply to which get -func (client *Client) GetRepliedMessage(chatId int64, messageId int64) (*Message, error) { +func (client *Client) GetRepliedMessage(req *GetRepliedMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "getRepliedMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -804,16 +889,19 @@ func (client *Client) GetRepliedMessage(chatId int64, messageId int64) (*Message return UnmarshalMessage(result.Data) } +type GetChatPinnedMessageRequest struct { + // Identifier of the chat the message belongs to + ChatId int64 `json:"chat_id"` +} + // Returns information about a pinned chat message -// -// @param chatId Identifier of the chat the message belongs to -func (client *Client) GetChatPinnedMessage(chatId int64) (*Message, error) { +func (client *Client) GetChatPinnedMessage(req *GetChatPinnedMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatPinnedMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -827,18 +915,22 @@ func (client *Client) GetChatPinnedMessage(chatId int64) (*Message, error) { return UnmarshalMessage(result.Data) } +type GetMessagesRequest struct { + // Identifier of the chat the messages belong to + ChatId int64 `json:"chat_id"` + // Identifiers of the messages to get + MessageIds []int64 `json:"message_ids"` +} + // Returns information about messages. If a message is not found, returns null on the corresponding position of the result -// -// @param chatId Identifier of the chat the messages belong to -// @param messageIds Identifiers of the messages to get -func (client *Client) GetMessages(chatId int64, messageIds []int64) (*Messages, error) { +func (client *Client) GetMessages(req *GetMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "getMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_ids": messageIds, + "chat_id": req.ChatId, + "message_ids": req.MessageIds, }, }) if err != nil { @@ -852,16 +944,19 @@ func (client *Client) GetMessages(chatId int64, messageIds []int64) (*Messages, return UnmarshalMessages(result.Data) } +type GetFileRequest struct { + // Identifier of the file to get + FileId int32 `json:"file_id"` +} + // Returns information about a file; this is an offline request -// -// @param fileId Identifier of the file to get -func (client *Client) GetFile(fileId int32) (*File, error) { +func (client *Client) GetFile(req *GetFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "getFile", }, Data: map[string]interface{}{ - "file_id": fileId, + "file_id": req.FileId, }, }) if err != nil { @@ -875,18 +970,22 @@ func (client *Client) GetFile(fileId int32) (*File, error) { return UnmarshalFile(result.Data) } +type GetRemoteFileRequest struct { + // Remote identifier of the file to get + RemoteFileId string `json:"remote_file_id"` + // File type, if known + FileType FileType `json:"file_type"` +} + // Returns information about a file by its remote ID; this is an offline request. Can be used to register a URL as a file for further uploading, or sending as a message -// -// @param remoteFileId Remote identifier of the file to get -// @param fileType File type, if known -func (client *Client) GetRemoteFile(remoteFileId string, fileType FileType) (*File, error) { +func (client *Client) GetRemoteFile(req *GetRemoteFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "getRemoteFile", }, Data: map[string]interface{}{ - "remote_file_id": remoteFileId, - "file_type": fileType, + "remote_file_id": req.RemoteFileId, + "file_type": req.FileType, }, }) if err != nil { @@ -900,20 +999,25 @@ func (client *Client) GetRemoteFile(remoteFileId string, fileType FileType) (*Fi return UnmarshalFile(result.Data) } +type GetChatsRequest struct { + // Chat order to return chats from + OffsetOrder JsonInt64 `json:"offset_order"` + // Chat identifier to return chats from + OffsetChatId int64 `json:"offset_chat_id"` + // The maximum number of chats to be returned. It is possible that fewer chats than the limit are returned even if the end of the list is not reached + Limit int32 `json:"limit"` +} + // Returns an ordered list of chats. Chats are sorted by the pair (order, chat_id) in decreasing order. (For example, to get a list of chats from the beginning, the offset_order should be equal to 2^63 - 1). For optimal performance the number of returned chats is chosen by the library. -// -// @param offsetOrder Chat order to return chats from -// @param offsetChatId Chat identifier to return chats from -// @param limit The maximum number of chats to be returned. It is possible that fewer chats than the limit are returned even if the end of the list is not reached -func (client *Client) GetChats(offsetOrder JsonInt64, offsetChatId int64, limit int32) (*Chats, error) { +func (client *Client) GetChats(req *GetChatsRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChats", }, Data: map[string]interface{}{ - "offset_order": offsetOrder, - "offset_chat_id": offsetChatId, - "limit": limit, + "offset_order": req.OffsetOrder, + "offset_chat_id": req.OffsetChatId, + "limit": req.Limit, }, }) if err != nil { @@ -927,16 +1031,19 @@ func (client *Client) GetChats(offsetOrder JsonInt64, offsetChatId int64, limit return UnmarshalChats(result.Data) } +type SearchPublicChatRequest struct { + // Username to be resolved + Username string `json:"username"` +} + // Searches a public chat by its username. Currently only private chats, supergroups and channels can be public. Returns the chat if found; otherwise an error is returned -// -// @param username Username to be resolved -func (client *Client) SearchPublicChat(username string) (*Chat, error) { +func (client *Client) SearchPublicChat(req *SearchPublicChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchPublicChat", }, Data: map[string]interface{}{ - "username": username, + "username": req.Username, }, }) if err != nil { @@ -950,16 +1057,19 @@ func (client *Client) SearchPublicChat(username string) (*Chat, error) { return UnmarshalChat(result.Data) } +type SearchPublicChatsRequest struct { + // Query to search for + Query string `json:"query"` +} + // Searches public chats by looking for specified query in their username and title. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results -// -// @param query Query to search for -func (client *Client) SearchPublicChats(query string) (*Chats, error) { +func (client *Client) SearchPublicChats(req *SearchPublicChatsRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchPublicChats", }, Data: map[string]interface{}{ - "query": query, + "query": req.Query, }, }) if err != nil { @@ -973,18 +1083,22 @@ func (client *Client) SearchPublicChats(query string) (*Chats, error) { return UnmarshalChats(result.Data) } +type SearchChatsRequest struct { + // Query to search for. If the query is empty, returns up to 20 recently found chats + Query string `json:"query"` + // Maximum number of chats to be returned + Limit int32 `json:"limit"` +} + // Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the chat list -// -// @param query Query to search for. If the query is empty, returns up to 20 recently found chats -// @param limit Maximum number of chats to be returned -func (client *Client) SearchChats(query string, limit int32) (*Chats, error) { +func (client *Client) SearchChats(req *SearchChatsRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchChats", }, Data: map[string]interface{}{ - "query": query, - "limit": limit, + "query": req.Query, + "limit": req.Limit, }, }) if err != nil { @@ -998,18 +1112,22 @@ func (client *Client) SearchChats(query string, limit int32) (*Chats, error) { return UnmarshalChats(result.Data) } +type SearchChatsOnServerRequest struct { + // Query to search for + Query string `json:"query"` + // Maximum number of chats to be returned + Limit int32 `json:"limit"` +} + // Searches for the specified query in the title and username of already known chats via request to the server. Returns chats in the order seen in the chat list -// -// @param query Query to search for -// @param limit Maximum number of chats to be returned -func (client *Client) SearchChatsOnServer(query string, limit int32) (*Chats, error) { +func (client *Client) SearchChatsOnServer(req *SearchChatsOnServerRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchChatsOnServer", }, Data: map[string]interface{}{ - "query": query, - "limit": limit, + "query": req.Query, + "limit": req.Limit, }, }) if err != nil { @@ -1023,18 +1141,22 @@ func (client *Client) SearchChatsOnServer(query string, limit int32) (*Chats, er return UnmarshalChats(result.Data) } +type GetTopChatsRequest struct { + // Category of chats to be returned + Category TopChatCategory `json:"category"` + // Maximum number of chats to be returned; up to 30 + Limit int32 `json:"limit"` +} + // Returns a list of frequently used chats. Supported only if the chat info database is enabled -// -// @param category Category of chats to be returned -// @param limit Maximum number of chats to be returned; up to 30 -func (client *Client) GetTopChats(category TopChatCategory, limit int32) (*Chats, error) { +func (client *Client) GetTopChats(req *GetTopChatsRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "getTopChats", }, Data: map[string]interface{}{ - "category": category, - "limit": limit, + "category": req.Category, + "limit": req.Limit, }, }) if err != nil { @@ -1048,18 +1170,22 @@ func (client *Client) GetTopChats(category TopChatCategory, limit int32) (*Chats return UnmarshalChats(result.Data) } +type RemoveTopChatRequest struct { + // Category of frequently used chats + Category TopChatCategory `json:"category"` + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Removes a chat from the list of frequently used chats. Supported only if the chat info database is enabled -// -// @param category Category of frequently used chats -// @param chatId Chat identifier -func (client *Client) RemoveTopChat(category TopChatCategory, chatId int64) (*Ok, error) { +func (client *Client) RemoveTopChat(req *RemoveTopChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeTopChat", }, Data: map[string]interface{}{ - "category": category, - "chat_id": chatId, + "category": req.Category, + "chat_id": req.ChatId, }, }) if err != nil { @@ -1073,16 +1199,19 @@ func (client *Client) RemoveTopChat(category TopChatCategory, chatId int64) (*Ok return UnmarshalOk(result.Data) } +type AddRecentlyFoundChatRequest struct { + // Identifier of the chat to add + ChatId int64 `json:"chat_id"` +} + // Adds a chat to the list of recently found chats. The chat is added to the beginning of the list. If the chat is already in the list, it will be removed from the list first -// -// @param chatId Identifier of the chat to add -func (client *Client) AddRecentlyFoundChat(chatId int64) (*Ok, error) { +func (client *Client) AddRecentlyFoundChat(req *AddRecentlyFoundChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addRecentlyFoundChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -1096,16 +1225,19 @@ func (client *Client) AddRecentlyFoundChat(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type RemoveRecentlyFoundChatRequest struct { + // Identifier of the chat to be removed + ChatId int64 `json:"chat_id"` +} + // Removes a chat from the list of recently found chats -// -// @param chatId Identifier of the chat to be removed -func (client *Client) RemoveRecentlyFoundChat(chatId int64) (*Ok, error) { +func (client *Client) RemoveRecentlyFoundChat(req *RemoveRecentlyFoundChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeRecentlyFoundChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -1138,18 +1270,22 @@ func (client *Client) ClearRecentlyFoundChats() (*Ok, error) { return UnmarshalOk(result.Data) } +type CheckChatUsernameRequest struct { + // Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created + ChatId JsonInt64 `json:"chat_id"` + // Username to be checked + Username string `json:"username"` +} + // Checks whether a username can be set for a chat -// -// @param chatId Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created -// @param username Username to be checked -func (client *Client) CheckChatUsername(chatId JsonInt64, username string) (CheckChatUsernameResult, error) { +func (client *Client) CheckChatUsername(req *CheckChatUsernameRequest) (CheckChatUsernameResult, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkChatUsername", }, Data: map[string]interface{}{ - "chat_id": chatId, - "username": username, + "chat_id": req.ChatId, + "username": req.Username, }, }) if err != nil { @@ -1200,20 +1336,25 @@ func (client *Client) GetCreatedPublicChats() (*Chats, error) { return UnmarshalChats(result.Data) } +type GetGroupsInCommonRequest struct { + // User identifier + UserId int32 `json:"user_id"` + // Chat identifier starting from which to return chats; use 0 for the first request + OffsetChatId int64 `json:"offset_chat_id"` + // Maximum number of chats to be returned; up to 100 + Limit int32 `json:"limit"` +} + // Returns a list of common chats with a given user. Chats are sorted by their type and creation date -// -// @param userId User identifier -// @param offsetChatId Chat identifier starting from which to return chats; use 0 for the first request -// @param limit Maximum number of chats to be returned; up to 100 -func (client *Client) GetGroupsInCommon(userId int32, offsetChatId int64, limit int32) (*Chats, error) { +func (client *Client) GetGroupsInCommon(req *GetGroupsInCommonRequest) (*Chats, error) { result, err := client.Send(Request{ meta: meta{ Type: "getGroupsInCommon", }, Data: map[string]interface{}{ - "user_id": userId, - "offset_chat_id": offsetChatId, - "limit": limit, + "user_id": req.UserId, + "offset_chat_id": req.OffsetChatId, + "limit": req.Limit, }, }) if err != nil { @@ -1227,24 +1368,31 @@ func (client *Client) GetGroupsInCommon(userId int32, offsetChatId int64, limit return UnmarshalChats(result.Data) } +type GetChatHistoryRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Identifier of the message starting from which history must be fetched; use 0 to get results from the last message + FromMessageId int64 `json:"from_message_id"` + // Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages + Offset int32 `json:"offset"` + // The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached + Limit int32 `json:"limit"` + // If true, returns only messages that are available locally without sending network requests + OnlyLocal bool `json:"only_local"` +} + // Returns messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id). For optimal performance the number of returned messages is chosen by the library. This is an offline request if only_local is true -// -// @param chatId Chat identifier -// @param fromMessageId Identifier of the message starting from which history must be fetched; use 0 to get results from the last message -// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages -// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached -// @param onlyLocal If true, returns only messages that are available locally without sending network requests -func (client *Client) GetChatHistory(chatId int64, fromMessageId int64, offset int32, limit int32, onlyLocal bool) (*Messages, error) { +func (client *Client) GetChatHistory(req *GetChatHistoryRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatHistory", }, Data: map[string]interface{}{ - "chat_id": chatId, - "from_message_id": fromMessageId, - "offset": offset, - "limit": limit, - "only_local": onlyLocal, + "chat_id": req.ChatId, + "from_message_id": req.FromMessageId, + "offset": req.Offset, + "limit": req.Limit, + "only_local": req.OnlyLocal, }, }) if err != nil { @@ -1258,18 +1406,22 @@ func (client *Client) GetChatHistory(chatId int64, fromMessageId int64, offset i return UnmarshalMessages(result.Data) } +type DeleteChatHistoryRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Pass true if the chat should be removed from the chats list + RemoveFromChatList bool `json:"remove_from_chat_list"` +} + // Deletes all messages in the chat only for the user. Cannot be used in channels and public supergroups -// -// @param chatId Chat identifier -// @param removeFromChatList Pass true if the chat should be removed from the chats list -func (client *Client) DeleteChatHistory(chatId int64, removeFromChatList bool) (*Ok, error) { +func (client *Client) DeleteChatHistory(req *DeleteChatHistoryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteChatHistory", }, Data: map[string]interface{}{ - "chat_id": chatId, - "remove_from_chat_list": removeFromChatList, + "chat_id": req.ChatId, + "remove_from_chat_list": req.RemoveFromChatList, }, }) if err != nil { @@ -1283,28 +1435,37 @@ func (client *Client) DeleteChatHistory(chatId int64, removeFromChatList bool) ( return UnmarshalOk(result.Data) } +type SearchChatMessagesRequest struct { + // Identifier of the chat in which to search messages + ChatId int64 `json:"chat_id"` + // Query to search for + Query string `json:"query"` + // If not 0, only messages sent by the specified user will be returned. Not supported in secret chats + SenderUserId int32 `json:"sender_user_id"` + // Identifier of the message starting from which history must be fetched; use 0 to get results from the last message + FromMessageId int64 `json:"from_message_id"` + // Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages + Offset int32 `json:"offset"` + // The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached + Limit int32 `json:"limit"` + // Filter for message content in the search results + Filter SearchMessagesFilter `json:"filter"` +} + // Searches for messages with given words in the chat. Returns the results in reverse chronological order, i.e. in order of decreasing message_id. Cannot be used in secret chats with a non-empty query (searchSecretMessages should be used instead), or without an enabled message database. For optimal performance the number of returned messages is chosen by the library -// -// @param chatId Identifier of the chat in which to search messages -// @param query Query to search for -// @param senderUserId If not 0, only messages sent by the specified user will be returned. Not supported in secret chats -// @param fromMessageId Identifier of the message starting from which history must be fetched; use 0 to get results from the last message -// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages -// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached -// @param filter Filter for message content in the search results -func (client *Client) SearchChatMessages(chatId int64, query string, senderUserId int32, fromMessageId int64, offset int32, limit int32, filter SearchMessagesFilter) (*Messages, error) { +func (client *Client) SearchChatMessages(req *SearchChatMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchChatMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "query": query, - "sender_user_id": senderUserId, - "from_message_id": fromMessageId, - "offset": offset, - "limit": limit, - "filter": filter, + "chat_id": req.ChatId, + "query": req.Query, + "sender_user_id": req.SenderUserId, + "from_message_id": req.FromMessageId, + "offset": req.Offset, + "limit": req.Limit, + "filter": req.Filter, }, }) if err != nil { @@ -1318,24 +1479,31 @@ func (client *Client) SearchChatMessages(chatId int64, query string, senderUserI return UnmarshalMessages(result.Data) } +type SearchMessagesRequest struct { + // Query to search for + Query string `json:"query"` + // The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message + OffsetDate int32 `json:"offset_date"` + // The chat identifier of the last found message, or 0 for the first request + OffsetChatId int64 `json:"offset_chat_id"` + // The message identifier of the last found message, or 0 for the first request + OffsetMessageId int64 `json:"offset_message_id"` + // The maximum number of messages to be returned, up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached + Limit int32 `json:"limit"` +} + // Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). For optimal performance the number of returned messages is chosen by the library -// -// @param query Query to search for -// @param offsetDate The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message -// @param offsetChatId The chat identifier of the last found message, or 0 for the first request -// @param offsetMessageId The message identifier of the last found message, or 0 for the first request -// @param limit The maximum number of messages to be returned, up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached -func (client *Client) SearchMessages(query string, offsetDate int32, offsetChatId int64, offsetMessageId int64, limit int32) (*Messages, error) { +func (client *Client) SearchMessages(req *SearchMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchMessages", }, Data: map[string]interface{}{ - "query": query, - "offset_date": offsetDate, - "offset_chat_id": offsetChatId, - "offset_message_id": offsetMessageId, - "limit": limit, + "query": req.Query, + "offset_date": req.OffsetDate, + "offset_chat_id": req.OffsetChatId, + "offset_message_id": req.OffsetMessageId, + "limit": req.Limit, }, }) if err != nil { @@ -1349,24 +1517,31 @@ func (client *Client) SearchMessages(query string, offsetDate int32, offsetChatI return UnmarshalMessages(result.Data) } +type SearchSecretMessagesRequest struct { + // Identifier of the chat in which to search. Specify 0 to search in all secret chats + ChatId int64 `json:"chat_id"` + // Query to search for. If empty, searchChatMessages should be used instead + Query string `json:"query"` + // The identifier from the result of a previous request, use 0 to get results from the last message + FromSearchId JsonInt64 `json:"from_search_id"` + // Maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached + Limit int32 `json:"limit"` + // A filter for the content of messages in the search results + Filter SearchMessagesFilter `json:"filter"` +} + // Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance the number of returned messages is chosen by the library -// -// @param chatId Identifier of the chat in which to search. Specify 0 to search in all secret chats -// @param query Query to search for. If empty, searchChatMessages should be used instead -// @param fromSearchId The identifier from the result of a previous request, use 0 to get results from the last message -// @param limit Maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached -// @param filter A filter for the content of messages in the search results -func (client *Client) SearchSecretMessages(chatId int64, query string, fromSearchId JsonInt64, limit int32, filter SearchMessagesFilter) (*FoundMessages, error) { +func (client *Client) SearchSecretMessages(req *SearchSecretMessagesRequest) (*FoundMessages, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchSecretMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "query": query, - "from_search_id": fromSearchId, - "limit": limit, - "filter": filter, + "chat_id": req.ChatId, + "query": req.Query, + "from_search_id": req.FromSearchId, + "limit": req.Limit, + "filter": req.Filter, }, }) if err != nil { @@ -1380,20 +1555,25 @@ func (client *Client) SearchSecretMessages(chatId int64, query string, fromSearc return UnmarshalFoundMessages(result.Data) } +type SearchCallMessagesRequest struct { + // Identifier of the message from which to search; use 0 to get results from the last message + FromMessageId int64 `json:"from_message_id"` + // The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached + Limit int32 `json:"limit"` + // If true, returns only messages with missed calls + OnlyMissed bool `json:"only_missed"` +} + // Searches for call messages. Returns the results in reverse chronological order (i. e., in order of decreasing message_id). For optimal performance the number of returned messages is chosen by the library -// -// @param fromMessageId Identifier of the message from which to search; use 0 to get results from the last message -// @param limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached -// @param onlyMissed If true, returns only messages with missed calls -func (client *Client) SearchCallMessages(fromMessageId int64, limit int32, onlyMissed bool) (*Messages, error) { +func (client *Client) SearchCallMessages(req *SearchCallMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchCallMessages", }, Data: map[string]interface{}{ - "from_message_id": fromMessageId, - "limit": limit, - "only_missed": onlyMissed, + "from_message_id": req.FromMessageId, + "limit": req.Limit, + "only_missed": req.OnlyMissed, }, }) if err != nil { @@ -1407,18 +1587,22 @@ func (client *Client) SearchCallMessages(fromMessageId int64, limit int32, onlyM return UnmarshalMessages(result.Data) } +type SearchChatRecentLocationMessagesRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Maximum number of messages to be returned + Limit int32 `json:"limit"` +} + // Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user -// -// @param chatId Chat identifier -// @param limit Maximum number of messages to be returned -func (client *Client) SearchChatRecentLocationMessages(chatId int64, limit int32) (*Messages, error) { +func (client *Client) SearchChatRecentLocationMessages(req *SearchChatRecentLocationMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchChatRecentLocationMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "limit": limit, + "chat_id": req.ChatId, + "limit": req.Limit, }, }) if err != nil { @@ -1451,18 +1635,22 @@ func (client *Client) GetActiveLiveLocationMessages() (*Messages, error) { return UnmarshalMessages(result.Data) } +type GetChatMessageByDateRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Point in time (Unix timestamp) relative to which to search for messages + Date int32 `json:"date"` +} + // Returns the last message sent in a chat no later than the specified date -// -// @param chatId Chat identifier -// @param date Point in time (Unix timestamp) relative to which to search for messages -func (client *Client) GetChatMessageByDate(chatId int64, date int32) (*Message, error) { +func (client *Client) GetChatMessageByDate(req *GetChatMessageByDateRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatMessageByDate", }, Data: map[string]interface{}{ - "chat_id": chatId, - "date": date, + "chat_id": req.ChatId, + "date": req.Date, }, }) if err != nil { @@ -1476,20 +1664,25 @@ func (client *Client) GetChatMessageByDate(chatId int64, date int32) (*Message, return UnmarshalMessage(result.Data) } +type GetChatMessageCountRequest struct { + // Identifier of the chat in which to count messages + ChatId int64 `json:"chat_id"` + // Filter for message content; searchMessagesFilterEmpty is unsupported in this function + Filter SearchMessagesFilter `json:"filter"` + // If true, returns count that is available locally without sending network requests, returning -1 if the number of messages is unknown + ReturnLocal bool `json:"return_local"` +} + // Returns approximate number of messages of the specified type in the chat -// -// @param chatId Identifier of the chat in which to count messages -// @param filter Filter for message content; searchMessagesFilterEmpty is unsupported in this function -// @param returnLocal If true, returns count that is available locally without sending network requests, returning -1 if the number of messages is unknown -func (client *Client) GetChatMessageCount(chatId int64, filter SearchMessagesFilter, returnLocal bool) (*Count, error) { +func (client *Client) GetChatMessageCount(req *GetChatMessageCountRequest) (*Count, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatMessageCount", }, Data: map[string]interface{}{ - "chat_id": chatId, - "filter": filter, - "return_local": returnLocal, + "chat_id": req.ChatId, + "filter": req.Filter, + "return_local": req.ReturnLocal, }, }) if err != nil { @@ -1503,20 +1696,25 @@ func (client *Client) GetChatMessageCount(chatId int64, filter SearchMessagesFil return UnmarshalCount(result.Data) } +type GetPublicMessageLinkRequest struct { + // Identifier of the chat to which the message belongs + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // Pass true if a link for a whole media album should be returned + ForAlbum bool `json:"for_album"` +} + // Returns a public HTTPS link to a message. Available only for messages in public supergroups and channels -// -// @param chatId Identifier of the chat to which the message belongs -// @param messageId Identifier of the message -// @param forAlbum Pass true if a link for a whole media album should be returned -func (client *Client) GetPublicMessageLink(chatId int64, messageId int64, forAlbum bool) (*PublicMessageLink, error) { +func (client *Client) GetPublicMessageLink(req *GetPublicMessageLinkRequest) (*PublicMessageLink, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPublicMessageLink", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "for_album": forAlbum, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "for_album": req.ForAlbum, }, }) if err != nil { @@ -1530,26 +1728,34 @@ func (client *Client) GetPublicMessageLink(chatId int64, messageId int64, forAlb return UnmarshalPublicMessageLink(result.Data) } +type SendMessageRequest struct { + // Target chat + ChatId int64 `json:"chat_id"` + // Identifier of the message to reply to or 0 + ReplyToMessageId int64 `json:"reply_to_message_id"` + // Pass true to disable notification for the message. Not supported in secret chats + DisableNotification bool `json:"disable_notification"` + // Pass true if the message is sent from the background + FromBackground bool `json:"from_background"` + // Markup for replying to the message; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // The content of the message to be sent + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Sends a message. Returns the sent message -// -// @param chatId Target chat -// @param replyToMessageId Identifier of the message to reply to or 0 -// @param disableNotification Pass true to disable notification for the message. Not supported in secret chats -// @param fromBackground Pass true if the message is sent from the background -// @param replyMarkup Markup for replying to the message; for bots only -// @param inputMessageContent The content of the message to be sent -func (client *Client) SendMessage(chatId int64, replyToMessageId int64, disableNotification bool, fromBackground bool, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) { +func (client *Client) SendMessage(req *SendMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "reply_to_message_id": replyToMessageId, - "disable_notification": disableNotification, - "from_background": fromBackground, - "reply_markup": replyMarkup, - "input_message_content": inputMessageContent, + "chat_id": req.ChatId, + "reply_to_message_id": req.ReplyToMessageId, + "disable_notification": req.DisableNotification, + "from_background": req.FromBackground, + "reply_markup": req.ReplyMarkup, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -1563,24 +1769,31 @@ func (client *Client) SendMessage(chatId int64, replyToMessageId int64, disableN return UnmarshalMessage(result.Data) } +type SendMessageAlbumRequest struct { + // Target chat + ChatId int64 `json:"chat_id"` + // Identifier of a message to reply to or 0 + ReplyToMessageId int64 `json:"reply_to_message_id"` + // Pass true to disable notification for the messages. Not supported in secret chats + DisableNotification bool `json:"disable_notification"` + // Pass true if the messages are sent from the background + FromBackground bool `json:"from_background"` + // Contents of messages to be sent + InputMessageContents []InputMessageContent `json:"input_message_contents"` +} + // Sends messages grouped together into an album. Currently only photo and video messages can be grouped into an album. Returns sent messages -// -// @param chatId Target chat -// @param replyToMessageId Identifier of a message to reply to or 0 -// @param disableNotification Pass true to disable notification for the messages. Not supported in secret chats -// @param fromBackground Pass true if the messages are sent from the background -// @param inputMessageContents Contents of messages to be sent -func (client *Client) SendMessageAlbum(chatId int64, replyToMessageId int64, disableNotification bool, fromBackground bool, inputMessageContents []InputMessageContent) (*Messages, error) { +func (client *Client) SendMessageAlbum(req *SendMessageAlbumRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendMessageAlbum", }, Data: map[string]interface{}{ - "chat_id": chatId, - "reply_to_message_id": replyToMessageId, - "disable_notification": disableNotification, - "from_background": fromBackground, - "input_message_contents": inputMessageContents, + "chat_id": req.ChatId, + "reply_to_message_id": req.ReplyToMessageId, + "disable_notification": req.DisableNotification, + "from_background": req.FromBackground, + "input_message_contents": req.InputMessageContents, }, }) if err != nil { @@ -1594,20 +1807,25 @@ func (client *Client) SendMessageAlbum(chatId int64, replyToMessageId int64, dis return UnmarshalMessages(result.Data) } +type SendBotStartMessageRequest struct { + // Identifier of the bot + BotUserId int32 `json:"bot_user_id"` + // Identifier of the target chat + ChatId int64 `json:"chat_id"` + // A hidden parameter sent to the bot for deep linking purposes (https://api.telegram.org/bots#deep-linking) + Parameter string `json:"parameter"` +} + // Invites a bot to a chat (if it is not yet a member) and sends it the /start command. Bots can't be invited to a private chat other than the chat with the bot. Bots can't be invited to channels (although they can be added as admins) and secret chats. Returns the sent message -// -// @param botUserId Identifier of the bot -// @param chatId Identifier of the target chat -// @param parameter A hidden parameter sent to the bot for deep linking purposes (https://api.telegram.org/bots#deep-linking) -func (client *Client) SendBotStartMessage(botUserId int32, chatId int64, parameter string) (*Message, error) { +func (client *Client) SendBotStartMessage(req *SendBotStartMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendBotStartMessage", }, Data: map[string]interface{}{ - "bot_user_id": botUserId, - "chat_id": chatId, - "parameter": parameter, + "bot_user_id": req.BotUserId, + "chat_id": req.ChatId, + "parameter": req.Parameter, }, }) if err != nil { @@ -1621,26 +1839,34 @@ func (client *Client) SendBotStartMessage(botUserId int32, chatId int64, paramet return UnmarshalMessage(result.Data) } +type SendInlineQueryResultMessageRequest struct { + // Target chat + ChatId int64 `json:"chat_id"` + // Identifier of a message to reply to or 0 + ReplyToMessageId int64 `json:"reply_to_message_id"` + // Pass true to disable notification for the message. Not supported in secret chats + DisableNotification bool `json:"disable_notification"` + // Pass true if the message is sent from background + FromBackground bool `json:"from_background"` + // Identifier of the inline query + QueryId JsonInt64 `json:"query_id"` + // Identifier of the inline result + ResultId string `json:"result_id"` +} + // Sends the result of an inline query as a message. Returns the sent message. Always clears a chat draft message -// -// @param chatId Target chat -// @param replyToMessageId Identifier of a message to reply to or 0 -// @param disableNotification Pass true to disable notification for the message. Not supported in secret chats -// @param fromBackground Pass true if the message is sent from background -// @param queryId Identifier of the inline query -// @param resultId Identifier of the inline result -func (client *Client) SendInlineQueryResultMessage(chatId int64, replyToMessageId int64, disableNotification bool, fromBackground bool, queryId JsonInt64, resultId string) (*Message, error) { +func (client *Client) SendInlineQueryResultMessage(req *SendInlineQueryResultMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendInlineQueryResultMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "reply_to_message_id": replyToMessageId, - "disable_notification": disableNotification, - "from_background": fromBackground, - "query_id": queryId, - "result_id": resultId, + "chat_id": req.ChatId, + "reply_to_message_id": req.ReplyToMessageId, + "disable_notification": req.DisableNotification, + "from_background": req.FromBackground, + "query_id": req.QueryId, + "result_id": req.ResultId, }, }) if err != nil { @@ -1654,26 +1880,34 @@ func (client *Client) SendInlineQueryResultMessage(chatId int64, replyToMessageI return UnmarshalMessage(result.Data) } +type ForwardMessagesRequest struct { + // Identifier of the chat to which to forward messages + ChatId int64 `json:"chat_id"` + // Identifier of the chat from which to forward messages + FromChatId int64 `json:"from_chat_id"` + // Identifiers of the messages to forward + MessageIds []int64 `json:"message_ids"` + // Pass true to disable notification for the message, doesn't work if messages are forwarded to a secret chat + DisableNotification bool `json:"disable_notification"` + // Pass true if the message is sent from the background + FromBackground bool `json:"from_background"` + // True, if the messages should be grouped into an album after forwarding. For this to work, no more than 10 messages may be forwarded, and all of them must be photo or video messages + AsAlbum bool `json:"as_album"` +} + // Forwards previously sent messages. Returns the forwarded messages in the same order as the message identifiers passed in message_ids. If a message can't be forwarded, null will be returned instead of the message -// -// @param chatId Identifier of the chat to which to forward messages -// @param fromChatId Identifier of the chat from which to forward messages -// @param messageIds Identifiers of the messages to forward -// @param disableNotification Pass true to disable notification for the message, doesn't work if messages are forwarded to a secret chat -// @param fromBackground Pass true if the message is sent from the background -// @param asAlbum True, if the messages should be grouped into an album after forwarding. For this to work, no more than 10 messages may be forwarded, and all of them must be photo or video messages -func (client *Client) ForwardMessages(chatId int64, fromChatId int64, messageIds []int64, disableNotification bool, fromBackground bool, asAlbum bool) (*Messages, error) { +func (client *Client) ForwardMessages(req *ForwardMessagesRequest) (*Messages, error) { result, err := client.Send(Request{ meta: meta{ Type: "forwardMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "from_chat_id": fromChatId, - "message_ids": messageIds, - "disable_notification": disableNotification, - "from_background": fromBackground, - "as_album": asAlbum, + "chat_id": req.ChatId, + "from_chat_id": req.FromChatId, + "message_ids": req.MessageIds, + "disable_notification": req.DisableNotification, + "from_background": req.FromBackground, + "as_album": req.AsAlbum, }, }) if err != nil { @@ -1687,18 +1921,22 @@ func (client *Client) ForwardMessages(chatId int64, fromChatId int64, messageIds return UnmarshalMessages(result.Data) } +type SendChatSetTtlMessageRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New TTL value, in seconds + Ttl int32 `json:"ttl"` +} + // Changes the current TTL setting (sets a new self-destruct timer) in a secret chat and sends the corresponding message -// -// @param chatId Chat identifier -// @param ttl New TTL value, in seconds -func (client *Client) SendChatSetTtlMessage(chatId int64, ttl int32) (*Message, error) { +func (client *Client) SendChatSetTtlMessage(req *SendChatSetTtlMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendChatSetTtlMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "ttl": ttl, + "chat_id": req.ChatId, + "ttl": req.Ttl, }, }) if err != nil { @@ -1712,16 +1950,19 @@ func (client *Client) SendChatSetTtlMessage(chatId int64, ttl int32) (*Message, return UnmarshalMessage(result.Data) } +type SendChatScreenshotTakenNotificationRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Sends a notification about a screenshot taken in a chat. Supported only in private and secret chats -// -// @param chatId Chat identifier -func (client *Client) SendChatScreenshotTakenNotification(chatId int64) (*Ok, error) { +func (client *Client) SendChatScreenshotTakenNotification(req *SendChatScreenshotTakenNotificationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendChatScreenshotTakenNotification", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -1735,24 +1976,31 @@ func (client *Client) SendChatScreenshotTakenNotification(chatId int64) (*Ok, er return UnmarshalOk(result.Data) } +type AddLocalMessageRequest struct { + // Target chat + ChatId int64 `json:"chat_id"` + // Identifier of the user who will be shown as the sender of the message; may be 0 for channel posts + SenderUserId int32 `json:"sender_user_id"` + // Identifier of the message to reply to or 0 + ReplyToMessageId int64 `json:"reply_to_message_id"` + // Pass true to disable notification for the message + DisableNotification bool `json:"disable_notification"` + // The content of the message to be added + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message -// -// @param chatId Target chat -// @param senderUserId Identifier of the user who will be shown as the sender of the message; may be 0 for channel posts -// @param replyToMessageId Identifier of the message to reply to or 0 -// @param disableNotification Pass true to disable notification for the message -// @param inputMessageContent The content of the message to be added -func (client *Client) AddLocalMessage(chatId int64, senderUserId int32, replyToMessageId int64, disableNotification bool, inputMessageContent InputMessageContent) (*Message, error) { +func (client *Client) AddLocalMessage(req *AddLocalMessageRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "addLocalMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "sender_user_id": senderUserId, - "reply_to_message_id": replyToMessageId, - "disable_notification": disableNotification, - "input_message_content": inputMessageContent, + "chat_id": req.ChatId, + "sender_user_id": req.SenderUserId, + "reply_to_message_id": req.ReplyToMessageId, + "disable_notification": req.DisableNotification, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -1766,20 +2014,25 @@ func (client *Client) AddLocalMessage(chatId int64, senderUserId int32, replyToM return UnmarshalMessage(result.Data) } +type DeleteMessagesRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Identifiers of the messages to be deleted + MessageIds []int64 `json:"message_ids"` + // Pass true to try to delete outgoing messages for all chat members (may fail if messages are too old). Always true for supergroups, channels and secret chats + Revoke bool `json:"revoke"` +} + // Deletes messages -// -// @param chatId Chat identifier -// @param messageIds Identifiers of the messages to be deleted -// @param revoke Pass true to try to delete outgoing messages for all chat members (may fail if messages are too old). Always true for supergroups, channels and secret chats -func (client *Client) DeleteMessages(chatId int64, messageIds []int64, revoke bool) (*Ok, error) { +func (client *Client) DeleteMessages(req *DeleteMessagesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_ids": messageIds, - "revoke": revoke, + "chat_id": req.ChatId, + "message_ids": req.MessageIds, + "revoke": req.Revoke, }, }) if err != nil { @@ -1793,18 +2046,22 @@ func (client *Client) DeleteMessages(chatId int64, messageIds []int64, revoke bo return UnmarshalOk(result.Data) } +type DeleteChatMessagesFromUserRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // User identifier + UserId int32 `json:"user_id"` +} + // Deletes all messages sent by the specified user to a chat. Supported only in supergroups; requires can_delete_messages administrator privileges -// -// @param chatId Chat identifier -// @param userId User identifier -func (client *Client) DeleteChatMessagesFromUser(chatId int64, userId int32) (*Ok, error) { +func (client *Client) DeleteChatMessagesFromUser(req *DeleteChatMessagesFromUserRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteChatMessagesFromUser", }, Data: map[string]interface{}{ - "chat_id": chatId, - "user_id": userId, + "chat_id": req.ChatId, + "user_id": req.UserId, }, }) if err != nil { @@ -1818,22 +2075,28 @@ func (client *Client) DeleteChatMessagesFromUser(chatId int64, userId int32) (*O return UnmarshalOk(result.Data) } +type EditMessageTextRequest struct { + // The chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // The new message reply markup; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New text content of the message. Should be of type InputMessageText + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Edits the text of a message (or a text of a game message). Returns the edited message after the edit is completed on the server side -// -// @param chatId The chat the message belongs to -// @param messageId Identifier of the message -// @param replyMarkup The new message reply markup; for bots only -// @param inputMessageContent New text content of the message. Should be of type InputMessageText -func (client *Client) EditMessageText(chatId int64, messageId int64, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) { +func (client *Client) EditMessageText(req *EditMessageTextRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "editMessageText", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "reply_markup": replyMarkup, - "input_message_content": inputMessageContent, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "reply_markup": req.ReplyMarkup, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -1847,22 +2110,28 @@ func (client *Client) EditMessageText(chatId int64, messageId int64, replyMarkup return UnmarshalMessage(result.Data) } +type EditMessageLiveLocationRequest struct { + // The chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // The new message reply markup; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New location content of the message; may be null. Pass null to stop sharing the live location + Location *Location `json:"location"` +} + // Edits the message content of a live location. Messages can be edited for a limited period of time specified in the live location. Returns the edited message after the edit is completed on the server side -// -// @param chatId The chat the message belongs to -// @param messageId Identifier of the message -// @param replyMarkup The new message reply markup; for bots only -// @param location New location content of the message; may be null. Pass null to stop sharing the live location -func (client *Client) EditMessageLiveLocation(chatId int64, messageId int64, replyMarkup ReplyMarkup, location *Location) (*Message, error) { +func (client *Client) EditMessageLiveLocation(req *EditMessageLiveLocationRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "editMessageLiveLocation", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "reply_markup": replyMarkup, - "location": location, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "reply_markup": req.ReplyMarkup, + "location": req.Location, }, }) if err != nil { @@ -1876,22 +2145,28 @@ func (client *Client) EditMessageLiveLocation(chatId int64, messageId int64, rep return UnmarshalMessage(result.Data) } +type EditMessageMediaRequest struct { + // The chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // The new message reply markup; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Edits the content of a message with an animation, an audio, a document, a photo or a video. The media in the message can't be replaced if the message was set to self-destruct. Media can't be replaced by self-destructing media. Media in an album can be edited only to contain a photo or a video. Returns the edited message after the edit is completed on the server side -// -// @param chatId The chat the message belongs to -// @param messageId Identifier of the message -// @param replyMarkup The new message reply markup; for bots only -// @param inputMessageContent New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo -func (client *Client) EditMessageMedia(chatId int64, messageId int64, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) { +func (client *Client) EditMessageMedia(req *EditMessageMediaRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "editMessageMedia", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "reply_markup": replyMarkup, - "input_message_content": inputMessageContent, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "reply_markup": req.ReplyMarkup, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -1905,22 +2180,28 @@ func (client *Client) EditMessageMedia(chatId int64, messageId int64, replyMarku return UnmarshalMessage(result.Data) } +type EditMessageCaptionRequest struct { + // The chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // The new message reply markup; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New message content caption; 0-GetOption("message_caption_length_max") characters + Caption *FormattedText `json:"caption"` +} + // Edits the message content caption. Returns the edited message after the edit is completed on the server side -// -// @param chatId The chat the message belongs to -// @param messageId Identifier of the message -// @param replyMarkup The new message reply markup; for bots only -// @param caption New message content caption; 0-GetOption("message_caption_length_max") characters -func (client *Client) EditMessageCaption(chatId int64, messageId int64, replyMarkup ReplyMarkup, caption *FormattedText) (*Message, error) { +func (client *Client) EditMessageCaption(req *EditMessageCaptionRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "editMessageCaption", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "reply_markup": replyMarkup, - "caption": caption, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "reply_markup": req.ReplyMarkup, + "caption": req.Caption, }, }) if err != nil { @@ -1934,20 +2215,25 @@ func (client *Client) EditMessageCaption(chatId int64, messageId int64, replyMar return UnmarshalMessage(result.Data) } +type EditMessageReplyMarkupRequest struct { + // The chat the message belongs to + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // The new message reply markup + ReplyMarkup ReplyMarkup `json:"reply_markup"` +} + // Edits the message reply markup; for bots only. Returns the edited message after the edit is completed on the server side -// -// @param chatId The chat the message belongs to -// @param messageId Identifier of the message -// @param replyMarkup The new message reply markup -func (client *Client) EditMessageReplyMarkup(chatId int64, messageId int64, replyMarkup ReplyMarkup) (*Message, error) { +func (client *Client) EditMessageReplyMarkup(req *EditMessageReplyMarkupRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "editMessageReplyMarkup", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "reply_markup": replyMarkup, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "reply_markup": req.ReplyMarkup, }, }) if err != nil { @@ -1961,20 +2247,25 @@ func (client *Client) EditMessageReplyMarkup(chatId int64, messageId int64, repl return UnmarshalMessage(result.Data) } +type EditInlineMessageTextRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // The new message reply markup + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New text content of the message. Should be of type InputMessageText + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Edits the text of an inline text or game message sent via a bot; for bots only -// -// @param inlineMessageId Inline message identifier -// @param replyMarkup The new message reply markup -// @param inputMessageContent New text content of the message. Should be of type InputMessageText -func (client *Client) EditInlineMessageText(inlineMessageId string, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Ok, error) { +func (client *Client) EditInlineMessageText(req *EditInlineMessageTextRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editInlineMessageText", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "reply_markup": replyMarkup, - "input_message_content": inputMessageContent, + "inline_message_id": req.InlineMessageId, + "reply_markup": req.ReplyMarkup, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -1988,20 +2279,25 @@ func (client *Client) EditInlineMessageText(inlineMessageId string, replyMarkup return UnmarshalOk(result.Data) } +type EditInlineMessageLiveLocationRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // The new message reply markup + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New location content of the message; may be null. Pass null to stop sharing the live location + Location *Location `json:"location"` +} + // Edits the content of a live location in an inline message sent via a bot; for bots only -// -// @param inlineMessageId Inline message identifier -// @param replyMarkup The new message reply markup -// @param location New location content of the message; may be null. Pass null to stop sharing the live location -func (client *Client) EditInlineMessageLiveLocation(inlineMessageId string, replyMarkup ReplyMarkup, location *Location) (*Ok, error) { +func (client *Client) EditInlineMessageLiveLocation(req *EditInlineMessageLiveLocationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editInlineMessageLiveLocation", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "reply_markup": replyMarkup, - "location": location, + "inline_message_id": req.InlineMessageId, + "reply_markup": req.ReplyMarkup, + "location": req.Location, }, }) if err != nil { @@ -2015,20 +2311,25 @@ func (client *Client) EditInlineMessageLiveLocation(inlineMessageId string, repl return UnmarshalOk(result.Data) } +type EditInlineMessageMediaRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // The new message reply markup; for bots only + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo + InputMessageContent InputMessageContent `json:"input_message_content"` +} + // Edits the content of a message with an animation, an audio, a document, a photo or a video in an inline message sent via a bot; for bots only -// -// @param inlineMessageId Inline message identifier -// @param replyMarkup The new message reply markup; for bots only -// @param inputMessageContent New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo -func (client *Client) EditInlineMessageMedia(inlineMessageId string, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Ok, error) { +func (client *Client) EditInlineMessageMedia(req *EditInlineMessageMediaRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editInlineMessageMedia", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "reply_markup": replyMarkup, - "input_message_content": inputMessageContent, + "inline_message_id": req.InlineMessageId, + "reply_markup": req.ReplyMarkup, + "input_message_content": req.InputMessageContent, }, }) if err != nil { @@ -2042,20 +2343,25 @@ func (client *Client) EditInlineMessageMedia(inlineMessageId string, replyMarkup return UnmarshalOk(result.Data) } +type EditInlineMessageCaptionRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // The new message reply markup + ReplyMarkup ReplyMarkup `json:"reply_markup"` + // New message content caption; 0-GetOption("message_caption_length_max") characters + Caption *FormattedText `json:"caption"` +} + // Edits the caption of an inline message sent via a bot; for bots only -// -// @param inlineMessageId Inline message identifier -// @param replyMarkup The new message reply markup -// @param caption New message content caption; 0-GetOption("message_caption_length_max") characters -func (client *Client) EditInlineMessageCaption(inlineMessageId string, replyMarkup ReplyMarkup, caption *FormattedText) (*Ok, error) { +func (client *Client) EditInlineMessageCaption(req *EditInlineMessageCaptionRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editInlineMessageCaption", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "reply_markup": replyMarkup, - "caption": caption, + "inline_message_id": req.InlineMessageId, + "reply_markup": req.ReplyMarkup, + "caption": req.Caption, }, }) if err != nil { @@ -2069,18 +2375,22 @@ func (client *Client) EditInlineMessageCaption(inlineMessageId string, replyMark return UnmarshalOk(result.Data) } +type EditInlineMessageReplyMarkupRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // The new message reply markup + ReplyMarkup ReplyMarkup `json:"reply_markup"` +} + // Edits the reply markup of an inline message sent via a bot; for bots only -// -// @param inlineMessageId Inline message identifier -// @param replyMarkup The new message reply markup -func (client *Client) EditInlineMessageReplyMarkup(inlineMessageId string, replyMarkup ReplyMarkup) (*Ok, error) { +func (client *Client) EditInlineMessageReplyMarkup(req *EditInlineMessageReplyMarkupRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editInlineMessageReplyMarkup", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "reply_markup": replyMarkup, + "inline_message_id": req.InlineMessageId, + "reply_markup": req.ReplyMarkup, }, }) if err != nil { @@ -2094,16 +2404,19 @@ func (client *Client) EditInlineMessageReplyMarkup(inlineMessageId string, reply return UnmarshalOk(result.Data) } +type GetTextEntitiesRequest struct { + // The text in which to look for entites + Text string `json:"text"` +} + // Returns all entities (mentions, hashtags, cashtags, bot commands, URLs, and email addresses) contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param text The text in which to look for entites -func (client *Client) GetTextEntities(text string) (*TextEntities, error) { +func (client *Client) GetTextEntities(req *GetTextEntitiesRequest) (*TextEntities, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "getTextEntities", }, Data: map[string]interface{}{ - "text": text, + "text": req.Text, }, }) if err != nil { @@ -2117,18 +2430,22 @@ func (client *Client) GetTextEntities(text string) (*TextEntities, error) { return UnmarshalTextEntities(result.Data) } +type ParseTextEntitiesRequest struct { + // The text which should be parsed + Text string `json:"text"` + // Text parse mode + ParseMode TextParseMode `json:"parse_mode"` +} + // Parses Bold, Italic, Code, Pre, PreCode and TextUrl entities contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param text The text which should be parsed -// @param parseMode Text parse mode -func (client *Client) ParseTextEntities(text string, parseMode TextParseMode) (*FormattedText, error) { +func (client *Client) ParseTextEntities(req *ParseTextEntitiesRequest) (*FormattedText, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "parseTextEntities", }, Data: map[string]interface{}{ - "text": text, - "parse_mode": parseMode, + "text": req.Text, + "parse_mode": req.ParseMode, }, }) if err != nil { @@ -2142,16 +2459,19 @@ func (client *Client) ParseTextEntities(text string, parseMode TextParseMode) (* return UnmarshalFormattedText(result.Data) } +type GetFileMimeTypeRequest struct { + // The name of the file or path to the file + FileName string `json:"file_name"` +} + // Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param fileName The name of the file or path to the file -func (client *Client) GetFileMimeType(fileName string) (*Text, error) { +func (client *Client) GetFileMimeType(req *GetFileMimeTypeRequest) (*Text, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "getFileMimeType", }, Data: map[string]interface{}{ - "file_name": fileName, + "file_name": req.FileName, }, }) if err != nil { @@ -2165,16 +2485,19 @@ func (client *Client) GetFileMimeType(fileName string) (*Text, error) { return UnmarshalText(result.Data) } +type GetFileExtensionRequest struct { + // The MIME type of the file + MimeType string `json:"mime_type"` +} + // Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param mimeType The MIME type of the file -func (client *Client) GetFileExtension(mimeType string) (*Text, error) { +func (client *Client) GetFileExtension(req *GetFileExtensionRequest) (*Text, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "getFileExtension", }, Data: map[string]interface{}{ - "mime_type": mimeType, + "mime_type": req.MimeType, }, }) if err != nil { @@ -2188,16 +2511,19 @@ func (client *Client) GetFileExtension(mimeType string) (*Text, error) { return UnmarshalText(result.Data) } +type CleanFileNameRequest struct { + // File name or path to the file + FileName string `json:"file_name"` +} + // Removes potentially dangerous characters from the name of a file. The encoding of the file name is supposed to be UTF-8. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param fileName File name or path to the file -func (client *Client) CleanFileName(fileName string) (*Text, error) { +func (client *Client) CleanFileName(req *CleanFileNameRequest) (*Text, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "cleanFileName", }, Data: map[string]interface{}{ - "file_name": fileName, + "file_name": req.FileName, }, }) if err != nil { @@ -2211,22 +2537,28 @@ func (client *Client) CleanFileName(fileName string) (*Text, error) { return UnmarshalText(result.Data) } +type GetLanguagePackStringRequest struct { + // Path to the language pack database in which strings are stored + LanguagePackDatabasePath string `json:"language_pack_database_path"` + // Localization target to which the language pack belongs + LocalizationTarget string `json:"localization_target"` + // Language pack identifier + LanguagePackId string `json:"language_pack_id"` + // Language pack key of the string to be returned + Key string `json:"key"` +} + // Returns a string stored in the local database from the specified localization target and language pack by its key. Returns a 404 error if the string is not found. This is an offline method. Can be called before authorization. Can be called synchronously -// -// @param languagePackDatabasePath Path to the language pack database in which strings are stored -// @param localizationTarget Localization target to which the language pack belongs -// @param languagePackId Language pack identifier -// @param key Language pack key of the string to be returned -func (client *Client) GetLanguagePackString(languagePackDatabasePath string, localizationTarget string, languagePackId string, key string) (LanguagePackStringValue, error) { +func (client *Client) GetLanguagePackString(req *GetLanguagePackStringRequest) (LanguagePackStringValue, error) { result, err := client.jsonClient.Execute(Request{ meta: meta{ Type: "getLanguagePackString", }, Data: map[string]interface{}{ - "language_pack_database_path": languagePackDatabasePath, - "localization_target": localizationTarget, - "language_pack_id": languagePackId, - "key": key, + "language_pack_database_path": req.LanguagePackDatabasePath, + "localization_target": req.LocalizationTarget, + "language_pack_id": req.LanguagePackId, + "key": req.Key, }, }) if err != nil { @@ -2252,24 +2584,31 @@ func (client *Client) GetLanguagePackString(languagePackDatabasePath string, loc } } +type GetInlineQueryResultsRequest struct { + // The identifier of the target bot + BotUserId int32 `json:"bot_user_id"` + // Identifier of the chat, where the query was sent + ChatId int64 `json:"chat_id"` + // Location of the user, only if needed + UserLocation *Location `json:"user_location"` + // Text of the query + Query string `json:"query"` + // Offset of the first entry to return + Offset string `json:"offset"` +} + // Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires -// -// @param botUserId The identifier of the target bot -// @param chatId Identifier of the chat, where the query was sent -// @param userLocation Location of the user, only if needed -// @param query Text of the query -// @param offset Offset of the first entry to return -func (client *Client) GetInlineQueryResults(botUserId int32, chatId int64, userLocation *Location, query string, offset string) (*InlineQueryResults, error) { +func (client *Client) GetInlineQueryResults(req *GetInlineQueryResultsRequest) (*InlineQueryResults, error) { result, err := client.Send(Request{ meta: meta{ Type: "getInlineQueryResults", }, Data: map[string]interface{}{ - "bot_user_id": botUserId, - "chat_id": chatId, - "user_location": userLocation, - "query": query, - "offset": offset, + "bot_user_id": req.BotUserId, + "chat_id": req.ChatId, + "user_location": req.UserLocation, + "query": req.Query, + "offset": req.Offset, }, }) if err != nil { @@ -2283,28 +2622,37 @@ func (client *Client) GetInlineQueryResults(botUserId int32, chatId int64, userL return UnmarshalInlineQueryResults(result.Data) } +type AnswerInlineQueryRequest struct { + // Identifier of the inline query + InlineQueryId JsonInt64 `json:"inline_query_id"` + // True, if the result of the query can be cached for the specified user + IsPersonal bool `json:"is_personal"` + // The results of the query + Results []InputInlineQueryResult `json:"results"` + // Allowed time to cache the results of the query, in seconds + CacheTime int32 `json:"cache_time"` + // Offset for the next inline query; pass an empty string if there are no more results + NextOffset string `json:"next_offset"` + // If non-empty, this text should be shown on the button that opens a private chat with the bot and sends a start message to the bot with the parameter switch_pm_parameter + SwitchPmText string `json:"switch_pm_text"` + // The parameter for the bot start message + SwitchPmParameter string `json:"switch_pm_parameter"` +} + // Sets the result of an inline query; for bots only -// -// @param inlineQueryId Identifier of the inline query -// @param isPersonal True, if the result of the query can be cached for the specified user -// @param results The results of the query -// @param cacheTime Allowed time to cache the results of the query, in seconds -// @param nextOffset Offset for the next inline query; pass an empty string if there are no more results -// @param switchPmText If non-empty, this text should be shown on the button that opens a private chat with the bot and sends a start message to the bot with the parameter switch_pm_parameter -// @param switchPmParameter The parameter for the bot start message -func (client *Client) AnswerInlineQuery(inlineQueryId JsonInt64, isPersonal bool, results []InputInlineQueryResult, cacheTime int32, nextOffset string, switchPmText string, switchPmParameter string) (*Ok, error) { +func (client *Client) AnswerInlineQuery(req *AnswerInlineQueryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "answerInlineQuery", }, Data: map[string]interface{}{ - "inline_query_id": inlineQueryId, - "is_personal": isPersonal, - "results": results, - "cache_time": cacheTime, - "next_offset": nextOffset, - "switch_pm_text": switchPmText, - "switch_pm_parameter": switchPmParameter, + "inline_query_id": req.InlineQueryId, + "is_personal": req.IsPersonal, + "results": req.Results, + "cache_time": req.CacheTime, + "next_offset": req.NextOffset, + "switch_pm_text": req.SwitchPmText, + "switch_pm_parameter": req.SwitchPmParameter, }, }) if err != nil { @@ -2318,20 +2666,25 @@ func (client *Client) AnswerInlineQuery(inlineQueryId JsonInt64, isPersonal bool return UnmarshalOk(result.Data) } +type GetCallbackQueryAnswerRequest struct { + // Identifier of the chat with the message + ChatId int64 `json:"chat_id"` + // Identifier of the message from which the query originated + MessageId int64 `json:"message_id"` + // Query payload + Payload CallbackQueryPayload `json:"payload"` +} + // Sends a callback query to a bot and returns an answer. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires -// -// @param chatId Identifier of the chat with the message -// @param messageId Identifier of the message from which the query originated -// @param payload Query payload -func (client *Client) GetCallbackQueryAnswer(chatId int64, messageId int64, payload CallbackQueryPayload) (*CallbackQueryAnswer, error) { +func (client *Client) GetCallbackQueryAnswer(req *GetCallbackQueryAnswerRequest) (*CallbackQueryAnswer, error) { result, err := client.Send(Request{ meta: meta{ Type: "getCallbackQueryAnswer", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "payload": payload, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "payload": req.Payload, }, }) if err != nil { @@ -2345,24 +2698,31 @@ func (client *Client) GetCallbackQueryAnswer(chatId int64, messageId int64, payl return UnmarshalCallbackQueryAnswer(result.Data) } +type AnswerCallbackQueryRequest struct { + // Identifier of the callback query + CallbackQueryId JsonInt64 `json:"callback_query_id"` + // Text of the answer + Text string `json:"text"` + // If true, an alert should be shown to the user instead of a toast notification + ShowAlert bool `json:"show_alert"` + // URL to be opened + Url string `json:"url"` + // Time during which the result of the query can be cached, in seconds + CacheTime int32 `json:"cache_time"` +} + // Sets the result of a callback query; for bots only -// -// @param callbackQueryId Identifier of the callback query -// @param text Text of the answer -// @param showAlert If true, an alert should be shown to the user instead of a toast notification -// @param url URL to be opened -// @param cacheTime Time during which the result of the query can be cached, in seconds -func (client *Client) AnswerCallbackQuery(callbackQueryId JsonInt64, text string, showAlert bool, url string, cacheTime int32) (*Ok, error) { +func (client *Client) AnswerCallbackQuery(req *AnswerCallbackQueryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "answerCallbackQuery", }, Data: map[string]interface{}{ - "callback_query_id": callbackQueryId, - "text": text, - "show_alert": showAlert, - "url": url, - "cache_time": cacheTime, + "callback_query_id": req.CallbackQueryId, + "text": req.Text, + "show_alert": req.ShowAlert, + "url": req.Url, + "cache_time": req.CacheTime, }, }) if err != nil { @@ -2376,20 +2736,25 @@ func (client *Client) AnswerCallbackQuery(callbackQueryId JsonInt64, text string return UnmarshalOk(result.Data) } +type AnswerShippingQueryRequest struct { + // Identifier of the shipping query + ShippingQueryId JsonInt64 `json:"shipping_query_id"` + // Available shipping options + ShippingOptions []*ShippingOption `json:"shipping_options"` + // An error message, empty on success + ErrorMessage string `json:"error_message"` +} + // Sets the result of a shipping query; for bots only -// -// @param shippingQueryId Identifier of the shipping query -// @param shippingOptions Available shipping options -// @param errorMessage An error message, empty on success -func (client *Client) AnswerShippingQuery(shippingQueryId JsonInt64, shippingOptions []*ShippingOption, errorMessage string) (*Ok, error) { +func (client *Client) AnswerShippingQuery(req *AnswerShippingQueryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "answerShippingQuery", }, Data: map[string]interface{}{ - "shipping_query_id": shippingQueryId, - "shipping_options": shippingOptions, - "error_message": errorMessage, + "shipping_query_id": req.ShippingQueryId, + "shipping_options": req.ShippingOptions, + "error_message": req.ErrorMessage, }, }) if err != nil { @@ -2403,18 +2768,22 @@ func (client *Client) AnswerShippingQuery(shippingQueryId JsonInt64, shippingOpt return UnmarshalOk(result.Data) } +type AnswerPreCheckoutQueryRequest struct { + // Identifier of the pre-checkout query + PreCheckoutQueryId JsonInt64 `json:"pre_checkout_query_id"` + // An error message, empty on success + ErrorMessage string `json:"error_message"` +} + // Sets the result of a pre-checkout query; for bots only -// -// @param preCheckoutQueryId Identifier of the pre-checkout query -// @param errorMessage An error message, empty on success -func (client *Client) AnswerPreCheckoutQuery(preCheckoutQueryId JsonInt64, errorMessage string) (*Ok, error) { +func (client *Client) AnswerPreCheckoutQuery(req *AnswerPreCheckoutQueryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "answerPreCheckoutQuery", }, Data: map[string]interface{}{ - "pre_checkout_query_id": preCheckoutQueryId, - "error_message": errorMessage, + "pre_checkout_query_id": req.PreCheckoutQueryId, + "error_message": req.ErrorMessage, }, }) if err != nil { @@ -2428,26 +2797,34 @@ func (client *Client) AnswerPreCheckoutQuery(preCheckoutQueryId JsonInt64, error return UnmarshalOk(result.Data) } +type SetGameScoreRequest struct { + // The chat to which the message with the game + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // True, if the message should be edited + EditMessage bool `json:"edit_message"` + // User identifier + UserId int32 `json:"user_id"` + // The new score + Score int32 `json:"score"` + // Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table + Force bool `json:"force"` +} + // Updates the game score of the specified user in the game; for bots only -// -// @param chatId The chat to which the message with the game -// @param messageId Identifier of the message -// @param editMessage True, if the message should be edited -// @param userId User identifier -// @param score The new score -// @param force Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table -func (client *Client) SetGameScore(chatId int64, messageId int64, editMessage bool, userId int32, score int32, force bool) (*Message, error) { +func (client *Client) SetGameScore(req *SetGameScoreRequest) (*Message, error) { result, err := client.Send(Request{ meta: meta{ Type: "setGameScore", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "edit_message": editMessage, - "user_id": userId, - "score": score, - "force": force, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "edit_message": req.EditMessage, + "user_id": req.UserId, + "score": req.Score, + "force": req.Force, }, }) if err != nil { @@ -2461,24 +2838,31 @@ func (client *Client) SetGameScore(chatId int64, messageId int64, editMessage bo return UnmarshalMessage(result.Data) } +type SetInlineGameScoreRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // True, if the message should be edited + EditMessage bool `json:"edit_message"` + // User identifier + UserId int32 `json:"user_id"` + // The new score + Score int32 `json:"score"` + // Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table + Force bool `json:"force"` +} + // Updates the game score of the specified user in a game; for bots only -// -// @param inlineMessageId Inline message identifier -// @param editMessage True, if the message should be edited -// @param userId User identifier -// @param score The new score -// @param force Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table -func (client *Client) SetInlineGameScore(inlineMessageId string, editMessage bool, userId int32, score int32, force bool) (*Ok, error) { +func (client *Client) SetInlineGameScore(req *SetInlineGameScoreRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setInlineGameScore", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "edit_message": editMessage, - "user_id": userId, - "score": score, - "force": force, + "inline_message_id": req.InlineMessageId, + "edit_message": req.EditMessage, + "user_id": req.UserId, + "score": req.Score, + "force": req.Force, }, }) if err != nil { @@ -2492,20 +2876,25 @@ func (client *Client) SetInlineGameScore(inlineMessageId string, editMessage boo return UnmarshalOk(result.Data) } +type GetGameHighScoresRequest struct { + // The chat that contains the message with the game + ChatId int64 `json:"chat_id"` + // Identifier of the message + MessageId int64 `json:"message_id"` + // User identifier + UserId int32 `json:"user_id"` +} + // Returns the high scores for a game and some part of the high score table in the range of the specified user; for bots only -// -// @param chatId The chat that contains the message with the game -// @param messageId Identifier of the message -// @param userId User identifier -func (client *Client) GetGameHighScores(chatId int64, messageId int64, userId int32) (*GameHighScores, error) { +func (client *Client) GetGameHighScores(req *GetGameHighScoresRequest) (*GameHighScores, error) { result, err := client.Send(Request{ meta: meta{ Type: "getGameHighScores", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "user_id": userId, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "user_id": req.UserId, }, }) if err != nil { @@ -2519,18 +2908,22 @@ func (client *Client) GetGameHighScores(chatId int64, messageId int64, userId in return UnmarshalGameHighScores(result.Data) } +type GetInlineGameHighScoresRequest struct { + // Inline message identifier + InlineMessageId string `json:"inline_message_id"` + // User identifier + UserId int32 `json:"user_id"` +} + // Returns game high scores and some part of the high score table in the range of the specified user; for bots only -// -// @param inlineMessageId Inline message identifier -// @param userId User identifier -func (client *Client) GetInlineGameHighScores(inlineMessageId string, userId int32) (*GameHighScores, error) { +func (client *Client) GetInlineGameHighScores(req *GetInlineGameHighScoresRequest) (*GameHighScores, error) { result, err := client.Send(Request{ meta: meta{ Type: "getInlineGameHighScores", }, Data: map[string]interface{}{ - "inline_message_id": inlineMessageId, - "user_id": userId, + "inline_message_id": req.InlineMessageId, + "user_id": req.UserId, }, }) if err != nil { @@ -2544,18 +2937,22 @@ func (client *Client) GetInlineGameHighScores(inlineMessageId string, userId int return UnmarshalGameHighScores(result.Data) } +type DeleteChatReplyMarkupRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // The message identifier of the used keyboard + MessageId int64 `json:"message_id"` +} + // Deletes the default reply markup from a chat. Must be called after a one-time keyboard or a ForceReply reply markup has been used. UpdateChatReplyMarkup will be sent if the reply markup will be changed -// -// @param chatId Chat identifier -// @param messageId The message identifier of the used keyboard -func (client *Client) DeleteChatReplyMarkup(chatId int64, messageId int64) (*Ok, error) { +func (client *Client) DeleteChatReplyMarkup(req *DeleteChatReplyMarkupRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteChatReplyMarkup", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -2569,18 +2966,22 @@ func (client *Client) DeleteChatReplyMarkup(chatId int64, messageId int64) (*Ok, return UnmarshalOk(result.Data) } +type SendChatActionRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // The action description + Action ChatAction `json:"action"` +} + // Sends a notification about user activity in a chat -// -// @param chatId Chat identifier -// @param action The action description -func (client *Client) SendChatAction(chatId int64, action ChatAction) (*Ok, error) { +func (client *Client) SendChatAction(req *SendChatActionRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendChatAction", }, Data: map[string]interface{}{ - "chat_id": chatId, - "action": action, + "chat_id": req.ChatId, + "action": req.Action, }, }) if err != nil { @@ -2594,16 +2995,19 @@ func (client *Client) SendChatAction(chatId int64, action ChatAction) (*Ok, erro return UnmarshalOk(result.Data) } +type OpenChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // This method should be called if the chat is opened by the user. Many useful activities depend on the chat being opened or closed (e.g., in supergroups and channels all updates are received only for opened chats) -// -// @param chatId Chat identifier -func (client *Client) OpenChat(chatId int64) (*Ok, error) { +func (client *Client) OpenChat(req *OpenChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "openChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -2617,16 +3021,19 @@ func (client *Client) OpenChat(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type CloseChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // This method should be called if the chat is closed by the user. Many useful activities depend on the chat being opened or closed -// -// @param chatId Chat identifier -func (client *Client) CloseChat(chatId int64) (*Ok, error) { +func (client *Client) CloseChat(req *CloseChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "closeChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -2640,20 +3047,25 @@ func (client *Client) CloseChat(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type ViewMessagesRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // The identifiers of the messages being viewed + MessageIds []int64 `json:"message_ids"` + // True, if messages in closed chats should be marked as read + ForceRead bool `json:"force_read"` +} + // This method should be called if messages are being viewed by the user. Many useful activities depend on whether the messages are currently being viewed or not (e.g., marking messages as read, incrementing a view counter, updating a view counter, removing deleted messages in supergroups and channels) -// -// @param chatId Chat identifier -// @param messageIds The identifiers of the messages being viewed -// @param forceRead True, if messages in closed chats should be marked as read -func (client *Client) ViewMessages(chatId int64, messageIds []int64, forceRead bool) (*Ok, error) { +func (client *Client) ViewMessages(req *ViewMessagesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "viewMessages", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_ids": messageIds, - "force_read": forceRead, + "chat_id": req.ChatId, + "message_ids": req.MessageIds, + "force_read": req.ForceRead, }, }) if err != nil { @@ -2667,18 +3079,22 @@ func (client *Client) ViewMessages(chatId int64, messageIds []int64, forceRead b return UnmarshalOk(result.Data) } +type OpenMessageContentRequest struct { + // Chat identifier of the message + ChatId int64 `json:"chat_id"` + // Identifier of the message with the opened content + MessageId int64 `json:"message_id"` +} + // This method should be called if the message content has been opened (e.g., the user has opened a photo, video, document, location or venue, or has listened to an audio file or voice note message). An updateMessageContentOpened update will be generated if something has changed -// -// @param chatId Chat identifier of the message -// @param messageId Identifier of the message with the opened content -func (client *Client) OpenMessageContent(chatId int64, messageId int64) (*Ok, error) { +func (client *Client) OpenMessageContent(req *OpenMessageContentRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "openMessageContent", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -2692,16 +3108,19 @@ func (client *Client) OpenMessageContent(chatId int64, messageId int64) (*Ok, er return UnmarshalOk(result.Data) } +type ReadAllChatMentionsRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Marks all mentions in a chat as read -// -// @param chatId Chat identifier -func (client *Client) ReadAllChatMentions(chatId int64) (*Ok, error) { +func (client *Client) ReadAllChatMentions(req *ReadAllChatMentionsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "readAllChatMentions", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -2715,18 +3134,22 @@ func (client *Client) ReadAllChatMentions(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type CreatePrivateChatRequest struct { + // User identifier + UserId int32 `json:"user_id"` + // If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect + Force bool `json:"force"` +} + // Returns an existing chat corresponding to a given user -// -// @param userId User identifier -// @param force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect -func (client *Client) CreatePrivateChat(userId int32, force bool) (*Chat, error) { +func (client *Client) CreatePrivateChat(req *CreatePrivateChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createPrivateChat", }, Data: map[string]interface{}{ - "user_id": userId, - "force": force, + "user_id": req.UserId, + "force": req.Force, }, }) if err != nil { @@ -2740,18 +3163,22 @@ func (client *Client) CreatePrivateChat(userId int32, force bool) (*Chat, error) return UnmarshalChat(result.Data) } +type CreateBasicGroupChatRequest struct { + // Basic group identifier + BasicGroupId int32 `json:"basic_group_id"` + // If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect + Force bool `json:"force"` +} + // Returns an existing chat corresponding to a known basic group -// -// @param basicGroupId Basic group identifier -// @param force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect -func (client *Client) CreateBasicGroupChat(basicGroupId int32, force bool) (*Chat, error) { +func (client *Client) CreateBasicGroupChat(req *CreateBasicGroupChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createBasicGroupChat", }, Data: map[string]interface{}{ - "basic_group_id": basicGroupId, - "force": force, + "basic_group_id": req.BasicGroupId, + "force": req.Force, }, }) if err != nil { @@ -2765,18 +3192,22 @@ func (client *Client) CreateBasicGroupChat(basicGroupId int32, force bool) (*Cha return UnmarshalChat(result.Data) } +type CreateSupergroupChatRequest struct { + // Supergroup or channel identifier + SupergroupId int32 `json:"supergroup_id"` + // If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect + Force bool `json:"force"` +} + // Returns an existing chat corresponding to a known supergroup or channel -// -// @param supergroupId Supergroup or channel identifier -// @param force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect -func (client *Client) CreateSupergroupChat(supergroupId int32, force bool) (*Chat, error) { +func (client *Client) CreateSupergroupChat(req *CreateSupergroupChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createSupergroupChat", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "force": force, + "supergroup_id": req.SupergroupId, + "force": req.Force, }, }) if err != nil { @@ -2790,16 +3221,19 @@ func (client *Client) CreateSupergroupChat(supergroupId int32, force bool) (*Cha return UnmarshalChat(result.Data) } +type CreateSecretChatRequest struct { + // Secret chat identifier + SecretChatId int32 `json:"secret_chat_id"` +} + // Returns an existing chat corresponding to a known secret chat -// -// @param secretChatId Secret chat identifier -func (client *Client) CreateSecretChat(secretChatId int32) (*Chat, error) { +func (client *Client) CreateSecretChat(req *CreateSecretChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createSecretChat", }, Data: map[string]interface{}{ - "secret_chat_id": secretChatId, + "secret_chat_id": req.SecretChatId, }, }) if err != nil { @@ -2813,18 +3247,22 @@ func (client *Client) CreateSecretChat(secretChatId int32) (*Chat, error) { return UnmarshalChat(result.Data) } +type CreateNewBasicGroupChatRequest struct { + // Identifiers of users to be added to the basic group + UserIds []int32 `json:"user_ids"` + // Title of the new basic group; 1-255 characters + Title string `json:"title"` +} + // Creates a new basic group and sends a corresponding messageBasicGroupChatCreate. Returns the newly created chat -// -// @param userIds Identifiers of users to be added to the basic group -// @param title Title of the new basic group; 1-255 characters -func (client *Client) CreateNewBasicGroupChat(userIds []int32, title string) (*Chat, error) { +func (client *Client) CreateNewBasicGroupChat(req *CreateNewBasicGroupChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createNewBasicGroupChat", }, Data: map[string]interface{}{ - "user_ids": userIds, - "title": title, + "user_ids": req.UserIds, + "title": req.Title, }, }) if err != nil { @@ -2838,20 +3276,25 @@ func (client *Client) CreateNewBasicGroupChat(userIds []int32, title string) (*C return UnmarshalChat(result.Data) } +type CreateNewSupergroupChatRequest struct { + // Title of the new chat; 1-255 characters + Title string `json:"title"` + // True, if a channel chat should be created + IsChannel bool `json:"is_channel"` + // Chat description; 0-255 characters + Description string `json:"description"` +} + // Creates a new supergroup or channel and sends a corresponding messageSupergroupChatCreate. Returns the newly created chat -// -// @param title Title of the new chat; 1-255 characters -// @param isChannel True, if a channel chat should be created -// @param description Chat description; 0-255 characters -func (client *Client) CreateNewSupergroupChat(title string, isChannel bool, description string) (*Chat, error) { +func (client *Client) CreateNewSupergroupChat(req *CreateNewSupergroupChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createNewSupergroupChat", }, Data: map[string]interface{}{ - "title": title, - "is_channel": isChannel, - "description": description, + "title": req.Title, + "is_channel": req.IsChannel, + "description": req.Description, }, }) if err != nil { @@ -2865,16 +3308,19 @@ func (client *Client) CreateNewSupergroupChat(title string, isChannel bool, desc return UnmarshalChat(result.Data) } +type CreateNewSecretChatRequest struct { + // Identifier of the target user + UserId int32 `json:"user_id"` +} + // Creates a new secret chat. Returns the newly created chat -// -// @param userId Identifier of the target user -func (client *Client) CreateNewSecretChat(userId int32) (*Chat, error) { +func (client *Client) CreateNewSecretChat(req *CreateNewSecretChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "createNewSecretChat", }, Data: map[string]interface{}{ - "user_id": userId, + "user_id": req.UserId, }, }) if err != nil { @@ -2888,16 +3334,19 @@ func (client *Client) CreateNewSecretChat(userId int32) (*Chat, error) { return UnmarshalChat(result.Data) } +type UpgradeBasicGroupChatToSupergroupChatRequest struct { + // Identifier of the chat to upgrade + ChatId int64 `json:"chat_id"` +} + // Creates a new supergroup from an existing basic group and sends a corresponding messageChatUpgradeTo and messageChatUpgradeFrom. Deactivates the original basic group -// -// @param chatId Identifier of the chat to upgrade -func (client *Client) UpgradeBasicGroupChatToSupergroupChat(chatId int64) (*Chat, error) { +func (client *Client) UpgradeBasicGroupChatToSupergroupChat(req *UpgradeBasicGroupChatToSupergroupChatRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "upgradeBasicGroupChatToSupergroupChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -2911,18 +3360,22 @@ func (client *Client) UpgradeBasicGroupChatToSupergroupChat(chatId int64) (*Chat return UnmarshalChat(result.Data) } +type SetChatTitleRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New title of the chat; 1-255 characters + Title string `json:"title"` +} + // Changes the chat title. Supported only for basic groups, supergroups and channels. Requires administrator rights in basic groups and the appropriate administrator rights in supergroups and channels. The title will not be changed until the request to the server has been completed -// -// @param chatId Chat identifier -// @param title New title of the chat; 1-255 characters -func (client *Client) SetChatTitle(chatId int64, title string) (*Ok, error) { +func (client *Client) SetChatTitle(req *SetChatTitleRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatTitle", }, Data: map[string]interface{}{ - "chat_id": chatId, - "title": title, + "chat_id": req.ChatId, + "title": req.Title, }, }) if err != nil { @@ -2936,18 +3389,22 @@ func (client *Client) SetChatTitle(chatId int64, title string) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetChatPhotoRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New chat photo. You can use a zero InputFileId to delete the chat photo. Files that are accessible only by HTTP URL are not acceptable + Photo InputFile `json:"photo"` +} + // Changes the photo of a chat. Supported only for basic groups, supergroups and channels. Requires administrator rights in basic groups and the appropriate administrator rights in supergroups and channels. The photo will not be changed before request to the server has been completed -// -// @param chatId Chat identifier -// @param photo New chat photo. You can use a zero InputFileId to delete the chat photo. Files that are accessible only by HTTP URL are not acceptable -func (client *Client) SetChatPhoto(chatId int64, photo InputFile) (*Ok, error) { +func (client *Client) SetChatPhoto(req *SetChatPhotoRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatPhoto", }, Data: map[string]interface{}{ - "chat_id": chatId, - "photo": photo, + "chat_id": req.ChatId, + "photo": req.Photo, }, }) if err != nil { @@ -2961,18 +3418,22 @@ func (client *Client) SetChatPhoto(chatId int64, photo InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetChatDraftMessageRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New draft message; may be null + DraftMessage *DraftMessage `json:"draft_message"` +} + // Changes the draft message in a chat -// -// @param chatId Chat identifier -// @param draftMessage New draft message; may be null -func (client *Client) SetChatDraftMessage(chatId int64, draftMessage *DraftMessage) (*Ok, error) { +func (client *Client) SetChatDraftMessage(req *SetChatDraftMessageRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatDraftMessage", }, Data: map[string]interface{}{ - "chat_id": chatId, - "draft_message": draftMessage, + "chat_id": req.ChatId, + "draft_message": req.DraftMessage, }, }) if err != nil { @@ -2986,18 +3447,22 @@ func (client *Client) SetChatDraftMessage(chatId int64, draftMessage *DraftMessa return UnmarshalOk(result.Data) } +type SetChatNotificationSettingsRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New notification settings for the chat + NotificationSettings *ChatNotificationSettings `json:"notification_settings"` +} + // Changes the notification settings of a chat -// -// @param chatId Chat identifier -// @param notificationSettings New notification settings for the chat -func (client *Client) SetChatNotificationSettings(chatId int64, notificationSettings *ChatNotificationSettings) (*Ok, error) { +func (client *Client) SetChatNotificationSettings(req *SetChatNotificationSettingsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatNotificationSettings", }, Data: map[string]interface{}{ - "chat_id": chatId, - "notification_settings": notificationSettings, + "chat_id": req.ChatId, + "notification_settings": req.NotificationSettings, }, }) if err != nil { @@ -3011,18 +3476,22 @@ func (client *Client) SetChatNotificationSettings(chatId int64, notificationSett return UnmarshalOk(result.Data) } +type ToggleChatIsPinnedRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New value of is_pinned + IsPinned bool `json:"is_pinned"` +} + // Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max") non-secret chats and the same number of secret chats -// -// @param chatId Chat identifier -// @param isPinned New value of is_pinned -func (client *Client) ToggleChatIsPinned(chatId int64, isPinned bool) (*Ok, error) { +func (client *Client) ToggleChatIsPinned(req *ToggleChatIsPinnedRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleChatIsPinned", }, Data: map[string]interface{}{ - "chat_id": chatId, - "is_pinned": isPinned, + "chat_id": req.ChatId, + "is_pinned": req.IsPinned, }, }) if err != nil { @@ -3036,18 +3505,22 @@ func (client *Client) ToggleChatIsPinned(chatId int64, isPinned bool) (*Ok, erro return UnmarshalOk(result.Data) } +type ToggleChatIsMarkedAsUnreadRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New value of is_marked_as_unread + IsMarkedAsUnread bool `json:"is_marked_as_unread"` +} + // Changes the marked as unread state of a chat -// -// @param chatId Chat identifier -// @param isMarkedAsUnread New value of is_marked_as_unread -func (client *Client) ToggleChatIsMarkedAsUnread(chatId int64, isMarkedAsUnread bool) (*Ok, error) { +func (client *Client) ToggleChatIsMarkedAsUnread(req *ToggleChatIsMarkedAsUnreadRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleChatIsMarkedAsUnread", }, Data: map[string]interface{}{ - "chat_id": chatId, - "is_marked_as_unread": isMarkedAsUnread, + "chat_id": req.ChatId, + "is_marked_as_unread": req.IsMarkedAsUnread, }, }) if err != nil { @@ -3061,18 +3534,22 @@ func (client *Client) ToggleChatIsMarkedAsUnread(chatId int64, isMarkedAsUnread return UnmarshalOk(result.Data) } +type ToggleChatDefaultDisableNotificationRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New value of default_disable_notification + DefaultDisableNotification bool `json:"default_disable_notification"` +} + // Changes the value of the default disable_notification parameter, used when a message is sent to a chat -// -// @param chatId Chat identifier -// @param defaultDisableNotification New value of default_disable_notification -func (client *Client) ToggleChatDefaultDisableNotification(chatId int64, defaultDisableNotification bool) (*Ok, error) { +func (client *Client) ToggleChatDefaultDisableNotification(req *ToggleChatDefaultDisableNotificationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleChatDefaultDisableNotification", }, Data: map[string]interface{}{ - "chat_id": chatId, - "default_disable_notification": defaultDisableNotification, + "chat_id": req.ChatId, + "default_disable_notification": req.DefaultDisableNotification, }, }) if err != nil { @@ -3086,18 +3563,22 @@ func (client *Client) ToggleChatDefaultDisableNotification(chatId int64, default return UnmarshalOk(result.Data) } +type SetChatClientDataRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // New value of client_data + ClientData string `json:"client_data"` +} + // Changes client data associated with a chat -// -// @param chatId Chat identifier -// @param clientData New value of client_data -func (client *Client) SetChatClientData(chatId int64, clientData string) (*Ok, error) { +func (client *Client) SetChatClientData(req *SetChatClientDataRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatClientData", }, Data: map[string]interface{}{ - "chat_id": chatId, - "client_data": clientData, + "chat_id": req.ChatId, + "client_data": req.ClientData, }, }) if err != nil { @@ -3111,16 +3592,19 @@ func (client *Client) SetChatClientData(chatId int64, clientData string) (*Ok, e return UnmarshalOk(result.Data) } +type JoinChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Adds current user as a new member to a chat. Private and secret chats can't be joined using this method -// -// @param chatId Chat identifier -func (client *Client) JoinChat(chatId int64) (*Ok, error) { +func (client *Client) JoinChat(req *JoinChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "joinChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -3134,16 +3618,19 @@ func (client *Client) JoinChat(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type LeaveChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Removes current user from chat members. Private and secret chats can't be left using this method -// -// @param chatId Chat identifier -func (client *Client) LeaveChat(chatId int64) (*Ok, error) { +func (client *Client) LeaveChat(req *LeaveChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "leaveChat", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -3157,20 +3644,25 @@ func (client *Client) LeaveChat(chatId int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type AddChatMemberRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Identifier of the user + UserId int32 `json:"user_id"` + // The number of earlier messages from the chat to be forwarded to the new member; up to 300. Ignored for supergroups and channels + ForwardLimit int32 `json:"forward_limit"` +} + // Adds a new member to a chat. Members can't be added to private or secret chats. Members will not be added until the chat state has been synchronized with the server -// -// @param chatId Chat identifier -// @param userId Identifier of the user -// @param forwardLimit The number of earlier messages from the chat to be forwarded to the new member; up to 300. Ignored for supergroups and channels -func (client *Client) AddChatMember(chatId int64, userId int32, forwardLimit int32) (*Ok, error) { +func (client *Client) AddChatMember(req *AddChatMemberRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addChatMember", }, Data: map[string]interface{}{ - "chat_id": chatId, - "user_id": userId, - "forward_limit": forwardLimit, + "chat_id": req.ChatId, + "user_id": req.UserId, + "forward_limit": req.ForwardLimit, }, }) if err != nil { @@ -3184,18 +3676,22 @@ func (client *Client) AddChatMember(chatId int64, userId int32, forwardLimit int return UnmarshalOk(result.Data) } +type AddChatMembersRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Identifiers of the users to be added to the chat + UserIds []int32 `json:"user_ids"` +} + // Adds multiple new members to a chat. Currently this option is only available for supergroups and channels. This option can't be used to join a chat. Members can't be added to a channel if it has more than 200 members. Members will not be added until the chat state has been synchronized with the server -// -// @param chatId Chat identifier -// @param userIds Identifiers of the users to be added to the chat -func (client *Client) AddChatMembers(chatId int64, userIds []int32) (*Ok, error) { +func (client *Client) AddChatMembers(req *AddChatMembersRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addChatMembers", }, Data: map[string]interface{}{ - "chat_id": chatId, - "user_ids": userIds, + "chat_id": req.ChatId, + "user_ids": req.UserIds, }, }) if err != nil { @@ -3209,20 +3705,25 @@ func (client *Client) AddChatMembers(chatId int64, userIds []int32) (*Ok, error) return UnmarshalOk(result.Data) } +type SetChatMemberStatusRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // User identifier + UserId int32 `json:"user_id"` + // The new status of the member in the chat + Status ChatMemberStatus `json:"status"` +} + // Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for adding new members to the chat; instead, use addChatMember. The chat member status will not be changed until it has been synchronized with the server -// -// @param chatId Chat identifier -// @param userId User identifier -// @param status The new status of the member in the chat -func (client *Client) SetChatMemberStatus(chatId int64, userId int32, status ChatMemberStatus) (*Ok, error) { +func (client *Client) SetChatMemberStatus(req *SetChatMemberStatusRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setChatMemberStatus", }, Data: map[string]interface{}{ - "chat_id": chatId, - "user_id": userId, - "status": status, + "chat_id": req.ChatId, + "user_id": req.UserId, + "status": req.Status, }, }) if err != nil { @@ -3236,18 +3737,22 @@ func (client *Client) SetChatMemberStatus(chatId int64, userId int32, status Cha return UnmarshalOk(result.Data) } +type GetChatMemberRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // User identifier + UserId int32 `json:"user_id"` +} + // Returns information about a single member of a chat -// -// @param chatId Chat identifier -// @param userId User identifier -func (client *Client) GetChatMember(chatId int64, userId int32) (*ChatMember, error) { +func (client *Client) GetChatMember(req *GetChatMemberRequest) (*ChatMember, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatMember", }, Data: map[string]interface{}{ - "chat_id": chatId, - "user_id": userId, + "chat_id": req.ChatId, + "user_id": req.UserId, }, }) if err != nil { @@ -3261,22 +3766,28 @@ func (client *Client) GetChatMember(chatId int64, userId int32) (*ChatMember, er return UnmarshalChatMember(result.Data) } +type SearchChatMembersRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Query to search for + Query string `json:"query"` + // The maximum number of users to be returned + Limit int32 `json:"limit"` + // The type of users to return. By default, chatMembersFilterMembers + Filter ChatMembersFilter `json:"filter"` +} + // Searches for a specified query in the first name, last name and username of the members of a specified chat. Requires administrator rights in channels -// -// @param chatId Chat identifier -// @param query Query to search for -// @param limit The maximum number of users to be returned -// @param filter The type of users to return. By default, chatMembersFilterMembers -func (client *Client) SearchChatMembers(chatId int64, query string, limit int32, filter ChatMembersFilter) (*ChatMembers, error) { +func (client *Client) SearchChatMembers(req *SearchChatMembersRequest) (*ChatMembers, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchChatMembers", }, Data: map[string]interface{}{ - "chat_id": chatId, - "query": query, - "limit": limit, - "filter": filter, + "chat_id": req.ChatId, + "query": req.Query, + "limit": req.Limit, + "filter": req.Filter, }, }) if err != nil { @@ -3290,16 +3801,19 @@ func (client *Client) SearchChatMembers(chatId int64, query string, limit int32, return UnmarshalChatMembers(result.Data) } +type GetChatAdministratorsRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Returns a list of users who are administrators of the chat -// -// @param chatId Chat identifier -func (client *Client) GetChatAdministrators(chatId int64) (*Users, error) { +func (client *Client) GetChatAdministrators(req *GetChatAdministratorsRequest) (*Users, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatAdministrators", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -3313,16 +3827,19 @@ func (client *Client) GetChatAdministrators(chatId int64) (*Users, error) { return UnmarshalUsers(result.Data) } +type ClearAllDraftMessagesRequest struct { + // If true, local draft messages in secret chats will not be cleared + ExcludeSecretChats bool `json:"exclude_secret_chats"` +} + // Clears draft messages in all chats -// -// @param excludeSecretChats If true, local draft messages in secret chats will not be cleared -func (client *Client) ClearAllDraftMessages(excludeSecretChats bool) (*Ok, error) { +func (client *Client) ClearAllDraftMessages(req *ClearAllDraftMessagesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "clearAllDraftMessages", }, Data: map[string]interface{}{ - "exclude_secret_chats": excludeSecretChats, + "exclude_secret_chats": req.ExcludeSecretChats, }, }) if err != nil { @@ -3336,16 +3853,19 @@ func (client *Client) ClearAllDraftMessages(excludeSecretChats bool) (*Ok, error return UnmarshalOk(result.Data) } +type GetScopeNotificationSettingsRequest struct { + // Types of chats for which to return the notification settings information + Scope NotificationSettingsScope `json:"scope"` +} + // Returns the notification settings for chats of a given type -// -// @param scope Types of chats for which to return the notification settings information -func (client *Client) GetScopeNotificationSettings(scope NotificationSettingsScope) (*ScopeNotificationSettings, error) { +func (client *Client) GetScopeNotificationSettings(req *GetScopeNotificationSettingsRequest) (*ScopeNotificationSettings, error) { result, err := client.Send(Request{ meta: meta{ Type: "getScopeNotificationSettings", }, Data: map[string]interface{}{ - "scope": scope, + "scope": req.Scope, }, }) if err != nil { @@ -3359,18 +3879,22 @@ func (client *Client) GetScopeNotificationSettings(scope NotificationSettingsSco return UnmarshalScopeNotificationSettings(result.Data) } +type SetScopeNotificationSettingsRequest struct { + // Types of chats for which to change the notification settings + Scope NotificationSettingsScope `json:"scope"` + // The new notification settings for the given scope + NotificationSettings *ScopeNotificationSettings `json:"notification_settings"` +} + // Changes notification settings for chats of a given type -// -// @param scope Types of chats for which to change the notification settings -// @param notificationSettings The new notification settings for the given scope -func (client *Client) SetScopeNotificationSettings(scope NotificationSettingsScope, notificationSettings *ScopeNotificationSettings) (*Ok, error) { +func (client *Client) SetScopeNotificationSettings(req *SetScopeNotificationSettingsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setScopeNotificationSettings", }, Data: map[string]interface{}{ - "scope": scope, - "notification_settings": notificationSettings, + "scope": req.Scope, + "notification_settings": req.NotificationSettings, }, }) if err != nil { @@ -3403,16 +3927,19 @@ func (client *Client) ResetAllNotificationSettings() (*Ok, error) { return UnmarshalOk(result.Data) } +type SetPinnedChatsRequest struct { + // The new list of pinned chats + ChatIds []int64 `json:"chat_ids"` +} + // Changes the order of pinned chats -// -// @param chatIds The new list of pinned chats -func (client *Client) SetPinnedChats(chatIds []int64) (*Ok, error) { +func (client *Client) SetPinnedChats(req *SetPinnedChatsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setPinnedChats", }, Data: map[string]interface{}{ - "chat_ids": chatIds, + "chat_ids": req.ChatIds, }, }) if err != nil { @@ -3426,18 +3953,22 @@ func (client *Client) SetPinnedChats(chatIds []int64) (*Ok, error) { return UnmarshalOk(result.Data) } +type DownloadFileRequest struct { + // Identifier of the file to download + FileId int32 `json:"file_id"` + // Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile was called will be downloaded first + Priority int32 `json:"priority"` +} + // Asynchronously downloads a file from the cloud. updateFile will be used to notify about the download progress and successful completion of the download. Returns file state just after the download has been started -// -// @param fileId Identifier of the file to download -// @param priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile was called will be downloaded first -func (client *Client) DownloadFile(fileId int32, priority int32) (*File, error) { +func (client *Client) DownloadFile(req *DownloadFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "downloadFile", }, Data: map[string]interface{}{ - "file_id": fileId, - "priority": priority, + "file_id": req.FileId, + "priority": req.Priority, }, }) if err != nil { @@ -3451,18 +3982,22 @@ func (client *Client) DownloadFile(fileId int32, priority int32) (*File, error) return UnmarshalFile(result.Data) } +type CancelDownloadFileRequest struct { + // Identifier of a file to stop downloading + FileId int32 `json:"file_id"` + // Pass true to stop downloading only if it hasn't been started, i.e. request hasn't been sent to server + OnlyIfPending bool `json:"only_if_pending"` +} + // Stops the downloading of a file. If a file has already been downloaded, does nothing -// -// @param fileId Identifier of a file to stop downloading -// @param onlyIfPending Pass true to stop downloading only if it hasn't been started, i.e. request hasn't been sent to server -func (client *Client) CancelDownloadFile(fileId int32, onlyIfPending bool) (*Ok, error) { +func (client *Client) CancelDownloadFile(req *CancelDownloadFileRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "cancelDownloadFile", }, Data: map[string]interface{}{ - "file_id": fileId, - "only_if_pending": onlyIfPending, + "file_id": req.FileId, + "only_if_pending": req.OnlyIfPending, }, }) if err != nil { @@ -3476,20 +4011,25 @@ func (client *Client) CancelDownloadFile(fileId int32, onlyIfPending bool) (*Ok, return UnmarshalOk(result.Data) } +type UploadFileRequest struct { + // File to upload + File InputFile `json:"file"` + // File type + FileType FileType `json:"file_type"` + // Priority of the upload (1-32). The higher the priority, the earlier the file will be uploaded. If the priorities of two files are equal, then the first one for which uploadFile was called will be uploaded first + Priority int32 `json:"priority"` +} + // Asynchronously uploads a file to the cloud without sending it in a message. updateFile will be used to notify about upload progress and successful completion of the upload. The file will not have a persistent remote identifier until it will be sent in a message -// -// @param file File to upload -// @param fileType File type -// @param priority Priority of the upload (1-32). The higher the priority, the earlier the file will be uploaded. If the priorities of two files are equal, then the first one for which uploadFile was called will be uploaded first -func (client *Client) UploadFile(file InputFile, fileType FileType, priority int32) (*File, error) { +func (client *Client) UploadFile(req *UploadFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "uploadFile", }, Data: map[string]interface{}{ - "file": file, - "file_type": fileType, - "priority": priority, + "file": req.File, + "file_type": req.FileType, + "priority": req.Priority, }, }) if err != nil { @@ -3503,16 +4043,19 @@ func (client *Client) UploadFile(file InputFile, fileType FileType, priority int return UnmarshalFile(result.Data) } +type CancelUploadFileRequest struct { + // Identifier of the file to stop uploading + FileId int32 `json:"file_id"` +} + // Stops the uploading of a file. Supported only for files uploaded by using uploadFile. For other files the behavior is undefined -// -// @param fileId Identifier of the file to stop uploading -func (client *Client) CancelUploadFile(fileId int32) (*Ok, error) { +func (client *Client) CancelUploadFile(req *CancelUploadFileRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "cancelUploadFile", }, Data: map[string]interface{}{ - "file_id": fileId, + "file_id": req.FileId, }, }) if err != nil { @@ -3526,20 +4069,25 @@ func (client *Client) CancelUploadFile(fileId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetFileGenerationProgressRequest struct { + // The identifier of the generation process + GenerationId JsonInt64 `json:"generation_id"` + // Expected size of the generated file, in bytes; 0 if unknown + ExpectedSize int32 `json:"expected_size"` + // The number of bytes already generated + LocalPrefixSize int32 `json:"local_prefix_size"` +} + // The next part of a file was generated -// -// @param generationId The identifier of the generation process -// @param expectedSize Expected size of the generated file, in bytes; 0 if unknown -// @param localPrefixSize The number of bytes already generated -func (client *Client) SetFileGenerationProgress(generationId JsonInt64, expectedSize int32, localPrefixSize int32) (*Ok, error) { +func (client *Client) SetFileGenerationProgress(req *SetFileGenerationProgressRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setFileGenerationProgress", }, Data: map[string]interface{}{ - "generation_id": generationId, - "expected_size": expectedSize, - "local_prefix_size": localPrefixSize, + "generation_id": req.GenerationId, + "expected_size": req.ExpectedSize, + "local_prefix_size": req.LocalPrefixSize, }, }) if err != nil { @@ -3553,18 +4101,22 @@ func (client *Client) SetFileGenerationProgress(generationId JsonInt64, expected return UnmarshalOk(result.Data) } +type FinishFileGenerationRequest struct { + // The identifier of the generation process + GenerationId JsonInt64 `json:"generation_id"` + // If set, means that file generation has failed and should be terminated + Error *Error `json:"error"` +} + // Finishes the file generation -// -// @param generationId The identifier of the generation process -// @param error If set, means that file generation has failed and should be terminated -func (client *Client) FinishFileGeneration(generationId JsonInt64, error *Error) (*Ok, error) { +func (client *Client) FinishFileGeneration(req *FinishFileGenerationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "finishFileGeneration", }, Data: map[string]interface{}{ - "generation_id": generationId, - "error": error, + "generation_id": req.GenerationId, + "error": req.Error, }, }) if err != nil { @@ -3578,16 +4130,19 @@ func (client *Client) FinishFileGeneration(generationId JsonInt64, error *Error) return UnmarshalOk(result.Data) } +type DeleteFileRequest struct { + // Identifier of the file to delete + FileId int32 `json:"file_id"` +} + // Deletes a file from the TDLib file cache -// -// @param fileId Identifier of the file to delete -func (client *Client) DeleteFile(fileId int32) (*Ok, error) { +func (client *Client) DeleteFile(req *DeleteFileRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteFile", }, Data: map[string]interface{}{ - "file_id": fileId, + "file_id": req.FileId, }, }) if err != nil { @@ -3601,16 +4156,19 @@ func (client *Client) DeleteFile(fileId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type GenerateChatInviteLinkRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Generates a new invite link for a chat; the previously generated link is revoked. Available for basic groups, supergroups, and channels. In basic groups this can be called only by the group's creator; in supergroups and channels this requires appropriate administrator rights -// -// @param chatId Chat identifier -func (client *Client) GenerateChatInviteLink(chatId int64) (*ChatInviteLink, error) { +func (client *Client) GenerateChatInviteLink(req *GenerateChatInviteLinkRequest) (*ChatInviteLink, error) { result, err := client.Send(Request{ meta: meta{ Type: "generateChatInviteLink", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -3624,16 +4182,19 @@ func (client *Client) GenerateChatInviteLink(chatId int64) (*ChatInviteLink, err return UnmarshalChatInviteLink(result.Data) } +type CheckChatInviteLinkRequest struct { + // Invite link to be checked; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/" + InviteLink string `json:"invite_link"` +} + // Checks the validity of an invite link for a chat and returns information about the corresponding chat -// -// @param inviteLink Invite link to be checked; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/" -func (client *Client) CheckChatInviteLink(inviteLink string) (*ChatInviteLinkInfo, error) { +func (client *Client) CheckChatInviteLink(req *CheckChatInviteLinkRequest) (*ChatInviteLinkInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkChatInviteLink", }, Data: map[string]interface{}{ - "invite_link": inviteLink, + "invite_link": req.InviteLink, }, }) if err != nil { @@ -3647,16 +4208,19 @@ func (client *Client) CheckChatInviteLink(inviteLink string) (*ChatInviteLinkInf return UnmarshalChatInviteLinkInfo(result.Data) } +type JoinChatByInviteLinkRequest struct { + // Invite link to import; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/" + InviteLink string `json:"invite_link"` +} + // Uses an invite link to add the current user to the chat if possible. The new member will not be added until the chat state has been synchronized with the server -// -// @param inviteLink Invite link to import; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/" -func (client *Client) JoinChatByInviteLink(inviteLink string) (*Chat, error) { +func (client *Client) JoinChatByInviteLink(req *JoinChatByInviteLinkRequest) (*Chat, error) { result, err := client.Send(Request{ meta: meta{ Type: "joinChatByInviteLink", }, Data: map[string]interface{}{ - "invite_link": inviteLink, + "invite_link": req.InviteLink, }, }) if err != nil { @@ -3670,18 +4234,22 @@ func (client *Client) JoinChatByInviteLink(inviteLink string) (*Chat, error) { return UnmarshalChat(result.Data) } +type CreateCallRequest struct { + // Identifier of the user to be called + UserId int32 `json:"user_id"` + // Description of the call protocols supported by the client + Protocol *CallProtocol `json:"protocol"` +} + // Creates a new call -// -// @param userId Identifier of the user to be called -// @param protocol Description of the call protocols supported by the client -func (client *Client) CreateCall(userId int32, protocol *CallProtocol) (*CallId, error) { +func (client *Client) CreateCall(req *CreateCallRequest) (*CallId, error) { result, err := client.Send(Request{ meta: meta{ Type: "createCall", }, Data: map[string]interface{}{ - "user_id": userId, - "protocol": protocol, + "user_id": req.UserId, + "protocol": req.Protocol, }, }) if err != nil { @@ -3695,18 +4263,22 @@ func (client *Client) CreateCall(userId int32, protocol *CallProtocol) (*CallId, return UnmarshalCallId(result.Data) } +type AcceptCallRequest struct { + // Call identifier + CallId int32 `json:"call_id"` + // Description of the call protocols supported by the client + Protocol *CallProtocol `json:"protocol"` +} + // Accepts an incoming call -// -// @param callId Call identifier -// @param protocol Description of the call protocols supported by the client -func (client *Client) AcceptCall(callId int32, protocol *CallProtocol) (*Ok, error) { +func (client *Client) AcceptCall(req *AcceptCallRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "acceptCall", }, Data: map[string]interface{}{ - "call_id": callId, - "protocol": protocol, + "call_id": req.CallId, + "protocol": req.Protocol, }, }) if err != nil { @@ -3720,22 +4292,28 @@ func (client *Client) AcceptCall(callId int32, protocol *CallProtocol) (*Ok, err return UnmarshalOk(result.Data) } +type DiscardCallRequest struct { + // Call identifier + CallId int32 `json:"call_id"` + // True, if the user was disconnected + IsDisconnected bool `json:"is_disconnected"` + // The call duration, in seconds + Duration int32 `json:"duration"` + // Identifier of the connection used during the call + ConnectionId JsonInt64 `json:"connection_id"` +} + // Discards a call -// -// @param callId Call identifier -// @param isDisconnected True, if the user was disconnected -// @param duration The call duration, in seconds -// @param connectionId Identifier of the connection used during the call -func (client *Client) DiscardCall(callId int32, isDisconnected bool, duration int32, connectionId JsonInt64) (*Ok, error) { +func (client *Client) DiscardCall(req *DiscardCallRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "discardCall", }, Data: map[string]interface{}{ - "call_id": callId, - "is_disconnected": isDisconnected, - "duration": duration, - "connection_id": connectionId, + "call_id": req.CallId, + "is_disconnected": req.IsDisconnected, + "duration": req.Duration, + "connection_id": req.ConnectionId, }, }) if err != nil { @@ -3749,20 +4327,25 @@ func (client *Client) DiscardCall(callId int32, isDisconnected bool, duration in return UnmarshalOk(result.Data) } +type SendCallRatingRequest struct { + // Call identifier + CallId int32 `json:"call_id"` + // Call rating; 1-5 + Rating int32 `json:"rating"` + // An optional user comment if the rating is less than 5 + Comment string `json:"comment"` +} + // Sends a call rating -// -// @param callId Call identifier -// @param rating Call rating; 1-5 -// @param comment An optional user comment if the rating is less than 5 -func (client *Client) SendCallRating(callId int32, rating int32, comment string) (*Ok, error) { +func (client *Client) SendCallRating(req *SendCallRatingRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendCallRating", }, Data: map[string]interface{}{ - "call_id": callId, - "rating": rating, - "comment": comment, + "call_id": req.CallId, + "rating": req.Rating, + "comment": req.Comment, }, }) if err != nil { @@ -3776,18 +4359,22 @@ func (client *Client) SendCallRating(callId int32, rating int32, comment string) return UnmarshalOk(result.Data) } +type SendCallDebugInformationRequest struct { + // Call identifier + CallId int32 `json:"call_id"` + // Debug information in application-specific format + DebugInformation string `json:"debug_information"` +} + // Sends debug information for a call -// -// @param callId Call identifier -// @param debugInformation Debug information in application-specific format -func (client *Client) SendCallDebugInformation(callId int32, debugInformation string) (*Ok, error) { +func (client *Client) SendCallDebugInformation(req *SendCallDebugInformationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendCallDebugInformation", }, Data: map[string]interface{}{ - "call_id": callId, - "debug_information": debugInformation, + "call_id": req.CallId, + "debug_information": req.DebugInformation, }, }) if err != nil { @@ -3801,16 +4388,19 @@ func (client *Client) SendCallDebugInformation(callId int32, debugInformation st return UnmarshalOk(result.Data) } +type BlockUserRequest struct { + // User identifier + UserId int32 `json:"user_id"` +} + // Adds a user to the blacklist -// -// @param userId User identifier -func (client *Client) BlockUser(userId int32) (*Ok, error) { +func (client *Client) BlockUser(req *BlockUserRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "blockUser", }, Data: map[string]interface{}{ - "user_id": userId, + "user_id": req.UserId, }, }) if err != nil { @@ -3824,16 +4414,19 @@ func (client *Client) BlockUser(userId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type UnblockUserRequest struct { + // User identifier + UserId int32 `json:"user_id"` +} + // Removes a user from the blacklist -// -// @param userId User identifier -func (client *Client) UnblockUser(userId int32) (*Ok, error) { +func (client *Client) UnblockUser(req *UnblockUserRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "unblockUser", }, Data: map[string]interface{}{ - "user_id": userId, + "user_id": req.UserId, }, }) if err != nil { @@ -3847,18 +4440,22 @@ func (client *Client) UnblockUser(userId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetBlockedUsersRequest struct { + // Number of users to skip in the result; must be non-negative + Offset int32 `json:"offset"` + // Maximum number of users to return; up to 100 + Limit int32 `json:"limit"` +} + // Returns users that were blocked by the current user -// -// @param offset Number of users to skip in the result; must be non-negative -// @param limit Maximum number of users to return; up to 100 -func (client *Client) GetBlockedUsers(offset int32, limit int32) (*Users, error) { +func (client *Client) GetBlockedUsers(req *GetBlockedUsersRequest) (*Users, error) { result, err := client.Send(Request{ meta: meta{ Type: "getBlockedUsers", }, Data: map[string]interface{}{ - "offset": offset, - "limit": limit, + "offset": req.Offset, + "limit": req.Limit, }, }) if err != nil { @@ -3872,16 +4469,19 @@ func (client *Client) GetBlockedUsers(offset int32, limit int32) (*Users, error) return UnmarshalUsers(result.Data) } +type ImportContactsRequest struct { + // The list of contacts to import or edit, contact's vCard are ignored and are not imported + Contacts []*Contact `json:"contacts"` +} + // Adds new contacts or edits existing contacts; contacts' user identifiers are ignored -// -// @param contacts The list of contacts to import or edit, contact's vCard are ignored and are not imported -func (client *Client) ImportContacts(contacts []*Contact) (*ImportedContacts, error) { +func (client *Client) ImportContacts(req *ImportContactsRequest) (*ImportedContacts, error) { result, err := client.Send(Request{ meta: meta{ Type: "importContacts", }, Data: map[string]interface{}{ - "contacts": contacts, + "contacts": req.Contacts, }, }) if err != nil { @@ -3914,18 +4514,22 @@ func (client *Client) GetContacts() (*Users, error) { return UnmarshalUsers(result.Data) } +type SearchContactsRequest struct { + // Query to search for; can be empty to return all contacts + Query string `json:"query"` + // Maximum number of users to be returned + Limit int32 `json:"limit"` +} + // Searches for the specified query in the first names, last names and usernames of the known user contacts -// -// @param query Query to search for; can be empty to return all contacts -// @param limit Maximum number of users to be returned -func (client *Client) SearchContacts(query string, limit int32) (*Users, error) { +func (client *Client) SearchContacts(req *SearchContactsRequest) (*Users, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchContacts", }, Data: map[string]interface{}{ - "query": query, - "limit": limit, + "query": req.Query, + "limit": req.Limit, }, }) if err != nil { @@ -3939,16 +4543,19 @@ func (client *Client) SearchContacts(query string, limit int32) (*Users, error) return UnmarshalUsers(result.Data) } +type RemoveContactsRequest struct { + // Identifiers of users to be deleted + UserIds []int32 `json:"user_ids"` +} + // Removes users from the contacts list -// -// @param userIds Identifiers of users to be deleted -func (client *Client) RemoveContacts(userIds []int32) (*Ok, error) { +func (client *Client) RemoveContacts(req *RemoveContactsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeContacts", }, Data: map[string]interface{}{ - "user_ids": userIds, + "user_ids": req.UserIds, }, }) if err != nil { @@ -3981,16 +4588,19 @@ func (client *Client) GetImportedContactCount() (*Count, error) { return UnmarshalCount(result.Data) } +type ChangeImportedContactsRequest struct { + // The new list of contacts, contact's vCard are ignored and are not imported + Contacts []*Contact `json:"contacts"` +} + // Changes imported contacts using the list of current user contacts saved on the device. Imports newly added contacts and, if at least the file database is enabled, deletes recently deleted contacts. Query result depends on the result of the previous query, so only one query is possible at the same time -// -// @param contacts The new list of contacts, contact's vCard are ignored and are not imported -func (client *Client) ChangeImportedContacts(contacts []*Contact) (*ImportedContacts, error) { +func (client *Client) ChangeImportedContacts(req *ChangeImportedContactsRequest) (*ImportedContacts, error) { result, err := client.Send(Request{ meta: meta{ Type: "changeImportedContacts", }, Data: map[string]interface{}{ - "contacts": contacts, + "contacts": req.Contacts, }, }) if err != nil { @@ -4023,20 +4633,25 @@ func (client *Client) ClearImportedContacts() (*Ok, error) { return UnmarshalOk(result.Data) } +type GetUserProfilePhotosRequest struct { + // User identifier + UserId int32 `json:"user_id"` + // The number of photos to skip; must be non-negative + Offset int32 `json:"offset"` + // Maximum number of photos to be returned; up to 100 + Limit int32 `json:"limit"` +} + // Returns the profile photos of a user. The result of this query may be outdated: some photos might have been deleted already -// -// @param userId User identifier -// @param offset The number of photos to skip; must be non-negative -// @param limit Maximum number of photos to be returned; up to 100 -func (client *Client) GetUserProfilePhotos(userId int32, offset int32, limit int32) (*UserProfilePhotos, error) { +func (client *Client) GetUserProfilePhotos(req *GetUserProfilePhotosRequest) (*UserProfilePhotos, error) { result, err := client.Send(Request{ meta: meta{ Type: "getUserProfilePhotos", }, Data: map[string]interface{}{ - "user_id": userId, - "offset": offset, - "limit": limit, + "user_id": req.UserId, + "offset": req.Offset, + "limit": req.Limit, }, }) if err != nil { @@ -4050,18 +4665,22 @@ func (client *Client) GetUserProfilePhotos(userId int32, offset int32, limit int return UnmarshalUserProfilePhotos(result.Data) } +type GetStickersRequest struct { + // String representation of emoji. If empty, returns all known installed stickers + Emoji string `json:"emoji"` + // Maximum number of stickers to be returned + Limit int32 `json:"limit"` +} + // Returns stickers from the installed sticker sets that correspond to a given emoji. If the emoji is not empty, favorite and recently used stickers may also be returned -// -// @param emoji String representation of emoji. If empty, returns all known installed stickers -// @param limit Maximum number of stickers to be returned -func (client *Client) GetStickers(emoji string, limit int32) (*Stickers, error) { +func (client *Client) GetStickers(req *GetStickersRequest) (*Stickers, error) { result, err := client.Send(Request{ meta: meta{ Type: "getStickers", }, Data: map[string]interface{}{ - "emoji": emoji, - "limit": limit, + "emoji": req.Emoji, + "limit": req.Limit, }, }) if err != nil { @@ -4075,18 +4694,22 @@ func (client *Client) GetStickers(emoji string, limit int32) (*Stickers, error) return UnmarshalStickers(result.Data) } +type SearchStickersRequest struct { + // String representation of emoji; must be non-empty + Emoji string `json:"emoji"` + // Maximum number of stickers to be returned + Limit int32 `json:"limit"` +} + // Searches for stickers from public sticker sets that correspond to a given emoji -// -// @param emoji String representation of emoji; must be non-empty -// @param limit Maximum number of stickers to be returned -func (client *Client) SearchStickers(emoji string, limit int32) (*Stickers, error) { +func (client *Client) SearchStickers(req *SearchStickersRequest) (*Stickers, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchStickers", }, Data: map[string]interface{}{ - "emoji": emoji, - "limit": limit, + "emoji": req.Emoji, + "limit": req.Limit, }, }) if err != nil { @@ -4100,16 +4723,19 @@ func (client *Client) SearchStickers(emoji string, limit int32) (*Stickers, erro return UnmarshalStickers(result.Data) } +type GetInstalledStickerSetsRequest struct { + // Pass true to return mask sticker sets; pass false to return ordinary sticker sets + IsMasks bool `json:"is_masks"` +} + // Returns a list of installed sticker sets -// -// @param isMasks Pass true to return mask sticker sets; pass false to return ordinary sticker sets -func (client *Client) GetInstalledStickerSets(isMasks bool) (*StickerSets, error) { +func (client *Client) GetInstalledStickerSets(req *GetInstalledStickerSetsRequest) (*StickerSets, error) { result, err := client.Send(Request{ meta: meta{ Type: "getInstalledStickerSets", }, Data: map[string]interface{}{ - "is_masks": isMasks, + "is_masks": req.IsMasks, }, }) if err != nil { @@ -4123,20 +4749,25 @@ func (client *Client) GetInstalledStickerSets(isMasks bool) (*StickerSets, error return UnmarshalStickerSets(result.Data) } +type GetArchivedStickerSetsRequest struct { + // Pass true to return mask stickers sets; pass false to return ordinary sticker sets + IsMasks bool `json:"is_masks"` + // Identifier of the sticker set from which to return the result + OffsetStickerSetId JsonInt64 `json:"offset_sticker_set_id"` + // Maximum number of sticker sets to return + Limit int32 `json:"limit"` +} + // Returns a list of archived sticker sets -// -// @param isMasks Pass true to return mask stickers sets; pass false to return ordinary sticker sets -// @param offsetStickerSetId Identifier of the sticker set from which to return the result -// @param limit Maximum number of sticker sets to return -func (client *Client) GetArchivedStickerSets(isMasks bool, offsetStickerSetId JsonInt64, limit int32) (*StickerSets, error) { +func (client *Client) GetArchivedStickerSets(req *GetArchivedStickerSetsRequest) (*StickerSets, error) { result, err := client.Send(Request{ meta: meta{ Type: "getArchivedStickerSets", }, Data: map[string]interface{}{ - "is_masks": isMasks, - "offset_sticker_set_id": offsetStickerSetId, - "limit": limit, + "is_masks": req.IsMasks, + "offset_sticker_set_id": req.OffsetStickerSetId, + "limit": req.Limit, }, }) if err != nil { @@ -4169,16 +4800,19 @@ func (client *Client) GetTrendingStickerSets() (*StickerSets, error) { return UnmarshalStickerSets(result.Data) } +type GetAttachedStickerSetsRequest struct { + // File identifier + FileId int32 `json:"file_id"` +} + // Returns a list of sticker sets attached to a file. Currently only photos and videos can have attached sticker sets -// -// @param fileId File identifier -func (client *Client) GetAttachedStickerSets(fileId int32) (*StickerSets, error) { +func (client *Client) GetAttachedStickerSets(req *GetAttachedStickerSetsRequest) (*StickerSets, error) { result, err := client.Send(Request{ meta: meta{ Type: "getAttachedStickerSets", }, Data: map[string]interface{}{ - "file_id": fileId, + "file_id": req.FileId, }, }) if err != nil { @@ -4192,16 +4826,19 @@ func (client *Client) GetAttachedStickerSets(fileId int32) (*StickerSets, error) return UnmarshalStickerSets(result.Data) } +type GetStickerSetRequest struct { + // Identifier of the sticker set + SetId JsonInt64 `json:"set_id"` +} + // Returns information about a sticker set by its identifier -// -// @param setId Identifier of the sticker set -func (client *Client) GetStickerSet(setId JsonInt64) (*StickerSet, error) { +func (client *Client) GetStickerSet(req *GetStickerSetRequest) (*StickerSet, error) { result, err := client.Send(Request{ meta: meta{ Type: "getStickerSet", }, Data: map[string]interface{}{ - "set_id": setId, + "set_id": req.SetId, }, }) if err != nil { @@ -4215,16 +4852,19 @@ func (client *Client) GetStickerSet(setId JsonInt64) (*StickerSet, error) { return UnmarshalStickerSet(result.Data) } +type SearchStickerSetRequest struct { + // Name of the sticker set + Name string `json:"name"` +} + // Searches for a sticker set by its name -// -// @param name Name of the sticker set -func (client *Client) SearchStickerSet(name string) (*StickerSet, error) { +func (client *Client) SearchStickerSet(req *SearchStickerSetRequest) (*StickerSet, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchStickerSet", }, Data: map[string]interface{}{ - "name": name, + "name": req.Name, }, }) if err != nil { @@ -4238,20 +4878,25 @@ func (client *Client) SearchStickerSet(name string) (*StickerSet, error) { return UnmarshalStickerSet(result.Data) } +type SearchInstalledStickerSetsRequest struct { + // Pass true to return mask sticker sets; pass false to return ordinary sticker sets + IsMasks bool `json:"is_masks"` + // Query to search for + Query string `json:"query"` + // Maximum number of sticker sets to return + Limit int32 `json:"limit"` +} + // Searches for installed sticker sets by looking for specified query in their title and name -// -// @param isMasks Pass true to return mask sticker sets; pass false to return ordinary sticker sets -// @param query Query to search for -// @param limit Maximum number of sticker sets to return -func (client *Client) SearchInstalledStickerSets(isMasks bool, query string, limit int32) (*StickerSets, error) { +func (client *Client) SearchInstalledStickerSets(req *SearchInstalledStickerSetsRequest) (*StickerSets, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchInstalledStickerSets", }, Data: map[string]interface{}{ - "is_masks": isMasks, - "query": query, - "limit": limit, + "is_masks": req.IsMasks, + "query": req.Query, + "limit": req.Limit, }, }) if err != nil { @@ -4265,16 +4910,19 @@ func (client *Client) SearchInstalledStickerSets(isMasks bool, query string, lim return UnmarshalStickerSets(result.Data) } +type SearchStickerSetsRequest struct { + // Query to search for + Query string `json:"query"` +} + // Searches for ordinary sticker sets by looking for specified query in their title and name. Excludes installed sticker sets from the results -// -// @param query Query to search for -func (client *Client) SearchStickerSets(query string) (*StickerSets, error) { +func (client *Client) SearchStickerSets(req *SearchStickerSetsRequest) (*StickerSets, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchStickerSets", }, Data: map[string]interface{}{ - "query": query, + "query": req.Query, }, }) if err != nil { @@ -4288,20 +4936,25 @@ func (client *Client) SearchStickerSets(query string) (*StickerSets, error) { return UnmarshalStickerSets(result.Data) } +type ChangeStickerSetRequest struct { + // Identifier of the sticker set + SetId JsonInt64 `json:"set_id"` + // The new value of is_installed + IsInstalled bool `json:"is_installed"` + // The new value of is_archived. A sticker set can't be installed and archived simultaneously + IsArchived bool `json:"is_archived"` +} + // Installs/uninstalls or activates/archives a sticker set -// -// @param setId Identifier of the sticker set -// @param isInstalled The new value of is_installed -// @param isArchived The new value of is_archived. A sticker set can't be installed and archived simultaneously -func (client *Client) ChangeStickerSet(setId JsonInt64, isInstalled bool, isArchived bool) (*Ok, error) { +func (client *Client) ChangeStickerSet(req *ChangeStickerSetRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "changeStickerSet", }, Data: map[string]interface{}{ - "set_id": setId, - "is_installed": isInstalled, - "is_archived": isArchived, + "set_id": req.SetId, + "is_installed": req.IsInstalled, + "is_archived": req.IsArchived, }, }) if err != nil { @@ -4315,16 +4968,19 @@ func (client *Client) ChangeStickerSet(setId JsonInt64, isInstalled bool, isArch return UnmarshalOk(result.Data) } +type ViewTrendingStickerSetsRequest struct { + // Identifiers of viewed trending sticker sets + StickerSetIds []JsonInt64 `json:"sticker_set_ids"` +} + // Informs the server that some trending sticker sets have been viewed by the user -// -// @param stickerSetIds Identifiers of viewed trending sticker sets -func (client *Client) ViewTrendingStickerSets(stickerSetIds []JsonInt64) (*Ok, error) { +func (client *Client) ViewTrendingStickerSets(req *ViewTrendingStickerSetsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "viewTrendingStickerSets", }, Data: map[string]interface{}{ - "sticker_set_ids": stickerSetIds, + "sticker_set_ids": req.StickerSetIds, }, }) if err != nil { @@ -4338,18 +4994,22 @@ func (client *Client) ViewTrendingStickerSets(stickerSetIds []JsonInt64) (*Ok, e return UnmarshalOk(result.Data) } +type ReorderInstalledStickerSetsRequest struct { + // Pass true to change the order of mask sticker sets; pass false to change the order of ordinary sticker sets + IsMasks bool `json:"is_masks"` + // Identifiers of installed sticker sets in the new correct order + StickerSetIds []JsonInt64 `json:"sticker_set_ids"` +} + // Changes the order of installed sticker sets -// -// @param isMasks Pass true to change the order of mask sticker sets; pass false to change the order of ordinary sticker sets -// @param stickerSetIds Identifiers of installed sticker sets in the new correct order -func (client *Client) ReorderInstalledStickerSets(isMasks bool, stickerSetIds []JsonInt64) (*Ok, error) { +func (client *Client) ReorderInstalledStickerSets(req *ReorderInstalledStickerSetsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "reorderInstalledStickerSets", }, Data: map[string]interface{}{ - "is_masks": isMasks, - "sticker_set_ids": stickerSetIds, + "is_masks": req.IsMasks, + "sticker_set_ids": req.StickerSetIds, }, }) if err != nil { @@ -4363,16 +5023,19 @@ func (client *Client) ReorderInstalledStickerSets(isMasks bool, stickerSetIds [] return UnmarshalOk(result.Data) } +type GetRecentStickersRequest struct { + // Pass true to return stickers and masks that were recently attached to photos or video files; pass false to return recently sent stickers + IsAttached bool `json:"is_attached"` +} + // Returns a list of recently used stickers -// -// @param isAttached Pass true to return stickers and masks that were recently attached to photos or video files; pass false to return recently sent stickers -func (client *Client) GetRecentStickers(isAttached bool) (*Stickers, error) { +func (client *Client) GetRecentStickers(req *GetRecentStickersRequest) (*Stickers, error) { result, err := client.Send(Request{ meta: meta{ Type: "getRecentStickers", }, Data: map[string]interface{}{ - "is_attached": isAttached, + "is_attached": req.IsAttached, }, }) if err != nil { @@ -4386,18 +5049,22 @@ func (client *Client) GetRecentStickers(isAttached bool) (*Stickers, error) { return UnmarshalStickers(result.Data) } +type AddRecentStickerRequest struct { + // Pass true to add the sticker to the list of stickers recently attached to photo or video files; pass false to add the sticker to the list of recently sent stickers + IsAttached bool `json:"is_attached"` + // Sticker file to add + Sticker InputFile `json:"sticker"` +} + // Manually adds a new sticker to the list of recently used stickers. The new sticker is added to the top of the list. If the sticker was already in the list, it is removed from the list first. Only stickers belonging to a sticker set can be added to this list -// -// @param isAttached Pass true to add the sticker to the list of stickers recently attached to photo or video files; pass false to add the sticker to the list of recently sent stickers -// @param sticker Sticker file to add -func (client *Client) AddRecentSticker(isAttached bool, sticker InputFile) (*Stickers, error) { +func (client *Client) AddRecentSticker(req *AddRecentStickerRequest) (*Stickers, error) { result, err := client.Send(Request{ meta: meta{ Type: "addRecentSticker", }, Data: map[string]interface{}{ - "is_attached": isAttached, - "sticker": sticker, + "is_attached": req.IsAttached, + "sticker": req.Sticker, }, }) if err != nil { @@ -4411,18 +5078,22 @@ func (client *Client) AddRecentSticker(isAttached bool, sticker InputFile) (*Sti return UnmarshalStickers(result.Data) } +type RemoveRecentStickerRequest struct { + // Pass true to remove the sticker from the list of stickers recently attached to photo or video files; pass false to remove the sticker from the list of recently sent stickers + IsAttached bool `json:"is_attached"` + // Sticker file to delete + Sticker InputFile `json:"sticker"` +} + // Removes a sticker from the list of recently used stickers -// -// @param isAttached Pass true to remove the sticker from the list of stickers recently attached to photo or video files; pass false to remove the sticker from the list of recently sent stickers -// @param sticker Sticker file to delete -func (client *Client) RemoveRecentSticker(isAttached bool, sticker InputFile) (*Ok, error) { +func (client *Client) RemoveRecentSticker(req *RemoveRecentStickerRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeRecentSticker", }, Data: map[string]interface{}{ - "is_attached": isAttached, - "sticker": sticker, + "is_attached": req.IsAttached, + "sticker": req.Sticker, }, }) if err != nil { @@ -4436,16 +5107,19 @@ func (client *Client) RemoveRecentSticker(isAttached bool, sticker InputFile) (* return UnmarshalOk(result.Data) } +type ClearRecentStickersRequest struct { + // Pass true to clear the list of stickers recently attached to photo or video files; pass false to clear the list of recently sent stickers + IsAttached bool `json:"is_attached"` +} + // Clears the list of recently used stickers -// -// @param isAttached Pass true to clear the list of stickers recently attached to photo or video files; pass false to clear the list of recently sent stickers -func (client *Client) ClearRecentStickers(isAttached bool) (*Ok, error) { +func (client *Client) ClearRecentStickers(req *ClearRecentStickersRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "clearRecentStickers", }, Data: map[string]interface{}{ - "is_attached": isAttached, + "is_attached": req.IsAttached, }, }) if err != nil { @@ -4478,16 +5152,19 @@ func (client *Client) GetFavoriteStickers() (*Stickers, error) { return UnmarshalStickers(result.Data) } +type AddFavoriteStickerRequest struct { + // Sticker file to add + Sticker InputFile `json:"sticker"` +} + // Adds a new sticker to the list of favorite stickers. The new sticker is added to the top of the list. If the sticker was already in the list, it is removed from the list first. Only stickers belonging to a sticker set can be added to this list -// -// @param sticker Sticker file to add -func (client *Client) AddFavoriteSticker(sticker InputFile) (*Ok, error) { +func (client *Client) AddFavoriteSticker(req *AddFavoriteStickerRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addFavoriteSticker", }, Data: map[string]interface{}{ - "sticker": sticker, + "sticker": req.Sticker, }, }) if err != nil { @@ -4501,16 +5178,19 @@ func (client *Client) AddFavoriteSticker(sticker InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type RemoveFavoriteStickerRequest struct { + // Sticker file to delete from the list + Sticker InputFile `json:"sticker"` +} + // Removes a sticker from the list of favorite stickers -// -// @param sticker Sticker file to delete from the list -func (client *Client) RemoveFavoriteSticker(sticker InputFile) (*Ok, error) { +func (client *Client) RemoveFavoriteSticker(req *RemoveFavoriteStickerRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeFavoriteSticker", }, Data: map[string]interface{}{ - "sticker": sticker, + "sticker": req.Sticker, }, }) if err != nil { @@ -4524,16 +5204,19 @@ func (client *Client) RemoveFavoriteSticker(sticker InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetStickerEmojisRequest struct { + // Sticker file identifier + Sticker InputFile `json:"sticker"` +} + // Returns emoji corresponding to a sticker -// -// @param sticker Sticker file identifier -func (client *Client) GetStickerEmojis(sticker InputFile) (*StickerEmojis, error) { +func (client *Client) GetStickerEmojis(req *GetStickerEmojisRequest) (*StickerEmojis, error) { result, err := client.Send(Request{ meta: meta{ Type: "getStickerEmojis", }, Data: map[string]interface{}{ - "sticker": sticker, + "sticker": req.Sticker, }, }) if err != nil { @@ -4566,16 +5249,19 @@ func (client *Client) GetSavedAnimations() (*Animations, error) { return UnmarshalAnimations(result.Data) } +type AddSavedAnimationRequest struct { + // The animation file to be added. Only animations known to the server (i.e. successfully sent via a message) can be added to the list + Animation InputFile `json:"animation"` +} + // Manually adds a new animation to the list of saved animations. The new animation is added to the beginning of the list. If the animation was already in the list, it is removed first. Only non-secret video animations with MIME type "video/mp4" can be added to the list -// -// @param animation The animation file to be added. Only animations known to the server (i.e. successfully sent via a message) can be added to the list -func (client *Client) AddSavedAnimation(animation InputFile) (*Ok, error) { +func (client *Client) AddSavedAnimation(req *AddSavedAnimationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addSavedAnimation", }, Data: map[string]interface{}{ - "animation": animation, + "animation": req.Animation, }, }) if err != nil { @@ -4589,16 +5275,19 @@ func (client *Client) AddSavedAnimation(animation InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type RemoveSavedAnimationRequest struct { + // Animation file to be removed + Animation InputFile `json:"animation"` +} + // Removes an animation from the list of saved animations -// -// @param animation Animation file to be removed -func (client *Client) RemoveSavedAnimation(animation InputFile) (*Ok, error) { +func (client *Client) RemoveSavedAnimation(req *RemoveSavedAnimationRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeSavedAnimation", }, Data: map[string]interface{}{ - "animation": animation, + "animation": req.Animation, }, }) if err != nil { @@ -4631,18 +5320,22 @@ func (client *Client) GetRecentInlineBots() (*Users, error) { return UnmarshalUsers(result.Data) } +type SearchHashtagsRequest struct { + // Hashtag prefix to search for + Prefix string `json:"prefix"` + // Maximum number of hashtags to be returned + Limit int32 `json:"limit"` +} + // Searches for recently used hashtags by their prefix -// -// @param prefix Hashtag prefix to search for -// @param limit Maximum number of hashtags to be returned -func (client *Client) SearchHashtags(prefix string, limit int32) (*Hashtags, error) { +func (client *Client) SearchHashtags(req *SearchHashtagsRequest) (*Hashtags, error) { result, err := client.Send(Request{ meta: meta{ Type: "searchHashtags", }, Data: map[string]interface{}{ - "prefix": prefix, - "limit": limit, + "prefix": req.Prefix, + "limit": req.Limit, }, }) if err != nil { @@ -4656,16 +5349,19 @@ func (client *Client) SearchHashtags(prefix string, limit int32) (*Hashtags, err return UnmarshalHashtags(result.Data) } +type RemoveRecentHashtagRequest struct { + // Hashtag to delete + Hashtag string `json:"hashtag"` +} + // Removes a hashtag from the list of recently used hashtags -// -// @param hashtag Hashtag to delete -func (client *Client) RemoveRecentHashtag(hashtag string) (*Ok, error) { +func (client *Client) RemoveRecentHashtag(req *RemoveRecentHashtagRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeRecentHashtag", }, Data: map[string]interface{}{ - "hashtag": hashtag, + "hashtag": req.Hashtag, }, }) if err != nil { @@ -4679,16 +5375,19 @@ func (client *Client) RemoveRecentHashtag(hashtag string) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetWebPagePreviewRequest struct { + // Message text with formatting + Text *FormattedText `json:"text"` +} + // Returns a web page preview by the text of the message. Do not call this function too often. Returns a 404 error if the web page has no preview -// -// @param text Message text with formatting -func (client *Client) GetWebPagePreview(text *FormattedText) (*WebPage, error) { +func (client *Client) GetWebPagePreview(req *GetWebPagePreviewRequest) (*WebPage, error) { result, err := client.Send(Request{ meta: meta{ Type: "getWebPagePreview", }, Data: map[string]interface{}{ - "text": text, + "text": req.Text, }, }) if err != nil { @@ -4702,18 +5401,22 @@ func (client *Client) GetWebPagePreview(text *FormattedText) (*WebPage, error) { return UnmarshalWebPage(result.Data) } +type GetWebPageInstantViewRequest struct { + // The web page URL + Url string `json:"url"` + // If true, the full instant view for the web page will be returned + ForceFull bool `json:"force_full"` +} + // Returns an instant view version of a web page if available. Returns a 404 error if the web page has no instant view page -// -// @param url The web page URL -// @param forceFull If true, the full instant view for the web page will be returned -func (client *Client) GetWebPageInstantView(url string, forceFull bool) (*WebPageInstantView, error) { +func (client *Client) GetWebPageInstantView(req *GetWebPageInstantViewRequest) (*WebPageInstantView, error) { result, err := client.Send(Request{ meta: meta{ Type: "getWebPageInstantView", }, Data: map[string]interface{}{ - "url": url, - "force_full": forceFull, + "url": req.Url, + "force_full": req.ForceFull, }, }) if err != nil { @@ -4727,16 +5430,19 @@ func (client *Client) GetWebPageInstantView(url string, forceFull bool) (*WebPag return UnmarshalWebPageInstantView(result.Data) } +type SetProfilePhotoRequest struct { + // Profile photo to set. inputFileId and inputFileRemote may still be unsupported + Photo InputFile `json:"photo"` +} + // Uploads a new profile photo for the current user. If something changes, updateUser will be sent -// -// @param photo Profile photo to set. inputFileId and inputFileRemote may still be unsupported -func (client *Client) SetProfilePhoto(photo InputFile) (*Ok, error) { +func (client *Client) SetProfilePhoto(req *SetProfilePhotoRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setProfilePhoto", }, Data: map[string]interface{}{ - "photo": photo, + "photo": req.Photo, }, }) if err != nil { @@ -4750,16 +5456,19 @@ func (client *Client) SetProfilePhoto(photo InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type DeleteProfilePhotoRequest struct { + // Identifier of the profile photo to delete + ProfilePhotoId JsonInt64 `json:"profile_photo_id"` +} + // Deletes a profile photo. If something changes, updateUser will be sent -// -// @param profilePhotoId Identifier of the profile photo to delete -func (client *Client) DeleteProfilePhoto(profilePhotoId JsonInt64) (*Ok, error) { +func (client *Client) DeleteProfilePhoto(req *DeleteProfilePhotoRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteProfilePhoto", }, Data: map[string]interface{}{ - "profile_photo_id": profilePhotoId, + "profile_photo_id": req.ProfilePhotoId, }, }) if err != nil { @@ -4773,18 +5482,22 @@ func (client *Client) DeleteProfilePhoto(profilePhotoId JsonInt64) (*Ok, error) return UnmarshalOk(result.Data) } +type SetNameRequest struct { + // The new value of the first name for the user; 1-255 characters + FirstName string `json:"first_name"` + // The new value of the optional last name for the user; 0-255 characters + LastName string `json:"last_name"` +} + // Changes the first and last name of the current user. If something changes, updateUser will be sent -// -// @param firstName The new value of the first name for the user; 1-255 characters -// @param lastName The new value of the optional last name for the user; 0-255 characters -func (client *Client) SetName(firstName string, lastName string) (*Ok, error) { +func (client *Client) SetName(req *SetNameRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setName", }, Data: map[string]interface{}{ - "first_name": firstName, - "last_name": lastName, + "first_name": req.FirstName, + "last_name": req.LastName, }, }) if err != nil { @@ -4798,16 +5511,19 @@ func (client *Client) SetName(firstName string, lastName string) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetBioRequest struct { + // The new value of the user bio; 0-70 characters without line feeds + Bio string `json:"bio"` +} + // Changes the bio of the current user -// -// @param bio The new value of the user bio; 0-70 characters without line feeds -func (client *Client) SetBio(bio string) (*Ok, error) { +func (client *Client) SetBio(req *SetBioRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setBio", }, Data: map[string]interface{}{ - "bio": bio, + "bio": req.Bio, }, }) if err != nil { @@ -4821,16 +5537,19 @@ func (client *Client) SetBio(bio string) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetUsernameRequest struct { + // The new value of the username. Use an empty string to remove the username + Username string `json:"username"` +} + // Changes the username of the current user. If something changes, updateUser will be sent -// -// @param username The new value of the username. Use an empty string to remove the username -func (client *Client) SetUsername(username string) (*Ok, error) { +func (client *Client) SetUsername(req *SetUsernameRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setUsername", }, Data: map[string]interface{}{ - "username": username, + "username": req.Username, }, }) if err != nil { @@ -4844,20 +5563,25 @@ func (client *Client) SetUsername(username string) (*Ok, error) { return UnmarshalOk(result.Data) } +type ChangePhoneNumberRequest struct { + // The new phone number of the user in international format + PhoneNumber string `json:"phone_number"` + // Pass true if the code can be sent via flash call to the specified phone number + AllowFlashCall bool `json:"allow_flash_call"` + // Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false + IsCurrentPhoneNumber bool `json:"is_current_phone_number"` +} + // Changes the phone number of the user and sends an authentication code to the user's new phone number. On success, returns information about the sent code -// -// @param phoneNumber The new phone number of the user in international format -// @param allowFlashCall Pass true if the code can be sent via flash call to the specified phone number -// @param isCurrentPhoneNumber Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false -func (client *Client) ChangePhoneNumber(phoneNumber string, allowFlashCall bool, isCurrentPhoneNumber bool) (*AuthenticationCodeInfo, error) { +func (client *Client) ChangePhoneNumber(req *ChangePhoneNumberRequest) (*AuthenticationCodeInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "changePhoneNumber", }, Data: map[string]interface{}{ - "phone_number": phoneNumber, - "allow_flash_call": allowFlashCall, - "is_current_phone_number": isCurrentPhoneNumber, + "phone_number": req.PhoneNumber, + "allow_flash_call": req.AllowFlashCall, + "is_current_phone_number": req.IsCurrentPhoneNumber, }, }) if err != nil { @@ -4890,16 +5614,19 @@ func (client *Client) ResendChangePhoneNumberCode() (*AuthenticationCodeInfo, er return UnmarshalAuthenticationCodeInfo(result.Data) } +type CheckChangePhoneNumberCodeRequest struct { + // Verification code received by SMS, phone call or flash call + Code string `json:"code"` +} + // Checks the authentication code sent to confirm a new phone number of the user -// -// @param code Verification code received by SMS, phone call or flash call -func (client *Client) CheckChangePhoneNumberCode(code string) (*Ok, error) { +func (client *Client) CheckChangePhoneNumberCode(req *CheckChangePhoneNumberCodeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkChangePhoneNumberCode", }, Data: map[string]interface{}{ - "code": code, + "code": req.Code, }, }) if err != nil { @@ -4932,16 +5659,19 @@ func (client *Client) GetActiveSessions() (*Sessions, error) { return UnmarshalSessions(result.Data) } +type TerminateSessionRequest struct { + // Session identifier + SessionId JsonInt64 `json:"session_id"` +} + // Terminates a session of the current user -// -// @param sessionId Session identifier -func (client *Client) TerminateSession(sessionId JsonInt64) (*Ok, error) { +func (client *Client) TerminateSession(req *TerminateSessionRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "terminateSession", }, Data: map[string]interface{}{ - "session_id": sessionId, + "session_id": req.SessionId, }, }) if err != nil { @@ -4993,16 +5723,19 @@ func (client *Client) GetConnectedWebsites() (*ConnectedWebsites, error) { return UnmarshalConnectedWebsites(result.Data) } +type DisconnectWebsiteRequest struct { + // Website identifier + WebsiteId JsonInt64 `json:"website_id"` +} + // Disconnects website from the current user's Telegram account -// -// @param websiteId Website identifier -func (client *Client) DisconnectWebsite(websiteId JsonInt64) (*Ok, error) { +func (client *Client) DisconnectWebsite(req *DisconnectWebsiteRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "disconnectWebsite", }, Data: map[string]interface{}{ - "website_id": websiteId, + "website_id": req.WebsiteId, }, }) if err != nil { @@ -5035,18 +5768,22 @@ func (client *Client) DisconnectAllWebsites() (*Ok, error) { return UnmarshalOk(result.Data) } +type ToggleBasicGroupAdministratorsRequest struct { + // Identifier of the basic group + BasicGroupId int32 `json:"basic_group_id"` + // New value of everyone_is_administrator + EveryoneIsAdministrator bool `json:"everyone_is_administrator"` +} + // Toggles the "All members are admins" setting in basic groups; requires creator privileges in the group -// -// @param basicGroupId Identifier of the basic group -// @param everyoneIsAdministrator New value of everyone_is_administrator -func (client *Client) ToggleBasicGroupAdministrators(basicGroupId int32, everyoneIsAdministrator bool) (*Ok, error) { +func (client *Client) ToggleBasicGroupAdministrators(req *ToggleBasicGroupAdministratorsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleBasicGroupAdministrators", }, Data: map[string]interface{}{ - "basic_group_id": basicGroupId, - "everyone_is_administrator": everyoneIsAdministrator, + "basic_group_id": req.BasicGroupId, + "everyone_is_administrator": req.EveryoneIsAdministrator, }, }) if err != nil { @@ -5060,18 +5797,22 @@ func (client *Client) ToggleBasicGroupAdministrators(basicGroupId int32, everyon return UnmarshalOk(result.Data) } +type SetSupergroupUsernameRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` + // New value of the username. Use an empty string to remove the username + Username string `json:"username"` +} + // Changes the username of a supergroup or channel, requires creator privileges in the supergroup or channel -// -// @param supergroupId Identifier of the supergroup or channel -// @param username New value of the username. Use an empty string to remove the username -func (client *Client) SetSupergroupUsername(supergroupId int32, username string) (*Ok, error) { +func (client *Client) SetSupergroupUsername(req *SetSupergroupUsernameRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setSupergroupUsername", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "username": username, + "supergroup_id": req.SupergroupId, + "username": req.Username, }, }) if err != nil { @@ -5085,18 +5826,22 @@ func (client *Client) SetSupergroupUsername(supergroupId int32, username string) return UnmarshalOk(result.Data) } +type SetSupergroupStickerSetRequest struct { + // Identifier of the supergroup + SupergroupId int32 `json:"supergroup_id"` + // New value of the supergroup sticker set identifier. Use 0 to remove the supergroup sticker set + StickerSetId JsonInt64 `json:"sticker_set_id"` +} + // Changes the sticker set of a supergroup; requires appropriate rights in the supergroup -// -// @param supergroupId Identifier of the supergroup -// @param stickerSetId New value of the supergroup sticker set identifier. Use 0 to remove the supergroup sticker set -func (client *Client) SetSupergroupStickerSet(supergroupId int32, stickerSetId JsonInt64) (*Ok, error) { +func (client *Client) SetSupergroupStickerSet(req *SetSupergroupStickerSetRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setSupergroupStickerSet", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "sticker_set_id": stickerSetId, + "supergroup_id": req.SupergroupId, + "sticker_set_id": req.StickerSetId, }, }) if err != nil { @@ -5110,18 +5855,22 @@ func (client *Client) SetSupergroupStickerSet(supergroupId int32, stickerSetId J return UnmarshalOk(result.Data) } +type ToggleSupergroupInvitesRequest struct { + // Identifier of the supergroup + SupergroupId int32 `json:"supergroup_id"` + // New value of anyone_can_invite + AnyoneCanInvite bool `json:"anyone_can_invite"` +} + // Toggles whether all members of a supergroup can add new members; requires appropriate administrator rights in the supergroup. -// -// @param supergroupId Identifier of the supergroup -// @param anyoneCanInvite New value of anyone_can_invite -func (client *Client) ToggleSupergroupInvites(supergroupId int32, anyoneCanInvite bool) (*Ok, error) { +func (client *Client) ToggleSupergroupInvites(req *ToggleSupergroupInvitesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleSupergroupInvites", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "anyone_can_invite": anyoneCanInvite, + "supergroup_id": req.SupergroupId, + "anyone_can_invite": req.AnyoneCanInvite, }, }) if err != nil { @@ -5135,18 +5884,22 @@ func (client *Client) ToggleSupergroupInvites(supergroupId int32, anyoneCanInvit return UnmarshalOk(result.Data) } +type ToggleSupergroupSignMessagesRequest struct { + // Identifier of the channel + SupergroupId int32 `json:"supergroup_id"` + // New value of sign_messages + SignMessages bool `json:"sign_messages"` +} + // Toggles sender signatures messages sent in a channel; requires appropriate administrator rights in the channel. -// -// @param supergroupId Identifier of the channel -// @param signMessages New value of sign_messages -func (client *Client) ToggleSupergroupSignMessages(supergroupId int32, signMessages bool) (*Ok, error) { +func (client *Client) ToggleSupergroupSignMessages(req *ToggleSupergroupSignMessagesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleSupergroupSignMessages", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "sign_messages": signMessages, + "supergroup_id": req.SupergroupId, + "sign_messages": req.SignMessages, }, }) if err != nil { @@ -5160,18 +5913,22 @@ func (client *Client) ToggleSupergroupSignMessages(supergroupId int32, signMessa return UnmarshalOk(result.Data) } +type ToggleSupergroupIsAllHistoryAvailableRequest struct { + // The identifier of the supergroup + SupergroupId int32 `json:"supergroup_id"` + // The new value of is_all_history_available + IsAllHistoryAvailable bool `json:"is_all_history_available"` +} + // Toggles whether the message history of a supergroup is available to new members; requires appropriate administrator rights in the supergroup. -// -// @param supergroupId The identifier of the supergroup -// @param isAllHistoryAvailable The new value of is_all_history_available -func (client *Client) ToggleSupergroupIsAllHistoryAvailable(supergroupId int32, isAllHistoryAvailable bool) (*Ok, error) { +func (client *Client) ToggleSupergroupIsAllHistoryAvailable(req *ToggleSupergroupIsAllHistoryAvailableRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "toggleSupergroupIsAllHistoryAvailable", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "is_all_history_available": isAllHistoryAvailable, + "supergroup_id": req.SupergroupId, + "is_all_history_available": req.IsAllHistoryAvailable, }, }) if err != nil { @@ -5185,18 +5942,22 @@ func (client *Client) ToggleSupergroupIsAllHistoryAvailable(supergroupId int32, return UnmarshalOk(result.Data) } +type SetSupergroupDescriptionRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` + // New supergroup or channel description; 0-255 characters + Description string `json:"description"` +} + // Changes information about a supergroup or channel; requires appropriate administrator rights -// -// @param supergroupId Identifier of the supergroup or channel -// @param description New supergroup or channel description; 0-255 characters -func (client *Client) SetSupergroupDescription(supergroupId int32, description string) (*Ok, error) { +func (client *Client) SetSupergroupDescription(req *SetSupergroupDescriptionRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setSupergroupDescription", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "description": description, + "supergroup_id": req.SupergroupId, + "description": req.Description, }, }) if err != nil { @@ -5210,20 +5971,25 @@ func (client *Client) SetSupergroupDescription(supergroupId int32, description s return UnmarshalOk(result.Data) } +type PinSupergroupMessageRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` + // Identifier of the new pinned message + MessageId int64 `json:"message_id"` + // True, if there should be no notification about the pinned message + DisableNotification bool `json:"disable_notification"` +} + // Pins a message in a supergroup or channel; requires appropriate administrator rights in the supergroup or channel -// -// @param supergroupId Identifier of the supergroup or channel -// @param messageId Identifier of the new pinned message -// @param disableNotification True, if there should be no notification about the pinned message -func (client *Client) PinSupergroupMessage(supergroupId int32, messageId int64, disableNotification bool) (*Ok, error) { +func (client *Client) PinSupergroupMessage(req *PinSupergroupMessageRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "pinSupergroupMessage", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "message_id": messageId, - "disable_notification": disableNotification, + "supergroup_id": req.SupergroupId, + "message_id": req.MessageId, + "disable_notification": req.DisableNotification, }, }) if err != nil { @@ -5237,16 +6003,19 @@ func (client *Client) PinSupergroupMessage(supergroupId int32, messageId int64, return UnmarshalOk(result.Data) } +type UnpinSupergroupMessageRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` +} + // Removes the pinned message from a supergroup or channel; requires appropriate administrator rights in the supergroup or channel -// -// @param supergroupId Identifier of the supergroup or channel -func (client *Client) UnpinSupergroupMessage(supergroupId int32) (*Ok, error) { +func (client *Client) UnpinSupergroupMessage(req *UnpinSupergroupMessageRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "unpinSupergroupMessage", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, + "supergroup_id": req.SupergroupId, }, }) if err != nil { @@ -5260,20 +6029,25 @@ func (client *Client) UnpinSupergroupMessage(supergroupId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type ReportSupergroupSpamRequest struct { + // Supergroup identifier + SupergroupId int32 `json:"supergroup_id"` + // User identifier + UserId int32 `json:"user_id"` + // Identifiers of messages sent in the supergroup by the user. This list must be non-empty + MessageIds []int64 `json:"message_ids"` +} + // Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup -// -// @param supergroupId Supergroup identifier -// @param userId User identifier -// @param messageIds Identifiers of messages sent in the supergroup by the user. This list must be non-empty -func (client *Client) ReportSupergroupSpam(supergroupId int32, userId int32, messageIds []int64) (*Ok, error) { +func (client *Client) ReportSupergroupSpam(req *ReportSupergroupSpamRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "reportSupergroupSpam", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "user_id": userId, - "message_ids": messageIds, + "supergroup_id": req.SupergroupId, + "user_id": req.UserId, + "message_ids": req.MessageIds, }, }) if err != nil { @@ -5287,22 +6061,28 @@ func (client *Client) ReportSupergroupSpam(supergroupId int32, userId int32, mes return UnmarshalOk(result.Data) } +type GetSupergroupMembersRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` + // The type of users to return. By default, supergroupMembersRecent + Filter SupergroupMembersFilter `json:"filter"` + // Number of users to skip + Offset int32 `json:"offset"` + // The maximum number of users be returned; up to 200 + Limit int32 `json:"limit"` +} + // Returns information about members or banned users in a supergroup or channel. Can be used only if SupergroupFullInfo.can_get_members == true; additionally, administrator privileges may be required for some filters -// -// @param supergroupId Identifier of the supergroup or channel -// @param filter The type of users to return. By default, supergroupMembersRecent -// @param offset Number of users to skip -// @param limit The maximum number of users be returned; up to 200 -func (client *Client) GetSupergroupMembers(supergroupId int32, filter SupergroupMembersFilter, offset int32, limit int32) (*ChatMembers, error) { +func (client *Client) GetSupergroupMembers(req *GetSupergroupMembersRequest) (*ChatMembers, error) { result, err := client.Send(Request{ meta: meta{ Type: "getSupergroupMembers", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, - "filter": filter, - "offset": offset, - "limit": limit, + "supergroup_id": req.SupergroupId, + "filter": req.Filter, + "offset": req.Offset, + "limit": req.Limit, }, }) if err != nil { @@ -5316,16 +6096,19 @@ func (client *Client) GetSupergroupMembers(supergroupId int32, filter Supergroup return UnmarshalChatMembers(result.Data) } +type DeleteSupergroupRequest struct { + // Identifier of the supergroup or channel + SupergroupId int32 `json:"supergroup_id"` +} + // Deletes a supergroup or channel along with all messages in the corresponding chat. This will release the supergroup or channel username and remove all members; requires creator privileges in the supergroup or channel. Chats with more than 1000 members can't be deleted using this method -// -// @param supergroupId Identifier of the supergroup or channel -func (client *Client) DeleteSupergroup(supergroupId int32) (*Ok, error) { +func (client *Client) DeleteSupergroup(req *DeleteSupergroupRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteSupergroup", }, Data: map[string]interface{}{ - "supergroup_id": supergroupId, + "supergroup_id": req.SupergroupId, }, }) if err != nil { @@ -5339,16 +6122,19 @@ func (client *Client) DeleteSupergroup(supergroupId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type CloseSecretChatRequest struct { + // Secret chat identifier + SecretChatId int32 `json:"secret_chat_id"` +} + // Closes a secret chat, effectively transfering its state to secretChatStateClosed -// -// @param secretChatId Secret chat identifier -func (client *Client) CloseSecretChat(secretChatId int32) (*Ok, error) { +func (client *Client) CloseSecretChat(req *CloseSecretChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "closeSecretChat", }, Data: map[string]interface{}{ - "secret_chat_id": secretChatId, + "secret_chat_id": req.SecretChatId, }, }) if err != nil { @@ -5362,26 +6148,34 @@ func (client *Client) CloseSecretChat(secretChatId int32) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetChatEventLogRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // Search query by which to filter events + Query string `json:"query"` + // Identifier of an event from which to return results. Use 0 to get results from the latest events + FromEventId JsonInt64 `json:"from_event_id"` + // Maximum number of events to return; up to 100 + Limit int32 `json:"limit"` + // The types of events to return. By default, all types will be returned + Filters *ChatEventLogFilters `json:"filters"` + // User identifiers by which to filter events. By default, events relating to all users will be returned + UserIds []int32 `json:"user_ids"` +} + // Returns a list of service actions taken by chat members and administrators in the last 48 hours. Available only in supergroups and channels. Requires administrator rights. Returns results in reverse chronological order (i. e., in order of decreasing event_id) -// -// @param chatId Chat identifier -// @param query Search query by which to filter events -// @param fromEventId Identifier of an event from which to return results. Use 0 to get results from the latest events -// @param limit Maximum number of events to return; up to 100 -// @param filters The types of events to return. By default, all types will be returned -// @param userIds User identifiers by which to filter events. By default, events relating to all users will be returned -func (client *Client) GetChatEventLog(chatId int64, query string, fromEventId JsonInt64, limit int32, filters *ChatEventLogFilters, userIds []int32) (*ChatEvents, error) { +func (client *Client) GetChatEventLog(req *GetChatEventLogRequest) (*ChatEvents, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatEventLog", }, Data: map[string]interface{}{ - "chat_id": chatId, - "query": query, - "from_event_id": fromEventId, - "limit": limit, - "filters": filters, - "user_ids": userIds, + "chat_id": req.ChatId, + "query": req.Query, + "from_event_id": req.FromEventId, + "limit": req.Limit, + "filters": req.Filters, + "user_ids": req.UserIds, }, }) if err != nil { @@ -5395,18 +6189,22 @@ func (client *Client) GetChatEventLog(chatId int64, query string, fromEventId Js return UnmarshalChatEvents(result.Data) } +type GetPaymentFormRequest struct { + // Chat identifier of the Invoice message + ChatId int64 `json:"chat_id"` + // Message identifier + MessageId int64 `json:"message_id"` +} + // Returns an invoice payment form. This method should be called when the user presses inlineKeyboardButtonBuy -// -// @param chatId Chat identifier of the Invoice message -// @param messageId Message identifier -func (client *Client) GetPaymentForm(chatId int64, messageId int64) (*PaymentForm, error) { +func (client *Client) GetPaymentForm(req *GetPaymentFormRequest) (*PaymentForm, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPaymentForm", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -5420,22 +6218,28 @@ func (client *Client) GetPaymentForm(chatId int64, messageId int64) (*PaymentFor return UnmarshalPaymentForm(result.Data) } +type ValidateOrderInfoRequest struct { + // Chat identifier of the Invoice message + ChatId int64 `json:"chat_id"` + // Message identifier + MessageId int64 `json:"message_id"` + // The order information, provided by the user + OrderInfo *OrderInfo `json:"order_info"` + // True, if the order information can be saved + AllowSave bool `json:"allow_save"` +} + // Validates the order information provided by a user and returns the available shipping options for a flexible invoice -// -// @param chatId Chat identifier of the Invoice message -// @param messageId Message identifier -// @param orderInfo The order information, provided by the user -// @param allowSave True, if the order information can be saved -func (client *Client) ValidateOrderInfo(chatId int64, messageId int64, orderInfo *OrderInfo, allowSave bool) (*ValidatedOrderInfo, error) { +func (client *Client) ValidateOrderInfo(req *ValidateOrderInfoRequest) (*ValidatedOrderInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "validateOrderInfo", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "order_info": orderInfo, - "allow_save": allowSave, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "order_info": req.OrderInfo, + "allow_save": req.AllowSave, }, }) if err != nil { @@ -5449,24 +6253,31 @@ func (client *Client) ValidateOrderInfo(chatId int64, messageId int64, orderInfo return UnmarshalValidatedOrderInfo(result.Data) } +type SendPaymentFormRequest struct { + // Chat identifier of the Invoice message + ChatId int64 `json:"chat_id"` + // Message identifier + MessageId int64 `json:"message_id"` + // Identifier returned by ValidateOrderInfo, or an empty string + OrderInfoId string `json:"order_info_id"` + // Identifier of a chosen shipping option, if applicable + ShippingOptionId string `json:"shipping_option_id"` + // The credentials chosen by user for payment + Credentials InputCredentials `json:"credentials"` +} + // Sends a filled-out payment form to the bot for final verification -// -// @param chatId Chat identifier of the Invoice message -// @param messageId Message identifier -// @param orderInfoId Identifier returned by ValidateOrderInfo, or an empty string -// @param shippingOptionId Identifier of a chosen shipping option, if applicable -// @param credentials The credentials chosen by user for payment -func (client *Client) SendPaymentForm(chatId int64, messageId int64, orderInfoId string, shippingOptionId string, credentials InputCredentials) (*PaymentResult, error) { +func (client *Client) SendPaymentForm(req *SendPaymentFormRequest) (*PaymentResult, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendPaymentForm", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, - "order_info_id": orderInfoId, - "shipping_option_id": shippingOptionId, - "credentials": credentials, + "chat_id": req.ChatId, + "message_id": req.MessageId, + "order_info_id": req.OrderInfoId, + "shipping_option_id": req.ShippingOptionId, + "credentials": req.Credentials, }, }) if err != nil { @@ -5480,18 +6291,22 @@ func (client *Client) SendPaymentForm(chatId int64, messageId int64, orderInfoId return UnmarshalPaymentResult(result.Data) } +type GetPaymentReceiptRequest struct { + // Chat identifier of the PaymentSuccessful message + ChatId int64 `json:"chat_id"` + // Message identifier + MessageId int64 `json:"message_id"` +} + // Returns information about a successful payment -// -// @param chatId Chat identifier of the PaymentSuccessful message -// @param messageId Message identifier -func (client *Client) GetPaymentReceipt(chatId int64, messageId int64) (*PaymentReceipt, error) { +func (client *Client) GetPaymentReceipt(req *GetPaymentReceiptRequest) (*PaymentReceipt, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPaymentReceipt", }, Data: map[string]interface{}{ - "chat_id": chatId, - "message_id": messageId, + "chat_id": req.ChatId, + "message_id": req.MessageId, }, }) if err != nil { @@ -5600,16 +6415,19 @@ func (client *Client) GetWallpapers() (*Wallpapers, error) { return UnmarshalWallpapers(result.Data) } +type GetLocalizationTargetInfoRequest struct { + // If true, returns only locally available information without sending network requests + OnlyLocal bool `json:"only_local"` +} + // Returns information about the current localization target. This is an offline request if only_local is true -// -// @param onlyLocal If true, returns only locally available information without sending network requests -func (client *Client) GetLocalizationTargetInfo(onlyLocal bool) (*LocalizationTargetInfo, error) { +func (client *Client) GetLocalizationTargetInfo(req *GetLocalizationTargetInfoRequest) (*LocalizationTargetInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "getLocalizationTargetInfo", }, Data: map[string]interface{}{ - "only_local": onlyLocal, + "only_local": req.OnlyLocal, }, }) if err != nil { @@ -5623,18 +6441,22 @@ func (client *Client) GetLocalizationTargetInfo(onlyLocal bool) (*LocalizationTa return UnmarshalLocalizationTargetInfo(result.Data) } +type GetLanguagePackStringsRequest struct { + // Language pack identifier of the strings to be returned + LanguagePackId string `json:"language_pack_id"` + // Language pack keys of the strings to be returned; leave empty to request all available strings + Keys []string `json:"keys"` +} + // Returns strings from a language pack in the current localization target by their keys -// -// @param languagePackId Language pack identifier of the strings to be returned -// @param keys Language pack keys of the strings to be returned; leave empty to request all available strings -func (client *Client) GetLanguagePackStrings(languagePackId string, keys []string) (*LanguagePackStrings, error) { +func (client *Client) GetLanguagePackStrings(req *GetLanguagePackStringsRequest) (*LanguagePackStrings, error) { result, err := client.Send(Request{ meta: meta{ Type: "getLanguagePackStrings", }, Data: map[string]interface{}{ - "language_pack_id": languagePackId, - "keys": keys, + "language_pack_id": req.LanguagePackId, + "keys": req.Keys, }, }) if err != nil { @@ -5648,18 +6470,22 @@ func (client *Client) GetLanguagePackStrings(languagePackId string, keys []strin return UnmarshalLanguagePackStrings(result.Data) } +type SetCustomLanguagePackRequest struct { + // Information about the language pack. Language pack ID must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters + Info *LanguagePackInfo `json:"info"` + // Strings of the new language pack + Strings []*LanguagePackString `json:"strings"` +} + // Adds or changes a custom language pack to the current localization target -// -// @param info Information about the language pack. Language pack ID must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters -// @param strings Strings of the new language pack -func (client *Client) SetCustomLanguagePack(info *LanguagePackInfo, strings []*LanguagePackString) (*Ok, error) { +func (client *Client) SetCustomLanguagePack(req *SetCustomLanguagePackRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setCustomLanguagePack", }, Data: map[string]interface{}{ - "info": info, - "strings": strings, + "info": req.Info, + "strings": req.Strings, }, }) if err != nil { @@ -5673,16 +6499,19 @@ func (client *Client) SetCustomLanguagePack(info *LanguagePackInfo, strings []*L return UnmarshalOk(result.Data) } +type EditCustomLanguagePackInfoRequest struct { + // New information about the custom language pack + Info *LanguagePackInfo `json:"info"` +} + // Edits information about a custom language pack in the current localization target -// -// @param info New information about the custom language pack -func (client *Client) EditCustomLanguagePackInfo(info *LanguagePackInfo) (*Ok, error) { +func (client *Client) EditCustomLanguagePackInfo(req *EditCustomLanguagePackInfoRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "editCustomLanguagePackInfo", }, Data: map[string]interface{}{ - "info": info, + "info": req.Info, }, }) if err != nil { @@ -5696,18 +6525,22 @@ func (client *Client) EditCustomLanguagePackInfo(info *LanguagePackInfo) (*Ok, e return UnmarshalOk(result.Data) } +type SetCustomLanguagePackStringRequest struct { + // Identifier of a previously added custom language pack in the current localization target + LanguagePackId string `json:"language_pack_id"` + // New language pack string + NewString *LanguagePackString `json:"new_string"` +} + // Adds, edits or deletes a string in a custom language pack -// -// @param languagePackId Identifier of a previously added custom language pack in the current localization target -// @param newString New language pack string -func (client *Client) SetCustomLanguagePackString(languagePackId string, newString *LanguagePackString) (*Ok, error) { +func (client *Client) SetCustomLanguagePackString(req *SetCustomLanguagePackStringRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setCustomLanguagePackString", }, Data: map[string]interface{}{ - "language_pack_id": languagePackId, - "new_string": newString, + "language_pack_id": req.LanguagePackId, + "new_string": req.NewString, }, }) if err != nil { @@ -5721,16 +6554,19 @@ func (client *Client) SetCustomLanguagePackString(languagePackId string, newStri return UnmarshalOk(result.Data) } +type DeleteLanguagePackRequest struct { + // Identifier of the language pack to delete + LanguagePackId string `json:"language_pack_id"` +} + // Deletes all information about a language pack in the current localization target. The language pack that is currently in use can't be deleted -// -// @param languagePackId Identifier of the language pack to delete -func (client *Client) DeleteLanguagePack(languagePackId string) (*Ok, error) { +func (client *Client) DeleteLanguagePack(req *DeleteLanguagePackRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteLanguagePack", }, Data: map[string]interface{}{ - "language_pack_id": languagePackId, + "language_pack_id": req.LanguagePackId, }, }) if err != nil { @@ -5744,18 +6580,22 @@ func (client *Client) DeleteLanguagePack(languagePackId string) (*Ok, error) { return UnmarshalOk(result.Data) } +type RegisterDeviceRequest struct { + // Device token + DeviceToken DeviceToken `json:"device_token"` + // List of at most 100 user identifiers of other users currently using the client + OtherUserIds []int32 `json:"other_user_ids"` +} + // Registers the currently used device for receiving push notifications -// -// @param deviceToken Device token -// @param otherUserIds List of at most 100 user identifiers of other users currently using the client -func (client *Client) RegisterDevice(deviceToken DeviceToken, otherUserIds []int32) (*Ok, error) { +func (client *Client) RegisterDevice(req *RegisterDeviceRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "registerDevice", }, Data: map[string]interface{}{ - "device_token": deviceToken, - "other_user_ids": otherUserIds, + "device_token": req.DeviceToken, + "other_user_ids": req.OtherUserIds, }, }) if err != nil { @@ -5769,16 +6609,19 @@ func (client *Client) RegisterDevice(deviceToken DeviceToken, otherUserIds []int return UnmarshalOk(result.Data) } +type GetRecentlyVisitedTMeUrlsRequest struct { + // Google Play referrer to identify the user + Referrer string `json:"referrer"` +} + // Returns t.me URLs recently visited by a newly registered user -// -// @param referrer Google Play referrer to identify the user -func (client *Client) GetRecentlyVisitedTMeUrls(referrer string) (*TMeUrls, error) { +func (client *Client) GetRecentlyVisitedTMeUrls(req *GetRecentlyVisitedTMeUrlsRequest) (*TMeUrls, error) { result, err := client.Send(Request{ meta: meta{ Type: "getRecentlyVisitedTMeUrls", }, Data: map[string]interface{}{ - "referrer": referrer, + "referrer": req.Referrer, }, }) if err != nil { @@ -5792,18 +6635,22 @@ func (client *Client) GetRecentlyVisitedTMeUrls(referrer string) (*TMeUrls, erro return UnmarshalTMeUrls(result.Data) } +type SetUserPrivacySettingRulesRequest struct { + // The privacy setting + Setting UserPrivacySetting `json:"setting"` + // The new privacy rules + Rules *UserPrivacySettingRules `json:"rules"` +} + // Changes user privacy settings -// -// @param setting The privacy setting -// @param rules The new privacy rules -func (client *Client) SetUserPrivacySettingRules(setting UserPrivacySetting, rules *UserPrivacySettingRules) (*Ok, error) { +func (client *Client) SetUserPrivacySettingRules(req *SetUserPrivacySettingRulesRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setUserPrivacySettingRules", }, Data: map[string]interface{}{ - "setting": setting, - "rules": rules, + "setting": req.Setting, + "rules": req.Rules, }, }) if err != nil { @@ -5817,16 +6664,19 @@ func (client *Client) SetUserPrivacySettingRules(setting UserPrivacySetting, rul return UnmarshalOk(result.Data) } +type GetUserPrivacySettingRulesRequest struct { + // The privacy setting + Setting UserPrivacySetting `json:"setting"` +} + // Returns the current privacy settings -// -// @param setting The privacy setting -func (client *Client) GetUserPrivacySettingRules(setting UserPrivacySetting) (*UserPrivacySettingRules, error) { +func (client *Client) GetUserPrivacySettingRules(req *GetUserPrivacySettingRulesRequest) (*UserPrivacySettingRules, error) { result, err := client.Send(Request{ meta: meta{ Type: "getUserPrivacySettingRules", }, Data: map[string]interface{}{ - "setting": setting, + "setting": req.Setting, }, }) if err != nil { @@ -5840,16 +6690,19 @@ func (client *Client) GetUserPrivacySettingRules(setting UserPrivacySetting) (*U return UnmarshalUserPrivacySettingRules(result.Data) } +type GetOptionRequest struct { + // The name of the option + Name string `json:"name"` +} + // Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) Can be called before authorization -// -// @param name The name of the option -func (client *Client) GetOption(name string) (OptionValue, error) { +func (client *Client) GetOption(req *GetOptionRequest) (OptionValue, error) { result, err := client.Send(Request{ meta: meta{ Type: "getOption", }, Data: map[string]interface{}{ - "name": name, + "name": req.Name, }, }) if err != nil { @@ -5878,18 +6731,22 @@ func (client *Client) GetOption(name string) (OptionValue, error) { } } +type SetOptionRequest struct { + // The name of the option + Name string `json:"name"` + // The new value of the option + Value OptionValue `json:"value"` +} + // Sets the value of an option. (Check the list of available options on https://core.telegram.org/tdlib/options.) Only writable options can be set. Can be called before authorization -// -// @param name The name of the option -// @param value The new value of the option -func (client *Client) SetOption(name string, value OptionValue) (*Ok, error) { +func (client *Client) SetOption(req *SetOptionRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setOption", }, Data: map[string]interface{}{ - "name": name, - "value": value, + "name": req.Name, + "value": req.Value, }, }) if err != nil { @@ -5903,16 +6760,19 @@ func (client *Client) SetOption(name string, value OptionValue) (*Ok, error) { return UnmarshalOk(result.Data) } +type SetAccountTtlRequest struct { + // New account TTL + Ttl *AccountTtl `json:"ttl"` +} + // Changes the period of inactivity after which the account of the current user will automatically be deleted -// -// @param ttl New account TTL -func (client *Client) SetAccountTtl(ttl *AccountTtl) (*Ok, error) { +func (client *Client) SetAccountTtl(req *SetAccountTtlRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setAccountTtl", }, Data: map[string]interface{}{ - "ttl": ttl, + "ttl": req.Ttl, }, }) if err != nil { @@ -5945,16 +6805,19 @@ func (client *Client) GetAccountTtl() (*AccountTtl, error) { return UnmarshalAccountTtl(result.Data) } +type DeleteAccountRequest struct { + // The reason why the account was deleted; optional + Reason string `json:"reason"` +} + // Deletes the account of the current user, deleting all information associated with the user from the server. The phone number of the account can be used to create a new account. Can be called before authorization when the current authorization state is authorizationStateWaitPassword -// -// @param reason The reason why the account was deleted; optional -func (client *Client) DeleteAccount(reason string) (*Ok, error) { +func (client *Client) DeleteAccount(req *DeleteAccountRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deleteAccount", }, Data: map[string]interface{}{ - "reason": reason, + "reason": req.Reason, }, }) if err != nil { @@ -5968,16 +6831,19 @@ func (client *Client) DeleteAccount(reason string) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetChatReportSpamStateRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` +} + // Returns information on whether the current chat can be reported as spam -// -// @param chatId Chat identifier -func (client *Client) GetChatReportSpamState(chatId int64) (*ChatReportSpamState, error) { +func (client *Client) GetChatReportSpamState(req *GetChatReportSpamStateRequest) (*ChatReportSpamState, error) { result, err := client.Send(Request{ meta: meta{ Type: "getChatReportSpamState", }, Data: map[string]interface{}{ - "chat_id": chatId, + "chat_id": req.ChatId, }, }) if err != nil { @@ -5991,18 +6857,22 @@ func (client *Client) GetChatReportSpamState(chatId int64) (*ChatReportSpamState return UnmarshalChatReportSpamState(result.Data) } +type ChangeChatReportSpamStateRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // If true, the chat will be reported as spam; otherwise it will be marked as not spam + IsSpamChat bool `json:"is_spam_chat"` +} + // Used to let the server know whether a chat is spam or not. Can be used only if ChatReportSpamState.can_report_spam is true. After this request, ChatReportSpamState.can_report_spam becomes false forever -// -// @param chatId Chat identifier -// @param isSpamChat If true, the chat will be reported as spam; otherwise it will be marked as not spam -func (client *Client) ChangeChatReportSpamState(chatId int64, isSpamChat bool) (*Ok, error) { +func (client *Client) ChangeChatReportSpamState(req *ChangeChatReportSpamStateRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "changeChatReportSpamState", }, Data: map[string]interface{}{ - "chat_id": chatId, - "is_spam_chat": isSpamChat, + "chat_id": req.ChatId, + "is_spam_chat": req.IsSpamChat, }, }) if err != nil { @@ -6016,20 +6886,25 @@ func (client *Client) ChangeChatReportSpamState(chatId int64, isSpamChat bool) ( return UnmarshalOk(result.Data) } +type ReportChatRequest struct { + // Chat identifier + ChatId int64 `json:"chat_id"` + // The reason for reporting the chat + Reason ChatReportReason `json:"reason"` + // Identifiers of reported messages, if any + MessageIds []int64 `json:"message_ids"` +} + // Reports a chat to the Telegram moderators. Supported only for supergroups, channels, or private chats with bots, since other chats can't be checked by moderators -// -// @param chatId Chat identifier -// @param reason The reason for reporting the chat -// @param messageIds Identifiers of reported messages, if any -func (client *Client) ReportChat(chatId int64, reason ChatReportReason, messageIds []int64) (*Ok, error) { +func (client *Client) ReportChat(req *ReportChatRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "reportChat", }, Data: map[string]interface{}{ - "chat_id": chatId, - "reason": reason, - "message_ids": messageIds, + "chat_id": req.ChatId, + "reason": req.Reason, + "message_ids": req.MessageIds, }, }) if err != nil { @@ -6043,16 +6918,19 @@ func (client *Client) ReportChat(chatId int64, reason ChatReportReason, messageI return UnmarshalOk(result.Data) } +type GetStorageStatisticsRequest struct { + // Maximum number of chats with the largest storage usage for which separate statistics should be returned. All other chats will be grouped in entries with chat_id == 0. If the chat info database is not used, the chat_limit is ignored and is always set to 0 + ChatLimit int32 `json:"chat_limit"` +} + // Returns storage usage statistics -// -// @param chatLimit Maximum number of chats with the largest storage usage for which separate statistics should be returned. All other chats will be grouped in entries with chat_id == 0. If the chat info database is not used, the chat_limit is ignored and is always set to 0 -func (client *Client) GetStorageStatistics(chatLimit int32) (*StorageStatistics, error) { +func (client *Client) GetStorageStatistics(req *GetStorageStatisticsRequest) (*StorageStatistics, error) { result, err := client.Send(Request{ meta: meta{ Type: "getStorageStatistics", }, Data: map[string]interface{}{ - "chat_limit": chatLimit, + "chat_limit": req.ChatLimit, }, }) if err != nil { @@ -6085,30 +6963,40 @@ func (client *Client) GetStorageStatisticsFast() (*StorageStatisticsFast, error) return UnmarshalStorageStatisticsFast(result.Data) } +type OptimizeStorageRequest struct { + // Limit on the total size of files after deletion. Pass -1 to use the default limit + Size int64 `json:"size"` + // Limit on the time that has passed since the last time a file was accessed (or creation time for some filesystems). Pass -1 to use the default limit + Ttl int32 `json:"ttl"` + // Limit on the total count of files after deletion. Pass -1 to use the default limit + Count int32 `json:"count"` + // The amount of time after the creation of a file during which it can't be deleted, in seconds. Pass -1 to use the default value + ImmunityDelay int32 `json:"immunity_delay"` + // If not empty, only files with the given type(s) are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted + FileTypes []FileType `json:"file_types"` + // If not empty, only files from the given chats are considered. Use 0 as chat identifier to delete files not belonging to any chat (e.g., profile photos) + ChatIds []int64 `json:"chat_ids"` + // If not empty, files from the given chats are excluded. Use 0 as chat identifier to exclude all files not belonging to any chat (e.g., profile photos) + ExcludeChatIds []int64 `json:"exclude_chat_ids"` + // Same as in getStorageStatistics. Affects only returned statistics + ChatLimit int32 `json:"chat_limit"` +} + // Optimizes storage usage, i.e. deletes some files and returns new storage usage statistics. Secret thumbnails can't be deleted -// -// @param size Limit on the total size of files after deletion. Pass -1 to use the default limit -// @param ttl Limit on the time that has passed since the last time a file was accessed (or creation time for some filesystems). Pass -1 to use the default limit -// @param count Limit on the total count of files after deletion. Pass -1 to use the default limit -// @param immunityDelay The amount of time after the creation of a file during which it can't be deleted, in seconds. Pass -1 to use the default value -// @param fileTypes If not empty, only files with the given type(s) are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted -// @param chatIds If not empty, only files from the given chats are considered. Use 0 as chat identifier to delete files not belonging to any chat (e.g., profile photos) -// @param excludeChatIds If not empty, files from the given chats are excluded. Use 0 as chat identifier to exclude all files not belonging to any chat (e.g., profile photos) -// @param chatLimit Same as in getStorageStatistics. Affects only returned statistics -func (client *Client) OptimizeStorage(size int64, ttl int32, count int32, immunityDelay int32, fileTypes []FileType, chatIds []int64, excludeChatIds []int64, chatLimit int32) (*StorageStatistics, error) { +func (client *Client) OptimizeStorage(req *OptimizeStorageRequest) (*StorageStatistics, error) { result, err := client.Send(Request{ meta: meta{ Type: "optimizeStorage", }, Data: map[string]interface{}{ - "size": size, - "ttl": ttl, - "count": count, - "immunity_delay": immunityDelay, - "file_types": fileTypes, - "chat_ids": chatIds, - "exclude_chat_ids": excludeChatIds, - "chat_limit": chatLimit, + "size": req.Size, + "ttl": req.Ttl, + "count": req.Count, + "immunity_delay": req.ImmunityDelay, + "file_types": req.FileTypes, + "chat_ids": req.ChatIds, + "exclude_chat_ids": req.ExcludeChatIds, + "chat_limit": req.ChatLimit, }, }) if err != nil { @@ -6122,16 +7010,19 @@ func (client *Client) OptimizeStorage(size int64, ttl int32, count int32, immuni return UnmarshalStorageStatistics(result.Data) } +type SetNetworkTypeRequest struct { + // The new network type. By default, networkTypeOther + Type NetworkType `json:"type"` +} + // Sets the current network type. Can be called before authorization. Calling this method forces all network connections to reopen, mitigating the delay in switching between different networks, so it should be called whenever the network is changed, even if the network type remains the same. Network type is used to check whether the library can use the network at all and also for collecting detailed network data usage statistics -// -// @param typeParam The new network type. By default, networkTypeOther -func (client *Client) SetNetworkType(typeParam NetworkType) (*Ok, error) { +func (client *Client) SetNetworkType(req *SetNetworkTypeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setNetworkType", }, Data: map[string]interface{}{ - "type": typeParam, + "type": req.Type, }, }) if err != nil { @@ -6145,16 +7036,19 @@ func (client *Client) SetNetworkType(typeParam NetworkType) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetNetworkStatisticsRequest struct { + // If true, returns only data for the current library launch + OnlyCurrent bool `json:"only_current"` +} + // Returns network data usage statistics. Can be called before authorization -// -// @param onlyCurrent If true, returns only data for the current library launch -func (client *Client) GetNetworkStatistics(onlyCurrent bool) (*NetworkStatistics, error) { +func (client *Client) GetNetworkStatistics(req *GetNetworkStatisticsRequest) (*NetworkStatistics, error) { result, err := client.Send(Request{ meta: meta{ Type: "getNetworkStatistics", }, Data: map[string]interface{}{ - "only_current": onlyCurrent, + "only_current": req.OnlyCurrent, }, }) if err != nil { @@ -6168,16 +7062,19 @@ func (client *Client) GetNetworkStatistics(onlyCurrent bool) (*NetworkStatistics return UnmarshalNetworkStatistics(result.Data) } +type AddNetworkStatisticsRequest struct { + // The network statistics entry with the data to be added to statistics + Entry NetworkStatisticsEntry `json:"entry"` +} + // Adds the specified data to data usage statistics. Can be called before authorization -// -// @param entry The network statistics entry with the data to be added to statistics -func (client *Client) AddNetworkStatistics(entry NetworkStatisticsEntry) (*Ok, error) { +func (client *Client) AddNetworkStatistics(req *AddNetworkStatisticsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "addNetworkStatistics", }, Data: map[string]interface{}{ - "entry": entry, + "entry": req.Entry, }, }) if err != nil { @@ -6210,18 +7107,22 @@ func (client *Client) ResetNetworkStatistics() (*Ok, error) { return UnmarshalOk(result.Data) } +type GetPassportElementRequest struct { + // Telegram Passport element type + Type PassportElementType `json:"type"` + // Password of the current user + Password string `json:"password"` +} + // Returns one of the available Telegram Passport elements -// -// @param typeParam Telegram Passport element type -// @param password Password of the current user -func (client *Client) GetPassportElement(typeParam PassportElementType, password string) (PassportElement, error) { +func (client *Client) GetPassportElement(req *GetPassportElementRequest) (PassportElement, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPassportElement", }, Data: map[string]interface{}{ - "type": typeParam, - "password": password, + "type": req.Type, + "password": req.Password, }, }) if err != nil { @@ -6277,16 +7178,19 @@ func (client *Client) GetPassportElement(typeParam PassportElementType, password } } +type GetAllPassportElementsRequest struct { + // Password of the current user + Password string `json:"password"` +} + // Returns all available Telegram Passport elements -// -// @param password Password of the current user -func (client *Client) GetAllPassportElements(password string) (*PassportElements, error) { +func (client *Client) GetAllPassportElements(req *GetAllPassportElementsRequest) (*PassportElements, error) { result, err := client.Send(Request{ meta: meta{ Type: "getAllPassportElements", }, Data: map[string]interface{}{ - "password": password, + "password": req.Password, }, }) if err != nil { @@ -6300,18 +7204,22 @@ func (client *Client) GetAllPassportElements(password string) (*PassportElements return UnmarshalPassportElements(result.Data) } +type SetPassportElementRequest struct { + // Input Telegram Passport element + Element InputPassportElement `json:"element"` + // Password of the current user + Password string `json:"password"` +} + // Adds an element to the user's Telegram Passport. May return an error with a message "PHONE_VERIFICATION_NEEDED" or "EMAIL_VERIFICATION_NEEDED" if the chosen phone number or the chosen email address must be verified first -// -// @param element Input Telegram Passport element -// @param password Password of the current user -func (client *Client) SetPassportElement(element InputPassportElement, password string) (PassportElement, error) { +func (client *Client) SetPassportElement(req *SetPassportElementRequest) (PassportElement, error) { result, err := client.Send(Request{ meta: meta{ Type: "setPassportElement", }, Data: map[string]interface{}{ - "element": element, - "password": password, + "element": req.Element, + "password": req.Password, }, }) if err != nil { @@ -6367,16 +7275,19 @@ func (client *Client) SetPassportElement(element InputPassportElement, password } } +type DeletePassportElementRequest struct { + // Element type + Type PassportElementType `json:"type"` +} + // Deletes a Telegram Passport element -// -// @param typeParam Element type -func (client *Client) DeletePassportElement(typeParam PassportElementType) (*Ok, error) { +func (client *Client) DeletePassportElement(req *DeletePassportElementRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "deletePassportElement", }, Data: map[string]interface{}{ - "type": typeParam, + "type": req.Type, }, }) if err != nil { @@ -6390,18 +7301,22 @@ func (client *Client) DeletePassportElement(typeParam PassportElementType) (*Ok, return UnmarshalOk(result.Data) } +type SetPassportElementErrorsRequest struct { + // User identifier + UserId int32 `json:"user_id"` + // The errors + Errors []*InputPassportElementError `json:"errors"` +} + // Informs the user that some of the elements in their Telegram Passport contain errors; for bots only. The user will not be able to resend the elements, until the errors are fixed -// -// @param userId User identifier -// @param errors The errors -func (client *Client) SetPassportElementErrors(userId int32, errors []*InputPassportElementError) (*Ok, error) { +func (client *Client) SetPassportElementErrors(req *SetPassportElementErrorsRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setPassportElementErrors", }, Data: map[string]interface{}{ - "user_id": userId, - "errors": errors, + "user_id": req.UserId, + "errors": req.Errors, }, }) if err != nil { @@ -6415,16 +7330,19 @@ func (client *Client) SetPassportElementErrors(userId int32, errors []*InputPass return UnmarshalOk(result.Data) } +type GetPreferredCountryLanguageRequest struct { + // A two-letter ISO 3166-1 alpha-2 country code + CountryCode string `json:"country_code"` +} + // Returns an IETF language tag of the language preferred in the country, which should be used to fill native fields in Telegram Passport personal details. Returns a 404 error if unknown -// -// @param countryCode A two-letter ISO 3166-1 alpha-2 country code -func (client *Client) GetPreferredCountryLanguage(countryCode string) (*Text, error) { +func (client *Client) GetPreferredCountryLanguage(req *GetPreferredCountryLanguageRequest) (*Text, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPreferredCountryLanguage", }, Data: map[string]interface{}{ - "country_code": countryCode, + "country_code": req.CountryCode, }, }) if err != nil { @@ -6438,20 +7356,25 @@ func (client *Client) GetPreferredCountryLanguage(countryCode string) (*Text, er return UnmarshalText(result.Data) } +type SendPhoneNumberVerificationCodeRequest struct { + // The phone number of the user, in international format + PhoneNumber string `json:"phone_number"` + // Pass true if the authentication code may be sent via flash call to the specified phone number + AllowFlashCall bool `json:"allow_flash_call"` + // Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false + IsCurrentPhoneNumber bool `json:"is_current_phone_number"` +} + // Sends a code to verify a phone number to be added to a user's Telegram Passport -// -// @param phoneNumber The phone number of the user, in international format -// @param allowFlashCall Pass true if the authentication code may be sent via flash call to the specified phone number -// @param isCurrentPhoneNumber Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false -func (client *Client) SendPhoneNumberVerificationCode(phoneNumber string, allowFlashCall bool, isCurrentPhoneNumber bool) (*AuthenticationCodeInfo, error) { +func (client *Client) SendPhoneNumberVerificationCode(req *SendPhoneNumberVerificationCodeRequest) (*AuthenticationCodeInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendPhoneNumberVerificationCode", }, Data: map[string]interface{}{ - "phone_number": phoneNumber, - "allow_flash_call": allowFlashCall, - "is_current_phone_number": isCurrentPhoneNumber, + "phone_number": req.PhoneNumber, + "allow_flash_call": req.AllowFlashCall, + "is_current_phone_number": req.IsCurrentPhoneNumber, }, }) if err != nil { @@ -6484,16 +7407,19 @@ func (client *Client) ResendPhoneNumberVerificationCode() (*AuthenticationCodeIn return UnmarshalAuthenticationCodeInfo(result.Data) } +type CheckPhoneNumberVerificationCodeRequest struct { + // Verification code + Code string `json:"code"` +} + // Checks the phone number verification code for Telegram Passport -// -// @param code Verification code -func (client *Client) CheckPhoneNumberVerificationCode(code string) (*Ok, error) { +func (client *Client) CheckPhoneNumberVerificationCode(req *CheckPhoneNumberVerificationCodeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkPhoneNumberVerificationCode", }, Data: map[string]interface{}{ - "code": code, + "code": req.Code, }, }) if err != nil { @@ -6507,16 +7433,19 @@ func (client *Client) CheckPhoneNumberVerificationCode(code string) (*Ok, error) return UnmarshalOk(result.Data) } +type SendEmailAddressVerificationCodeRequest struct { + // Email address + EmailAddress string `json:"email_address"` +} + // Sends a code to verify an email address to be added to a user's Telegram Passport -// -// @param emailAddress Email address -func (client *Client) SendEmailAddressVerificationCode(emailAddress string) (*EmailAddressAuthenticationCodeInfo, error) { +func (client *Client) SendEmailAddressVerificationCode(req *SendEmailAddressVerificationCodeRequest) (*EmailAddressAuthenticationCodeInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendEmailAddressVerificationCode", }, Data: map[string]interface{}{ - "email_address": emailAddress, + "email_address": req.EmailAddress, }, }) if err != nil { @@ -6549,16 +7478,19 @@ func (client *Client) ResendEmailAddressVerificationCode() (*EmailAddressAuthent return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data) } +type CheckEmailAddressVerificationCodeRequest struct { + // Verification code + Code string `json:"code"` +} + // Checks the email address verification code for Telegram Passport -// -// @param code Verification code -func (client *Client) CheckEmailAddressVerificationCode(code string) (*Ok, error) { +func (client *Client) CheckEmailAddressVerificationCode(req *CheckEmailAddressVerificationCodeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkEmailAddressVerificationCode", }, Data: map[string]interface{}{ - "code": code, + "code": req.Code, }, }) if err != nil { @@ -6572,24 +7504,31 @@ func (client *Client) CheckEmailAddressVerificationCode(code string) (*Ok, error return UnmarshalOk(result.Data) } +type GetPassportAuthorizationFormRequest struct { + // User identifier of the service's bot + BotUserId int32 `json:"bot_user_id"` + // Telegram Passport element types requested by the service + Scope string `json:"scope"` + // Service's public_key + PublicKey string `json:"public_key"` + // Authorization form nonce provided by the service + Nonce string `json:"nonce"` + // Password of the current user + Password string `json:"password"` +} + // Returns a Telegram Passport authorization form for sharing data with a service -// -// @param botUserId User identifier of the service's bot -// @param scope Telegram Passport element types requested by the service -// @param publicKey Service's public_key -// @param nonce Authorization form nonce provided by the service -// @param password Password of the current user -func (client *Client) GetPassportAuthorizationForm(botUserId int32, scope string, publicKey string, nonce string, password string) (*PassportAuthorizationForm, error) { +func (client *Client) GetPassportAuthorizationForm(req *GetPassportAuthorizationFormRequest) (*PassportAuthorizationForm, error) { result, err := client.Send(Request{ meta: meta{ Type: "getPassportAuthorizationForm", }, Data: map[string]interface{}{ - "bot_user_id": botUserId, - "scope": scope, - "public_key": publicKey, - "nonce": nonce, - "password": password, + "bot_user_id": req.BotUserId, + "scope": req.Scope, + "public_key": req.PublicKey, + "nonce": req.Nonce, + "password": req.Password, }, }) if err != nil { @@ -6603,18 +7542,22 @@ func (client *Client) GetPassportAuthorizationForm(botUserId int32, scope string return UnmarshalPassportAuthorizationForm(result.Data) } +type SendPassportAuthorizationFormRequest struct { + // Authorization form identifier + AutorizationFormId int32 `json:"autorization_form_id"` + // Types of Telegram Passport elements chosen by user to complete the authorization form + Types []PassportElementType `json:"types"` +} + // Sends a Telegram Passport authorization form, effectively sharing data with the service -// -// @param autorizationFormId Authorization form identifier -// @param types Types of Telegram Passport elements chosen by user to complete the authorization form -func (client *Client) SendPassportAuthorizationForm(autorizationFormId int32, types []PassportElementType) (*Ok, error) { +func (client *Client) SendPassportAuthorizationForm(req *SendPassportAuthorizationFormRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendPassportAuthorizationForm", }, Data: map[string]interface{}{ - "autorization_form_id": autorizationFormId, - "types": types, + "autorization_form_id": req.AutorizationFormId, + "types": req.Types, }, }) if err != nil { @@ -6628,22 +7571,28 @@ func (client *Client) SendPassportAuthorizationForm(autorizationFormId int32, ty return UnmarshalOk(result.Data) } +type SendPhoneNumberConfirmationCodeRequest struct { + // Value of the "hash" parameter from the link + Hash string `json:"hash"` + // Value of the "phone" parameter from the link + PhoneNumber string `json:"phone_number"` + // Pass true if the authentication code may be sent via flash call to the specified phone number + AllowFlashCall bool `json:"allow_flash_call"` + // Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false + IsCurrentPhoneNumber bool `json:"is_current_phone_number"` +} + // Sends phone number confirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link -// -// @param hash Value of the "hash" parameter from the link -// @param phoneNumber Value of the "phone" parameter from the link -// @param allowFlashCall Pass true if the authentication code may be sent via flash call to the specified phone number -// @param isCurrentPhoneNumber Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false -func (client *Client) SendPhoneNumberConfirmationCode(hash string, phoneNumber string, allowFlashCall bool, isCurrentPhoneNumber bool) (*AuthenticationCodeInfo, error) { +func (client *Client) SendPhoneNumberConfirmationCode(req *SendPhoneNumberConfirmationCodeRequest) (*AuthenticationCodeInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendPhoneNumberConfirmationCode", }, Data: map[string]interface{}{ - "hash": hash, - "phone_number": phoneNumber, - "allow_flash_call": allowFlashCall, - "is_current_phone_number": isCurrentPhoneNumber, + "hash": req.Hash, + "phone_number": req.PhoneNumber, + "allow_flash_call": req.AllowFlashCall, + "is_current_phone_number": req.IsCurrentPhoneNumber, }, }) if err != nil { @@ -6676,16 +7625,19 @@ func (client *Client) ResendPhoneNumberConfirmationCode() (*AuthenticationCodeIn return UnmarshalAuthenticationCodeInfo(result.Data) } +type CheckPhoneNumberConfirmationCodeRequest struct { + // The phone number confirmation code + Code string `json:"code"` +} + // Checks phone number confirmation code -// -// @param code The phone number confirmation code -func (client *Client) CheckPhoneNumberConfirmationCode(code string) (*Ok, error) { +func (client *Client) CheckPhoneNumberConfirmationCode(req *CheckPhoneNumberConfirmationCodeRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "checkPhoneNumberConfirmationCode", }, Data: map[string]interface{}{ - "code": code, + "code": req.Code, }, }) if err != nil { @@ -6699,18 +7651,22 @@ func (client *Client) CheckPhoneNumberConfirmationCode(code string) (*Ok, error) return UnmarshalOk(result.Data) } +type SetBotUpdatesStatusRequest struct { + // The number of pending updates + PendingUpdateCount int32 `json:"pending_update_count"` + // The last error message + ErrorMessage string `json:"error_message"` +} + // Informs the server about the number of pending bot updates if they haven't been processed for a long time; for bots only -// -// @param pendingUpdateCount The number of pending updates -// @param errorMessage The last error message -func (client *Client) SetBotUpdatesStatus(pendingUpdateCount int32, errorMessage string) (*Ok, error) { +func (client *Client) SetBotUpdatesStatus(req *SetBotUpdatesStatusRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setBotUpdatesStatus", }, Data: map[string]interface{}{ - "pending_update_count": pendingUpdateCount, - "error_message": errorMessage, + "pending_update_count": req.PendingUpdateCount, + "error_message": req.ErrorMessage, }, }) if err != nil { @@ -6724,18 +7680,22 @@ func (client *Client) SetBotUpdatesStatus(pendingUpdateCount int32, errorMessage return UnmarshalOk(result.Data) } +type UploadStickerFileRequest struct { + // Sticker file owner + UserId int32 `json:"user_id"` + // PNG image with the sticker; must be up to 512 kB in size and fit in 512x512 square + PngSticker InputFile `json:"png_sticker"` +} + // Uploads a PNG image with a sticker; for bots only; returns the uploaded file -// -// @param userId Sticker file owner -// @param pngSticker PNG image with the sticker; must be up to 512 kB in size and fit in 512x512 square -func (client *Client) UploadStickerFile(userId int32, pngSticker InputFile) (*File, error) { +func (client *Client) UploadStickerFile(req *UploadStickerFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "uploadStickerFile", }, Data: map[string]interface{}{ - "user_id": userId, - "png_sticker": pngSticker, + "user_id": req.UserId, + "png_sticker": req.PngSticker, }, }) if err != nil { @@ -6749,24 +7709,31 @@ func (client *Client) UploadStickerFile(userId int32, pngSticker InputFile) (*Fi return UnmarshalFile(result.Data) } +type CreateNewStickerSetRequest struct { + // Sticker set owner + UserId int32 `json:"user_id"` + // Sticker set title; 1-64 characters + Title string `json:"title"` + // Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_"* (** is case insensitive); 1-64 characters + Name string `json:"name"` + // True, if stickers are masks + IsMasks bool `json:"is_masks"` + // List of stickers to be added to the set + Stickers []*InputSticker `json:"stickers"` +} + // Creates a new sticker set; for bots only. Returns the newly created sticker set -// -// @param userId Sticker set owner -// @param title Sticker set title; 1-64 characters -// @param name Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_"* (** is case insensitive); 1-64 characters -// @param isMasks True, if stickers are masks -// @param stickers List of stickers to be added to the set -func (client *Client) CreateNewStickerSet(userId int32, title string, name string, isMasks bool, stickers []*InputSticker) (*StickerSet, error) { +func (client *Client) CreateNewStickerSet(req *CreateNewStickerSetRequest) (*StickerSet, error) { result, err := client.Send(Request{ meta: meta{ Type: "createNewStickerSet", }, Data: map[string]interface{}{ - "user_id": userId, - "title": title, - "name": name, - "is_masks": isMasks, - "stickers": stickers, + "user_id": req.UserId, + "title": req.Title, + "name": req.Name, + "is_masks": req.IsMasks, + "stickers": req.Stickers, }, }) if err != nil { @@ -6780,20 +7747,25 @@ func (client *Client) CreateNewStickerSet(userId int32, title string, name strin return UnmarshalStickerSet(result.Data) } +type AddStickerToSetRequest struct { + // Sticker set owner + UserId int32 `json:"user_id"` + // Sticker set name + Name string `json:"name"` + // Sticker to add to the set + Sticker *InputSticker `json:"sticker"` +} + // Adds a new sticker to a set; for bots only. Returns the sticker set -// -// @param userId Sticker set owner -// @param name Sticker set name -// @param sticker Sticker to add to the set -func (client *Client) AddStickerToSet(userId int32, name string, sticker *InputSticker) (*StickerSet, error) { +func (client *Client) AddStickerToSet(req *AddStickerToSetRequest) (*StickerSet, error) { result, err := client.Send(Request{ meta: meta{ Type: "addStickerToSet", }, Data: map[string]interface{}{ - "user_id": userId, - "name": name, - "sticker": sticker, + "user_id": req.UserId, + "name": req.Name, + "sticker": req.Sticker, }, }) if err != nil { @@ -6807,18 +7779,22 @@ func (client *Client) AddStickerToSet(userId int32, name string, sticker *InputS return UnmarshalStickerSet(result.Data) } +type SetStickerPositionInSetRequest struct { + // Sticker + Sticker InputFile `json:"sticker"` + // New position of the sticker in the set, zero-based + Position int32 `json:"position"` +} + // Changes the position of a sticker in the set to which it belongs; for bots only. The sticker set must have been created by the bot -// -// @param sticker Sticker -// @param position New position of the sticker in the set, zero-based -func (client *Client) SetStickerPositionInSet(sticker InputFile, position int32) (*Ok, error) { +func (client *Client) SetStickerPositionInSet(req *SetStickerPositionInSetRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setStickerPositionInSet", }, Data: map[string]interface{}{ - "sticker": sticker, - "position": position, + "sticker": req.Sticker, + "position": req.Position, }, }) if err != nil { @@ -6832,16 +7808,19 @@ func (client *Client) SetStickerPositionInSet(sticker InputFile, position int32) return UnmarshalOk(result.Data) } +type RemoveStickerFromSetRequest struct { + // Sticker + Sticker InputFile `json:"sticker"` +} + // Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot -// -// @param sticker Sticker -func (client *Client) RemoveStickerFromSet(sticker InputFile) (*Ok, error) { +func (client *Client) RemoveStickerFromSet(req *RemoveStickerFromSetRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeStickerFromSet", }, Data: map[string]interface{}{ - "sticker": sticker, + "sticker": req.Sticker, }, }) if err != nil { @@ -6855,26 +7834,34 @@ func (client *Client) RemoveStickerFromSet(sticker InputFile) (*Ok, error) { return UnmarshalOk(result.Data) } +type GetMapThumbnailFileRequest struct { + // Location of the map center + Location *Location `json:"location"` + // Map zoom level; 13-20 + Zoom int32 `json:"zoom"` + // Map width in pixels before applying scale; 16-1024 + Width int32 `json:"width"` + // Map height in pixels before applying scale; 16-1024 + Height int32 `json:"height"` + // Map scale; 1-3 + Scale int32 `json:"scale"` + // Identifier of a chat, in which the thumbnail will be shown. Use 0 if unknown + ChatId int64 `json:"chat_id"` +} + // Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded -// -// @param location Location of the map center -// @param zoom Map zoom level; 13-20 -// @param width Map width in pixels before applying scale; 16-1024 -// @param height Map height in pixels before applying scale; 16-1024 -// @param scale Map scale; 1-3 -// @param chatId Identifier of a chat, in which the thumbnail will be shown. Use 0 if unknown -func (client *Client) GetMapThumbnailFile(location *Location, zoom int32, width int32, height int32, scale int32, chatId int64) (*File, error) { +func (client *Client) GetMapThumbnailFile(req *GetMapThumbnailFileRequest) (*File, error) { result, err := client.Send(Request{ meta: meta{ Type: "getMapThumbnailFile", }, Data: map[string]interface{}{ - "location": location, - "zoom": zoom, - "width": width, - "height": height, - "scale": scale, - "chat_id": chatId, + "location": req.Location, + "zoom": req.Zoom, + "width": req.Width, + "height": req.Height, + "scale": req.Scale, + "chat_id": req.ChatId, }, }) if err != nil { @@ -6888,16 +7875,19 @@ func (client *Client) GetMapThumbnailFile(location *Location, zoom int32, width return UnmarshalFile(result.Data) } +type AcceptTermsOfServiceRequest struct { + // Terms of service identifier + TermsOfServiceId string `json:"terms_of_service_id"` +} + // Accepts Telegram terms of services -// -// @param termsOfServiceId Terms of service identifier -func (client *Client) AcceptTermsOfService(termsOfServiceId string) (*Ok, error) { +func (client *Client) AcceptTermsOfService(req *AcceptTermsOfServiceRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "acceptTermsOfService", }, Data: map[string]interface{}{ - "terms_of_service_id": termsOfServiceId, + "terms_of_service_id": req.TermsOfServiceId, }, }) if err != nil { @@ -6911,18 +7901,22 @@ func (client *Client) AcceptTermsOfService(termsOfServiceId string) (*Ok, error) return UnmarshalOk(result.Data) } +type SendCustomRequestRequest struct { + // The method name + Method string `json:"method"` + // JSON-serialized method parameters + Parameters string `json:"parameters"` +} + // Sends a custom request; for bots only -// -// @param method The method name -// @param parameters JSON-serialized method parameters -func (client *Client) SendCustomRequest(method string, parameters string) (*CustomRequestResult, error) { +func (client *Client) SendCustomRequest(req *SendCustomRequestRequest) (*CustomRequestResult, error) { result, err := client.Send(Request{ meta: meta{ Type: "sendCustomRequest", }, Data: map[string]interface{}{ - "method": method, - "parameters": parameters, + "method": req.Method, + "parameters": req.Parameters, }, }) if err != nil { @@ -6936,18 +7930,22 @@ func (client *Client) SendCustomRequest(method string, parameters string) (*Cust return UnmarshalCustomRequestResult(result.Data) } +type AnswerCustomQueryRequest struct { + // Identifier of a custom query + CustomQueryId JsonInt64 `json:"custom_query_id"` + // JSON-serialized answer to the query + Data string `json:"data"` +} + // Answers a custom query; for bots only -// -// @param customQueryId Identifier of a custom query -// @param data JSON-serialized answer to the query -func (client *Client) AnswerCustomQuery(customQueryId JsonInt64, data string) (*Ok, error) { +func (client *Client) AnswerCustomQuery(req *AnswerCustomQueryRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "answerCustomQuery", }, Data: map[string]interface{}{ - "custom_query_id": customQueryId, - "data": data, + "custom_query_id": req.CustomQueryId, + "data": req.Data, }, }) if err != nil { @@ -6961,16 +7959,19 @@ func (client *Client) AnswerCustomQuery(customQueryId JsonInt64, data string) (* return UnmarshalOk(result.Data) } +type SetAlarmRequest struct { + // Number of seconds before the function returns + Seconds float64 `json:"seconds"` +} + // Succeeds after a specified amount of time has passed. Can be called before authorization. Can be called before initialization -// -// @param seconds Number of seconds before the function returns -func (client *Client) SetAlarm(seconds float64) (*Ok, error) { +func (client *Client) SetAlarm(req *SetAlarmRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "setAlarm", }, Data: map[string]interface{}{ - "seconds": seconds, + "seconds": req.Seconds, }, }) if err != nil { @@ -7022,16 +8023,19 @@ func (client *Client) GetInviteText() (*Text, error) { return UnmarshalText(result.Data) } +type GetDeepLinkInfoRequest struct { + // The link + Link string `json:"link"` +} + // Returns information about a tg:// deep link. Use "tg://need_update_for_some_feature" or "tg:some_unsupported_feature" for testing. Returns a 404 error for unknown links. Can be called before authorization -// -// @param link The link -func (client *Client) GetDeepLinkInfo(link string) (*DeepLinkInfo, error) { +func (client *Client) GetDeepLinkInfo(req *GetDeepLinkInfoRequest) (*DeepLinkInfo, error) { result, err := client.Send(Request{ meta: meta{ Type: "getDeepLinkInfo", }, Data: map[string]interface{}{ - "link": link, + "link": req.Link, }, }) if err != nil { @@ -7045,22 +8049,28 @@ func (client *Client) GetDeepLinkInfo(link string) (*DeepLinkInfo, error) { return UnmarshalDeepLinkInfo(result.Data) } +type AddProxyRequest struct { + // Proxy server IP address + Server string `json:"server"` + // Proxy server port + Port int32 `json:"port"` + // True, if the proxy should be enabled + Enable bool `json:"enable"` + // Proxy type + Type ProxyType `json:"type"` +} + // Adds a proxy server for network requests. Can be called before authorization -// -// @param server Proxy server IP address -// @param port Proxy server port -// @param enable True, if the proxy should be enabled -// @param typeParam Proxy type -func (client *Client) AddProxy(server string, port int32, enable bool, typeParam ProxyType) (*Proxy, error) { +func (client *Client) AddProxy(req *AddProxyRequest) (*Proxy, error) { result, err := client.Send(Request{ meta: meta{ Type: "addProxy", }, Data: map[string]interface{}{ - "server": server, - "port": port, - "enable": enable, - "type": typeParam, + "server": req.Server, + "port": req.Port, + "enable": req.Enable, + "type": req.Type, }, }) if err != nil { @@ -7074,24 +8084,31 @@ func (client *Client) AddProxy(server string, port int32, enable bool, typeParam return UnmarshalProxy(result.Data) } +type EditProxyRequest struct { + // Proxy identifier + ProxyId int32 `json:"proxy_id"` + // Proxy server IP address + Server string `json:"server"` + // Proxy server port + Port int32 `json:"port"` + // True, if the proxy should be enabled + Enable bool `json:"enable"` + // Proxy type + Type ProxyType `json:"type"` +} + // Edits an existing proxy server for network requests. Can be called before authorization -// -// @param proxyId Proxy identifier -// @param server Proxy server IP address -// @param port Proxy server port -// @param enable True, if the proxy should be enabled -// @param typeParam Proxy type -func (client *Client) EditProxy(proxyId int32, server string, port int32, enable bool, typeParam ProxyType) (*Proxy, error) { +func (client *Client) EditProxy(req *EditProxyRequest) (*Proxy, error) { result, err := client.Send(Request{ meta: meta{ Type: "editProxy", }, Data: map[string]interface{}{ - "proxy_id": proxyId, - "server": server, - "port": port, - "enable": enable, - "type": typeParam, + "proxy_id": req.ProxyId, + "server": req.Server, + "port": req.Port, + "enable": req.Enable, + "type": req.Type, }, }) if err != nil { @@ -7105,16 +8122,19 @@ func (client *Client) EditProxy(proxyId int32, server string, port int32, enable return UnmarshalProxy(result.Data) } +type EnableProxyRequest struct { + // Proxy identifier + ProxyId int32 `json:"proxy_id"` +} + // Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization -// -// @param proxyId Proxy identifier -func (client *Client) EnableProxy(proxyId int32) (*Ok, error) { +func (client *Client) EnableProxy(req *EnableProxyRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "enableProxy", }, Data: map[string]interface{}{ - "proxy_id": proxyId, + "proxy_id": req.ProxyId, }, }) if err != nil { @@ -7147,16 +8167,19 @@ func (client *Client) DisableProxy() (*Ok, error) { return UnmarshalOk(result.Data) } +type RemoveProxyRequest struct { + // Proxy identifier + ProxyId int32 `json:"proxy_id"` +} + // Removes a proxy server. Can be called before authorization -// -// @param proxyId Proxy identifier -func (client *Client) RemoveProxy(proxyId int32) (*Ok, error) { +func (client *Client) RemoveProxy(req *RemoveProxyRequest) (*Ok, error) { result, err := client.Send(Request{ meta: meta{ Type: "removeProxy", }, Data: map[string]interface{}{ - "proxy_id": proxyId, + "proxy_id": req.ProxyId, }, }) if err != nil { @@ -7189,16 +8212,19 @@ func (client *Client) GetProxies() (*Proxies, error) { return UnmarshalProxies(result.Data) } +type GetProxyLinkRequest struct { + // Proxy identifier + ProxyId int32 `json:"proxy_id"` +} + // Returns an HTTPS link, which can be used to add a proxy. Available only for SOCKS5 and MTProto proxies. Can be called before authorization -// -// @param proxyId Proxy identifier -func (client *Client) GetProxyLink(proxyId int32) (*Text, error) { +func (client *Client) GetProxyLink(req *GetProxyLinkRequest) (*Text, error) { result, err := client.Send(Request{ meta: meta{ Type: "getProxyLink", }, Data: map[string]interface{}{ - "proxy_id": proxyId, + "proxy_id": req.ProxyId, }, }) if err != nil { @@ -7212,16 +8238,19 @@ func (client *Client) GetProxyLink(proxyId int32) (*Text, error) { return UnmarshalText(result.Data) } +type PingProxyRequest struct { + // Proxy identifier. Use 0 to ping a Telegram server without a proxy + ProxyId int32 `json:"proxy_id"` +} + // Computes time needed to receive a response from a Telegram server through a proxy. Can be called before authorization -// -// @param proxyId Proxy identifier. Use 0 to ping a Telegram server without a proxy -func (client *Client) PingProxy(proxyId int32) (*Seconds, error) { +func (client *Client) PingProxy(req *PingProxyRequest) (*Seconds, error) { result, err := client.Send(Request{ meta: meta{ Type: "pingProxy", }, Data: map[string]interface{}{ - "proxy_id": proxyId, + "proxy_id": req.ProxyId, }, }) if err != nil { @@ -7254,16 +8283,19 @@ func (client *Client) TestCallEmpty() (*Ok, error) { return UnmarshalOk(result.Data) } +type TestCallStringRequest struct { + // String to return + X string `json:"x"` +} + // Returns the received string; for testing only -// -// @param x String to return -func (client *Client) TestCallString(x string) (*TestString, error) { +func (client *Client) TestCallString(req *TestCallStringRequest) (*TestString, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallString", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7277,16 +8309,19 @@ func (client *Client) TestCallString(x string) (*TestString, error) { return UnmarshalTestString(result.Data) } +type TestCallBytesRequest struct { + // Bytes to return + X []byte `json:"x"` +} + // Returns the received bytes; for testing only -// -// @param x Bytes to return -func (client *Client) TestCallBytes(x []byte) (*TestBytes, error) { +func (client *Client) TestCallBytes(req *TestCallBytesRequest) (*TestBytes, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallBytes", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7300,16 +8335,19 @@ func (client *Client) TestCallBytes(x []byte) (*TestBytes, error) { return UnmarshalTestBytes(result.Data) } +type TestCallVectorIntRequest struct { + // Vector of numbers to return + X []int32 `json:"x"` +} + // Returns the received vector of numbers; for testing only -// -// @param x Vector of numbers to return -func (client *Client) TestCallVectorInt(x []int32) (*TestVectorInt, error) { +func (client *Client) TestCallVectorInt(req *TestCallVectorIntRequest) (*TestVectorInt, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallVectorInt", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7323,16 +8361,19 @@ func (client *Client) TestCallVectorInt(x []int32) (*TestVectorInt, error) { return UnmarshalTestVectorInt(result.Data) } +type TestCallVectorIntObjectRequest struct { + // Vector of objects to return + X []*TestInt `json:"x"` +} + // Returns the received vector of objects containing a number; for testing only -// -// @param x Vector of objects to return -func (client *Client) TestCallVectorIntObject(x []*TestInt) (*TestVectorIntObject, error) { +func (client *Client) TestCallVectorIntObject(req *TestCallVectorIntObjectRequest) (*TestVectorIntObject, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallVectorIntObject", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7346,16 +8387,19 @@ func (client *Client) TestCallVectorIntObject(x []*TestInt) (*TestVectorIntObjec return UnmarshalTestVectorIntObject(result.Data) } +type TestCallVectorStringRequest struct { + // Vector of strings to return + X []string `json:"x"` +} + // For testing only request. Returns the received vector of strings; for testing only -// -// @param x Vector of strings to return -func (client *Client) TestCallVectorString(x []string) (*TestVectorString, error) { +func (client *Client) TestCallVectorString(req *TestCallVectorStringRequest) (*TestVectorString, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallVectorString", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7369,16 +8413,19 @@ func (client *Client) TestCallVectorString(x []string) (*TestVectorString, error return UnmarshalTestVectorString(result.Data) } +type TestCallVectorStringObjectRequest struct { + // Vector of objects to return + X []*TestString `json:"x"` +} + // Returns the received vector of objects containing a string; for testing only -// -// @param x Vector of objects to return -func (client *Client) TestCallVectorStringObject(x []*TestString) (*TestVectorStringObject, error) { +func (client *Client) TestCallVectorStringObject(req *TestCallVectorStringObjectRequest) (*TestVectorStringObject, error) { result, err := client.Send(Request{ meta: meta{ Type: "testCallVectorStringObject", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { @@ -7392,16 +8439,19 @@ func (client *Client) TestCallVectorStringObject(x []*TestString) (*TestVectorSt return UnmarshalTestVectorStringObject(result.Data) } +type TestSquareIntRequest struct { + // Number to square + X int32 `json:"x"` +} + // Returns the squared received number; for testing only -// -// @param x Number to square -func (client *Client) TestSquareInt(x int32) (*TestInt, error) { +func (client *Client) TestSquareInt(req *TestSquareIntRequest) (*TestInt, error) { result, err := client.Send(Request{ meta: meta{ Type: "testSquareInt", }, Data: map[string]interface{}{ - "x": x, + "x": req.X, }, }) if err != nil { diff --git a/client/puller/chat.go b/client/puller/chat.go index 2cac330..f86c929 100644 --- a/client/puller/chat.go +++ b/client/puller/chat.go @@ -24,7 +24,13 @@ func chatHistory(tdlibClient *client.Client, messageChan chan *client.Message, e }() for { - messages, err := tdlibClient.GetChatHistory(chatId, fromMessageId, offset, limit, onlyLocal) + messages, err := tdlibClient.GetChatHistory(&client.GetChatHistoryRequest{ + ChatId: chatId, + FromMessageId: fromMessageId, + Offset: offset, + Limit: limit, + OnlyLocal: onlyLocal, + }) if err != nil { errChan <- err diff --git a/client/puller/chats.go b/client/puller/chats.go index 9011181..7cd1061 100644 --- a/client/puller/chats.go +++ b/client/puller/chats.go @@ -26,7 +26,11 @@ func chats(tdlibClient *client.Client, chatChan chan *client.Chat, errChan chan }() for { - chats, err := tdlibClient.GetChats(offsetOrder, offsetChatId, limit) + chats, err := tdlibClient.GetChats(&client.GetChatsRequest{ + OffsetOrder: offsetOrder, + OffsetChatId: offsetChatId, + Limit: limit, + }) if err != nil { errChan <- err diff --git a/client/puller/supergroup.go b/client/puller/supergroup.go index 2ad9692..69d51bf 100644 --- a/client/puller/supergroup.go +++ b/client/puller/supergroup.go @@ -26,7 +26,12 @@ func supergroupMembers(tdlibClient *client.Client, chatMemberChan chan *client.C var page int32 = 0 for { - chatMembers, err := tdlibClient.GetSupergroupMembers(supergroupId, filter, page*limit+offset, limit) + chatMembers, err := tdlibClient.GetSupergroupMembers(&client.GetSupergroupMembersRequest{ + SupergroupId: supergroupId, + Filter: filter, + Offset: page*limit + offset, + Limit: limit, + }) if err != nil { errChan <- err diff --git a/codegen/function.go b/codegen/function.go index 1c8bd27..a8a2152 100644 --- a/codegen/function.go +++ b/codegen/function.go @@ -1,10 +1,10 @@ package codegen import ( - "github.com/zelenin/go-tdlib/tlparser" - "fmt" - "strings" "bytes" + "fmt" + + "github.com/zelenin/go-tdlib/tlparser" ) func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte { @@ -19,29 +19,31 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte { buf.WriteString("\n") for _, function := range schema.Functions { + tdlibFunction := TdlibFunction(function.Name, schema) + tdlibFunctionReturn := TdlibFunctionReturn(function.Class, schema) + + if len(function.Properties) > 0 { + buf.WriteString("\n") + buf.WriteString(fmt.Sprintf("type %sRequest struct { \n", tdlibFunction.ToGoName())) + for _, property := range function.Properties { + tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema) + + buf.WriteString(fmt.Sprintf(" // %s\n", property.Description)) + buf.WriteString(fmt.Sprintf(" %s %s `json:\"%s\"`\n", tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoType(), property.Name)) + } + buf.WriteString("}\n") + } + buf.WriteString("\n") buf.WriteString("// " + function.Description) buf.WriteString("\n") + requestArgument := "" if len(function.Properties) > 0 { - buf.WriteString("//") - buf.WriteString("\n") + requestArgument = fmt.Sprintf("req *%sRequest", tdlibFunction.ToGoName()) } - propertiesParts := []string{} - for _, property := range function.Properties { - tdlibFunctionProperty := TdlibFunctionProperty(property.Name, property.Type, schema) - - buf.WriteString(fmt.Sprintf("// @param %s %s", tdlibFunctionProperty.ToGoName(), property.Description)) - buf.WriteString("\n") - - propertiesParts = append(propertiesParts, tdlibFunctionProperty.ToGoName()+" "+tdlibFunctionProperty.ToGoType()) - } - - tdlibFunction := TdlibFunction(function.Name, schema) - tdlibFunctionReturn := TdlibFunctionReturn(function.Class, schema) - - buf.WriteString(fmt.Sprintf("func (client *Client) %s(%s) (%s, error) {\n", tdlibFunction.ToGoName(), strings.Join(propertiesParts, ", "), tdlibFunctionReturn.ToGoReturn())) + buf.WriteString(fmt.Sprintf("func (client *Client) %s(%s) (%s, error) {\n", tdlibFunction.ToGoName(), requestArgument, tdlibFunctionReturn.ToGoReturn())) sendMethod := "Send" if function.IsSynchronous { @@ -57,8 +59,9 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte { `, sendMethod, function.Name)) for _, property := range function.Properties { - tdlibFunctionProperty := TdlibFunctionProperty(property.Name, property.Type, schema) - buf.WriteString(fmt.Sprintf(" \"%s\": %s,\n", property.Name, tdlibFunctionProperty.ToGoName())) + tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema) + + buf.WriteString(fmt.Sprintf(" \"%s\": req.%s,\n", property.Name, tdlibTypeProperty.ToGoName())) } buf.WriteString(` },