go-tdlib/client/function.go

21379 lines
604 KiB
Go
Executable File

// AUTOGENERATED
package client
import (
"errors"
)
// Returns the current authorization state; this is an offline request. For informational purposes only. Use updateAuthorizationState instead to maintain the current authorization state. Can be called before initialization
func (client *Client) GetAuthorizationState() (AuthorizationState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getAuthorizationState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeAuthorizationStateWaitTdlibParameters:
return UnmarshalAuthorizationStateWaitTdlibParameters(result.Data)
case TypeAuthorizationStateWaitPhoneNumber:
return UnmarshalAuthorizationStateWaitPhoneNumber(result.Data)
case TypeAuthorizationStateWaitEmailAddress:
return UnmarshalAuthorizationStateWaitEmailAddress(result.Data)
case TypeAuthorizationStateWaitEmailCode:
return UnmarshalAuthorizationStateWaitEmailCode(result.Data)
case TypeAuthorizationStateWaitCode:
return UnmarshalAuthorizationStateWaitCode(result.Data)
case TypeAuthorizationStateWaitOtherDeviceConfirmation:
return UnmarshalAuthorizationStateWaitOtherDeviceConfirmation(result.Data)
case TypeAuthorizationStateWaitRegistration:
return UnmarshalAuthorizationStateWaitRegistration(result.Data)
case TypeAuthorizationStateWaitPassword:
return UnmarshalAuthorizationStateWaitPassword(result.Data)
case TypeAuthorizationStateReady:
return UnmarshalAuthorizationStateReady(result.Data)
case TypeAuthorizationStateLoggingOut:
return UnmarshalAuthorizationStateLoggingOut(result.Data)
case TypeAuthorizationStateClosing:
return UnmarshalAuthorizationStateClosing(result.Data)
case TypeAuthorizationStateClosed:
return UnmarshalAuthorizationStateClosed(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type SetTdlibParametersRequest struct {
// Pass true to use Telegram test environment instead of the production environment
UseTestDc bool `json:"use_test_dc"`
// The path to the directory for the persistent database; if empty, the current working directory will be used
DatabaseDirectory string `json:"database_directory"`
// The path to the directory for storing files; if empty, database_directory will be used
FilesDirectory string `json:"files_directory"`
// Encryption key for the database. If the encryption key is invalid, then an error with code 401 will be returned
DatabaseEncryptionKey []byte `json:"database_encryption_key"`
// Pass true to keep information about downloaded and uploaded files between application restarts
UseFileDatabase bool `json:"use_file_database"`
// Pass true to keep cache of users, basic groups, supergroups, channels and secret chats between restarts. Implies use_file_database
UseChatInfoDatabase bool `json:"use_chat_info_database"`
// Pass true to keep cache of chats and messages between restarts. Implies use_chat_info_database
UseMessageDatabase bool `json:"use_message_database"`
// Pass true to enable support for secret chats
UseSecretChats bool `json:"use_secret_chats"`
// Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
ApiId int32 `json:"api_id"`
// Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
ApiHash string `json:"api_hash"`
// IETF language tag of the user's operating system language; must be non-empty
SystemLanguageCode string `json:"system_language_code"`
// Model of the device the application is being run on; must be non-empty
DeviceModel string `json:"device_model"`
// Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
SystemVersion string `json:"system_version"`
// Application version; must be non-empty
ApplicationVersion string `json:"application_version"`
}
// Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters
func (client *Client) SetTdlibParameters(req *SetTdlibParametersRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setTdlibParameters",
},
Data: map[string]interface{}{
"use_test_dc": req.UseTestDc,
"database_directory": req.DatabaseDirectory,
"files_directory": req.FilesDirectory,
"database_encryption_key": req.DatabaseEncryptionKey,
"use_file_database": req.UseFileDatabase,
"use_chat_info_database": req.UseChatInfoDatabase,
"use_message_database": req.UseMessageDatabase,
"use_secret_chats": req.UseSecretChats,
"api_id": req.ApiId,
"api_hash": req.ApiHash,
"system_language_code": req.SystemLanguageCode,
"device_model": req.DeviceModel,
"system_version": req.SystemVersion,
"application_version": req.ApplicationVersion,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetAuthenticationPhoneNumberRequest struct {
// The phone number of the user, in international format
PhoneNumber string `json:"phone_number"`
// Settings for the authentication of the user's phone number; pass null to use default settings
Settings *PhoneNumberAuthenticationSettings `json:"settings"`
}
// Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber, or if there is no pending authentication query and the current authorization state is authorizationStateWaitEmailAddress, authorizationStateWaitEmailCode, authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword
func (client *Client) SetAuthenticationPhoneNumber(req *SetAuthenticationPhoneNumberRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setAuthenticationPhoneNumber",
},
Data: map[string]interface{}{
"phone_number": req.PhoneNumber,
"settings": req.Settings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetAuthenticationEmailAddressRequest struct {
// The email address of the user
EmailAddress string `json:"email_address"`
}
// Sets the email address of the user and sends an authentication code to the email address. Works only when the current authorization state is authorizationStateWaitEmailAddress
func (client *Client) SetAuthenticationEmailAddress(req *SetAuthenticationEmailAddressRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setAuthenticationEmailAddress",
},
Data: map[string]interface{}{
"email_address": req.EmailAddress,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Resends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode, the next_code_type of the result is not null and the server-specified timeout has passed, or when the current authorization state is authorizationStateWaitEmailCode
func (client *Client) ResendAuthenticationCode() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resendAuthenticationCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CheckAuthenticationEmailCodeRequest struct {
// Email address authentication to check
Code EmailAddressAuthentication `json:"code"`
}
// Checks the authentication of a email address. Works only when the current authorization state is authorizationStateWaitEmailCode
func (client *Client) CheckAuthenticationEmailCode(req *CheckAuthenticationEmailCodeRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationEmailCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CheckAuthenticationCodeRequest struct {
// Authentication code to check
Code string `json:"code"`
}
// Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode
func (client *Client) CheckAuthenticationCode(req *CheckAuthenticationCodeRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RequestQrCodeAuthenticationRequest struct {
// List of user identifiers of other users currently using the application
OtherUserIds []int64 `json:"other_user_ids"`
}
// Requests QR code authentication by scanning a QR code on another logged in device. Works only when the current authorization state is authorizationStateWaitPhoneNumber, or if there is no pending authentication query and the current authorization state is authorizationStateWaitEmailAddress, authorizationStateWaitEmailCode, authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword
func (client *Client) RequestQrCodeAuthentication(req *RequestQrCodeAuthenticationRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "requestQrCodeAuthentication",
},
Data: map[string]interface{}{
"other_user_ids": req.OtherUserIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RegisterUserRequest struct {
// The first name of the user; 1-64 characters
FirstName string `json:"first_name"`
// The last name of the user; 0-64 characters
LastName string `json:"last_name"`
// Pass true to disable notification about the current user joining Telegram for other users that added them to contact list
DisableNotification bool `json:"disable_notification"`
}
// Finishes user registration. Works only when the current authorization state is authorizationStateWaitRegistration
func (client *Client) RegisterUser(req *RegisterUserRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "registerUser",
},
Data: map[string]interface{}{
"first_name": req.FirstName,
"last_name": req.LastName,
"disable_notification": req.DisableNotification,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Resets the login email address. May return an error with a message "TASK_ALREADY_EXISTS" if reset is still pending. Works only when the current authorization state is authorizationStateWaitEmailCode and authorization_state.can_reset_email_address == true
func (client *Client) ResetAuthenticationEmailAddress() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resetAuthenticationEmailAddress",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CheckAuthenticationPasswordRequest struct {
// The 2-step verification password to check
Password string `json:"password"`
}
// Checks the 2-step verification password for correctness. Works only when the current authorization state is authorizationStateWaitPassword
func (client *Client) CheckAuthenticationPassword(req *CheckAuthenticationPasswordRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationPassword",
},
Data: map[string]interface{}{
"password": req.Password,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Requests to send a 2-step verification password recovery code to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword
func (client *Client) RequestAuthenticationPasswordRecovery() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "requestAuthenticationPasswordRecovery",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CheckAuthenticationPasswordRecoveryCodeRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
}
// Checks whether a 2-step verification password recovery code sent to an email address is valid. Works only when the current authorization state is authorizationStateWaitPassword
func (client *Client) CheckAuthenticationPasswordRecoveryCode(req *CheckAuthenticationPasswordRecoveryCodeRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationPasswordRecoveryCode",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RecoverAuthenticationPasswordRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
// New 2-step verification 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"`
}
// Recovers the 2-step verification 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
func (client *Client) RecoverAuthenticationPassword(req *RecoverAuthenticationPasswordRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "recoverAuthenticationPassword",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
"new_password": req.NewPassword,
"new_hint": req.NewHint,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SendAuthenticationFirebaseSmsRequest struct {
// SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application
Token string `json:"token"`
}
// Sends Firebase Authentication SMS to the phone number of the user. Works only when the current authorization state is authorizationStateWaitCode and the server returned code of the type authenticationCodeTypeFirebaseAndroid or authenticationCodeTypeFirebaseIos
func (client *Client) SendAuthenticationFirebaseSms(req *SendAuthenticationFirebaseSmsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "sendAuthenticationFirebaseSms",
},
Data: map[string]interface{}{
"token": req.Token,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) CheckAuthenticationBotToken(req *CheckAuthenticationBotTokenRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationBotToken",
},
Data: map[string]interface{}{
"token": req.Token,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Closes the TDLib instance after a proper logout. Requires an available network connection. All local data will be destroyed. After the logout completes, updateAuthorizationState with authorizationStateClosed will be sent
func (client *Client) LogOut() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "logOut",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Closes the TDLib instance. All databases will be flushed to disk and properly closed. After the close completes, updateAuthorizationState with authorizationStateClosed will be sent. Can be called before initialization
func (client *Client) Close() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "close",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Closes the TDLib instance, destroying all local data without a proper logout. The current user session will remain in the list of all active sessions. All local data will be destroyed. After the destruction completes updateAuthorizationState with authorizationStateClosed will be sent. Can be called before authorization
func (client *Client) Destroy() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "destroy",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ConfirmQrCodeAuthenticationRequest struct {
// A link from a QR code. The link must be scanned by the in-app camera
Link string `json:"link"`
}
// Confirms QR code authentication on another device. Returns created session on success
func (client *Client) ConfirmQrCodeAuthentication(req *ConfirmQrCodeAuthenticationRequest) (*Session, error) {
result, err := client.Send(Request{
meta: meta{
Type: "confirmQrCodeAuthentication",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalSession(result.Data)
}
// Returns all updates needed to restore current TDLib state, i.e. all actual updateAuthorizationState/updateUser/updateNewChat and others. This is especially useful if TDLib is run in a separate process. Can be called before initialization
func (client *Client) GetCurrentState() (*Updates, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getCurrentState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUpdates(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
func (client *Client) SetDatabaseEncryptionKey(req *SetDatabaseEncryptionKeyRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setDatabaseEncryptionKey",
},
Data: map[string]interface{}{
"new_encryption_key": req.NewEncryptionKey,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns the current state of 2-step verification
func (client *Client) GetPasswordState() (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getPasswordState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
type SetPasswordRequest struct {
// Previous 2-step verification password of the user
OldPassword string `json:"old_password"`
// New 2-step verification 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 to change also the recovery email address
SetRecoveryEmailAddress bool `json:"set_recovery_email_address"`
// New recovery email address; may be empty
NewRecoveryEmailAddress string `json:"new_recovery_email_address"`
}
// Changes the 2-step verification password for the current user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is confirmed
func (client *Client) SetPassword(req *SetPasswordRequest) (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setPassword",
},
Data: map[string]interface{}{
"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 {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
type SetLoginEmailAddressRequest struct {
// New login email address
NewLoginEmailAddress string `json:"new_login_email_address"`
}
// Changes the login email address of the user. The email address can be changed only if the current user already has login email and passwordState.login_email_address_pattern is non-empty. The change will not be applied until the new login email address is confirmed with checkLoginEmailAddressCode. To use Apple ID/Google ID instead of a email address, call checkLoginEmailAddressCode directly
func (client *Client) SetLoginEmailAddress(req *SetLoginEmailAddressRequest) (*EmailAddressAuthenticationCodeInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setLoginEmailAddress",
},
Data: map[string]interface{}{
"new_login_email_address": req.NewLoginEmailAddress,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
}
// Resends the login email address verification code
func (client *Client) ResendLoginEmailAddressCode() (*EmailAddressAuthenticationCodeInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resendLoginEmailAddressCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
}
type CheckLoginEmailAddressCodeRequest struct {
// Email address authentication to check
Code EmailAddressAuthentication `json:"code"`
}
// Checks the login email address authentication
func (client *Client) CheckLoginEmailAddressCode(req *CheckLoginEmailAddressCodeRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkLoginEmailAddressCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetRecoveryEmailAddressRequest struct {
// The 2-step verification password for the current user
Password string `json:"password"`
}
// Returns a 2-step verification recovery email address that was previously set up. This method can be used to verify a password provided by the user
func (client *Client) GetRecoveryEmailAddress(req *GetRecoveryEmailAddressRequest) (*RecoveryEmailAddress, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getRecoveryEmailAddress",
},
Data: map[string]interface{}{
"password": req.Password,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalRecoveryEmailAddress(result.Data)
}
type SetRecoveryEmailAddressRequest struct {
// The 2-step verification password of the current user
Password string `json:"password"`
// New recovery email address
NewRecoveryEmailAddress string `json:"new_recovery_email_address"`
}
// Changes the 2-step verification recovery email address of the user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is 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
func (client *Client) SetRecoveryEmailAddress(req *SetRecoveryEmailAddressRequest) (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setRecoveryEmailAddress",
},
Data: map[string]interface{}{
"password": req.Password,
"new_recovery_email_address": req.NewRecoveryEmailAddress,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
type CheckRecoveryEmailAddressCodeRequest struct {
// Verification code to check
Code string `json:"code"`
}
// Checks the 2-step verification recovery email address verification code
func (client *Client) CheckRecoveryEmailAddressCode(req *CheckRecoveryEmailAddressCodeRequest) (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkRecoveryEmailAddressCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
// Resends the 2-step verification recovery email address verification code
func (client *Client) ResendRecoveryEmailAddressCode() (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resendRecoveryEmailAddressCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
// Cancels verification of the 2-step verification recovery email address
func (client *Client) CancelRecoveryEmailAddressVerification() (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "cancelRecoveryEmailAddressVerification",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
// Requests to send a 2-step verification password recovery code to an email address that was previously set up
func (client *Client) RequestPasswordRecovery() (*EmailAddressAuthenticationCodeInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "requestPasswordRecovery",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
}
type CheckPasswordRecoveryCodeRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
}
// Checks whether a 2-step verification password recovery code sent to an email address is valid
func (client *Client) CheckPasswordRecoveryCode(req *CheckPasswordRecoveryCodeRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkPasswordRecoveryCode",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RecoverPasswordRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
// New 2-step verification 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"`
}
// Recovers the 2-step verification password using a recovery code sent to an email address that was previously set up
func (client *Client) RecoverPassword(req *RecoverPasswordRequest) (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "recoverPassword",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
"new_password": req.NewPassword,
"new_hint": req.NewHint,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
// Removes 2-step verification password without previous password and access to recovery email address. The password can't be reset immediately and the request needs to be repeated after the specified time
func (client *Client) ResetPassword() (ResetPasswordResult, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resetPassword",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeResetPasswordResultOk:
return UnmarshalResetPasswordResultOk(result.Data)
case TypeResetPasswordResultPending:
return UnmarshalResetPasswordResultPending(result.Data)
case TypeResetPasswordResultDeclined:
return UnmarshalResetPasswordResultDeclined(result.Data)
default:
return nil, errors.New("invalid type")
}
}
// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date > 0
func (client *Client) CancelPasswordReset() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "cancelPasswordReset",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CreateTemporaryPasswordRequest struct {
// The 2-step verification password of the current user
Password string `json:"password"`
// Time during which the temporary password will be valid, in seconds; must be between 60 and 86400
ValidFor int32 `json:"valid_for"`
}
// Creates a new temporary password for processing payments
func (client *Client) CreateTemporaryPassword(req *CreateTemporaryPasswordRequest) (*TemporaryPasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "createTemporaryPassword",
},
Data: map[string]interface{}{
"password": req.Password,
"valid_for": req.ValidFor,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalTemporaryPasswordState(result.Data)
}
// Returns information about the current temporary password
func (client *Client) GetTemporaryPasswordState() (*TemporaryPasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getTemporaryPasswordState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalTemporaryPasswordState(result.Data)
}
// Returns the current user
func (client *Client) GetMe() (*User, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMe",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUser(result.Data)
}
type GetUserRequest struct {
// User identifier
UserId int64 `json:"user_id"`
}
// Returns information about a user by their identifier. This is an offline request if the current user is not a bot
func (client *Client) GetUser(req *GetUserRequest) (*User, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getUser",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUser(result.Data)
}
type GetUserFullInfoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
}
// Returns full information about a user by their identifier
func (client *Client) GetUserFullInfo(req *GetUserFullInfoRequest) (*UserFullInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getUserFullInfo",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUserFullInfo(result.Data)
}
type GetBasicGroupRequest struct {
// Basic group identifier
BasicGroupId int64 `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
func (client *Client) GetBasicGroup(req *GetBasicGroupRequest) (*BasicGroup, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getBasicGroup",
},
Data: map[string]interface{}{
"basic_group_id": req.BasicGroupId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalBasicGroup(result.Data)
}
type GetBasicGroupFullInfoRequest struct {
// Basic group identifier
BasicGroupId int64 `json:"basic_group_id"`
}
// Returns full information about a basic group by its identifier
func (client *Client) GetBasicGroupFullInfo(req *GetBasicGroupFullInfoRequest) (*BasicGroupFullInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getBasicGroupFullInfo",
},
Data: map[string]interface{}{
"basic_group_id": req.BasicGroupId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalBasicGroupFullInfo(result.Data)
}
type GetSupergroupRequest struct {
// Supergroup or channel identifier
SupergroupId int64 `json:"supergroup_id"`
}
// Returns information about a supergroup or a channel by its identifier. This is an offline request if the current user is not a bot
func (client *Client) GetSupergroup(req *GetSupergroupRequest) (*Supergroup, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSupergroup",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalSupergroup(result.Data)
}
type GetSupergroupFullInfoRequest struct {
// Supergroup or channel identifier
SupergroupId int64 `json:"supergroup_id"`
}
// Returns full information about a supergroup or a channel by its identifier, cached for up to 1 minute
func (client *Client) GetSupergroupFullInfo(req *GetSupergroupFullInfoRequest) (*SupergroupFullInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSupergroupFullInfo",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) GetSecretChat(req *GetSecretChatRequest) (*SecretChat, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSecretChat",
},
Data: map[string]interface{}{
"secret_chat_id": req.SecretChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) GetChat(req *GetChatRequest) (*Chat, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) GetMessage(req *GetMessageRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type GetMessageLocallyRequest 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, if it is available without sending network request. This is an offline request
func (client *Client) GetMessageLocally(req *GetMessageLocallyRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLocally",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type GetRepliedMessageRequest struct {
// Identifier of the chat the message belongs to
ChatId int64 `json:"chat_id"`
// Identifier of the reply message
MessageId int64 `json:"message_id"`
}
// Returns information about a non-bundled message that is replied by a given message. Also, returns the pinned message, the game message, the invoice message, the message with a previously set same background, the giveaway message, and the topic creation message for messages of the types messagePinMessage, messageGameScore, messagePaymentSuccessful, messageChatSetBackground, messagePremiumGiveawayCompleted and topic messages without non-bundled replied message respectively
func (client *Client) GetRepliedMessage(req *GetRepliedMessageRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getRepliedMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type GetChatPinnedMessageRequest struct {
// Identifier of the chat the message belongs to
ChatId int64 `json:"chat_id"`
}
// Returns information about a newest pinned message in the chat
func (client *Client) GetChatPinnedMessage(req *GetChatPinnedMessageRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatPinnedMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type GetCallbackQueryMessageRequest struct {
// Identifier of the chat the message belongs to
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// Identifier of the callback query
CallbackQueryId JsonInt64 `json:"callback_query_id"`
}
// Returns information about a message with the callback button that originated a callback query; for bots only
func (client *Client) GetCallbackQueryMessage(req *GetCallbackQueryMessageRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getCallbackQueryMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"callback_query_id": req.CallbackQueryId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) GetMessages(req *GetMessagesRequest) (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type GetMessageThreadRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
}
// Returns information about a message thread. Can be used only if message.can_get_message_thread == true
func (client *Client) GetMessageThread(req *GetMessageThreadRequest) (*MessageThreadInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageThread",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageThreadInfo(result.Data)
}
type GetMessageReadDateRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
}
// Returns read date of a recent outgoing message in a private chat. The method can be called if message.can_get_read_date == true and the message is read
func (client *Client) GetMessageReadDate(req *GetMessageReadDateRequest) (MessageReadDate, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageReadDate",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeMessageReadDateRead:
return UnmarshalMessageReadDateRead(result.Data)
case TypeMessageReadDateUnread:
return UnmarshalMessageReadDateUnread(result.Data)
case TypeMessageReadDateTooOld:
return UnmarshalMessageReadDateTooOld(result.Data)
case TypeMessageReadDateUserPrivacyRestricted:
return UnmarshalMessageReadDateUserPrivacyRestricted(result.Data)
case TypeMessageReadDateMyPrivacyRestricted:
return UnmarshalMessageReadDateMyPrivacyRestricted(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type GetMessageViewersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
}
// Returns viewers of a recent outgoing message in a basic group or a supergroup chat. For video notes and voice notes only users, opened content of the message, are returned. The method can be called if message.can_get_viewers == true
func (client *Client) GetMessageViewers(req *GetMessageViewersRequest) (*MessageViewers, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageViewers",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageViewers(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
func (client *Client) GetFile(req *GetFileRequest) (*File, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type GetRemoteFileRequest struct {
// Remote identifier of the file to get
RemoteFileId string `json:"remote_file_id"`
// File type; pass null if unknown
FileType FileType `json:"file_type"`
}
// Returns information about a file by its remote identifier; this is an offline request. Can be used to register a URL as a file for further uploading, or sending as a message. Even the request succeeds, the file can be used only if it is still accessible to the user. For example, if the file is from a message, then the message must be not deleted and accessible to the user. If the file database is disabled, then the corresponding object with the file must be preloaded by the application
func (client *Client) GetRemoteFile(req *GetRemoteFileRequest) (*File, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getRemoteFile",
},
Data: map[string]interface{}{
"remote_file_id": req.RemoteFileId,
"file_type": req.FileType,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type LoadChatsRequest struct {
// The chat list in which to load chats; pass null to load chats from the main chat list
ChatList ChatList `json:"chat_list"`
// The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
Limit int32 `json:"limit"`
}
// Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded
func (client *Client) LoadChats(req *LoadChatsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "loadChats",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatsRequest struct {
// The chat list in which to return chats; pass null to get chats from the main chat list
ChatList ChatList `json:"chat_list"`
// The maximum number of chats to be returned
Limit int32 `json:"limit"`
}
// Returns an ordered list of chats from the beginning of a chat list. For informational purposes only. Use loadChats and updates processing instead to maintain chat lists in a consistent state
func (client *Client) GetChats(req *GetChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChats",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) SearchPublicChat(req *SearchPublicChatRequest) (*Chat, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchPublicChat",
},
Data: map[string]interface{}{
"username": req.Username,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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. Excludes private chats with contacts and chats from the chat list from the results
func (client *Client) SearchPublicChats(req *SearchPublicChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchPublicChats",
},
Data: map[string]interface{}{
"query": req.Query,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type SearchChatsRequest struct {
// Query to search for. If the query is empty, returns up to 50 recently found chats
Query string `json:"query"`
// The 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 main chat list
func (client *Client) SearchChats(req *SearchChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChats",
},
Data: map[string]interface{}{
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type SearchChatsOnServerRequest struct {
// Query to search for
Query string `json:"query"`
// The 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 main chat list
func (client *Client) SearchChatsOnServer(req *SearchChatsOnServerRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatsOnServer",
},
Data: map[string]interface{}{
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type SearchChatsNearbyRequest struct {
// Current user location
Location *Location `json:"location"`
}
// Returns a list of users and location-based supergroups nearby. The list of users nearby will be updated for 60 seconds after the request by the updates updateUsersNearby. The request must be sent again every 25 seconds with adjusted location to not miss new chats
func (client *Client) SearchChatsNearby(req *SearchChatsNearbyRequest) (*ChatsNearby, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatsNearby",
},
Data: map[string]interface{}{
"location": req.Location,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatsNearby(result.Data)
}
type GetChatSimilarChatsRequest struct {
// Identifier of the target chat; must be an identifier of a channel chat
ChatId int64 `json:"chat_id"`
}
// Returns a list of chats similar to the given chat
func (client *Client) GetChatSimilarChats(req *GetChatSimilarChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatSimilarChats",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type GetChatSimilarChatCountRequest struct {
// Identifier of the target chat; must be an identifier of a channel chat
ChatId int64 `json:"chat_id"`
// Pass true to get the number of chats without sending network requests, or -1 if the number of chats is unknown locally
ReturnLocal bool `json:"return_local"`
}
// Returns approximate number of chats similar to the given chat
func (client *Client) GetChatSimilarChatCount(req *GetChatSimilarChatCountRequest) (*Count, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatSimilarChatCount",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"return_local": req.ReturnLocal,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalCount(result.Data)
}
type OpenChatSimilarChatRequest struct {
// Identifier of the original chat, which similar chats were requested
ChatId int64 `json:"chat_id"`
// Identifier of the opened chat
OpenedChatId int64 `json:"opened_chat_id"`
}
// Informs TDLib that a chat was opened from the list of similar chats. The method is independent from openChat and closeChat methods
func (client *Client) OpenChatSimilarChat(req *OpenChatSimilarChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "openChatSimilarChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"opened_chat_id": req.OpenedChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetTopChatsRequest struct {
// Category of chats to be returned
Category TopChatCategory `json:"category"`
// The maximum number of chats to be returned; up to 30
Limit int32 `json:"limit"`
}
// Returns a list of frequently used chats
func (client *Client) GetTopChats(req *GetTopChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getTopChats",
},
Data: map[string]interface{}{
"category": req.Category,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) RemoveTopChat(req *RemoveTopChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "removeTopChat",
},
Data: map[string]interface{}{
"category": req.Category,
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SearchRecentlyFoundChatsRequest struct {
// Query to search for
Query string `json:"query"`
// The maximum number of chats to be returned
Limit int32 `json:"limit"`
}
// Searches for the specified query in the title and username of up to 50 recently found chats; this is an offline request
func (client *Client) SearchRecentlyFoundChats(req *SearchRecentlyFoundChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchRecentlyFoundChats",
},
Data: map[string]interface{}{
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(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
func (client *Client) AddRecentlyFoundChat(req *AddRecentlyFoundChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "addRecentlyFoundChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) RemoveRecentlyFoundChat(req *RemoveRecentlyFoundChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "removeRecentlyFoundChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Clears the list of recently found chats
func (client *Client) ClearRecentlyFoundChats() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "clearRecentlyFoundChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetRecentlyOpenedChatsRequest struct {
// The maximum number of chats to be returned
Limit int32 `json:"limit"`
}
// Returns recently opened chats; this is an offline request. Returns chats in the order of last opening
func (client *Client) GetRecentlyOpenedChats(req *GetRecentlyOpenedChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getRecentlyOpenedChats",
},
Data: map[string]interface{}{
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type CheckChatUsernameRequest struct {
// Chat identifier; must be identifier of a supergroup chat, or a channel chat, or a private chat with self, or 0 if the chat is being created
ChatId int64 `json:"chat_id"`
// Username to be checked
Username string `json:"username"`
}
// Checks whether a username can be set for a chat
func (client *Client) CheckChatUsername(req *CheckChatUsernameRequest) (CheckChatUsernameResult, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkChatUsername",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"username": req.Username,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeCheckChatUsernameResultOk:
return UnmarshalCheckChatUsernameResultOk(result.Data)
case TypeCheckChatUsernameResultUsernameInvalid:
return UnmarshalCheckChatUsernameResultUsernameInvalid(result.Data)
case TypeCheckChatUsernameResultUsernameOccupied:
return UnmarshalCheckChatUsernameResultUsernameOccupied(result.Data)
case TypeCheckChatUsernameResultUsernamePurchasable:
return UnmarshalCheckChatUsernameResultUsernamePurchasable(result.Data)
case TypeCheckChatUsernameResultPublicChatsTooMany:
return UnmarshalCheckChatUsernameResultPublicChatsTooMany(result.Data)
case TypeCheckChatUsernameResultPublicGroupsUnavailable:
return UnmarshalCheckChatUsernameResultPublicGroupsUnavailable(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type GetCreatedPublicChatsRequest struct {
// Type of the public chats to return
Type PublicChatType `json:"type"`
}
// Returns a list of public chats of the specified type, owned by the user
func (client *Client) GetCreatedPublicChats(req *GetCreatedPublicChatsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getCreatedPublicChats",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type CheckCreatedPublicChatsLimitRequest struct {
// Type of the public chats, for which to check the limit
Type PublicChatType `json:"type"`
}
// Checks whether the maximum number of owned public chats has been reached. Returns corresponding error if the limit was reached. The limit can be increased with Telegram Premium
func (client *Client) CheckCreatedPublicChatsLimit(req *CheckCreatedPublicChatsLimitRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkCreatedPublicChatsLimit",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Returned basic group chats must be first upgraded to supergroups before they can be set as a discussion group. To set a returned supergroup as a discussion group, access to its old messages must be enabled using toggleSupergroupIsAllHistoryAvailable first
func (client *Client) GetSuitableDiscussionChats() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSuitableDiscussionChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
// Returns a list of recently inactive supergroups and channels. Can be used when user reaches limit on the number of joined supergroups and channels and receives CHANNELS_TOO_MUCH error. Also, the limit can be increased with Telegram Premium
func (client *Client) GetInactiveSupergroupChats() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getInactiveSupergroupChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
// Returns a list of channel chats, which can be used as a personal chat
func (client *Client) GetSuitablePersonalChats() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSuitablePersonalChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type LoadSavedMessagesTopicsRequest struct {
// The maximum number of topics to be loaded. For optimal performance, the number of loaded topics is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
Limit int32 `json:"limit"`
}
// Loads more Saved Messages topics. The loaded topics will be sent through updateSavedMessagesTopic. Topics are sorted by their topic.order in descending order. Returns a 404 error if all topics have been loaded
func (client *Client) LoadSavedMessagesTopics(req *LoadSavedMessagesTopicsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "loadSavedMessagesTopics",
},
Data: map[string]interface{}{
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetSavedMessagesTopicHistoryRequest struct {
// Identifier of Saved Messages topic which messages will be fetched
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
// Identifier of the message starting from which messages 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 message from_message_id or a negative offset up to 99 to get additionally 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 or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
}
// Returns messages in a Saved Messages topic. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id)
func (client *Client) GetSavedMessagesTopicHistory(req *GetSavedMessagesTopicHistoryRequest) (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSavedMessagesTopicHistory",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type GetSavedMessagesTopicMessageByDateRequest struct {
// Identifier of Saved Messages topic which message will be returned
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
// Point in time (Unix timestamp) relative to which to search for messages
Date int32 `json:"date"`
}
// Returns the last message sent in a Saved Messages topic no later than the specified date
func (client *Client) GetSavedMessagesTopicMessageByDate(req *GetSavedMessagesTopicMessageByDateRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSavedMessagesTopicMessageByDate",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
"date": req.Date,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type DeleteSavedMessagesTopicHistoryRequest struct {
// Identifier of Saved Messages topic which messages will be deleted
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
}
// Deletes all messages in a Saved Messages topic
func (client *Client) DeleteSavedMessagesTopicHistory(req *DeleteSavedMessagesTopicHistoryRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteSavedMessagesTopicHistory",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteSavedMessagesTopicMessagesByDateRequest struct {
// Identifier of Saved Messages topic which messages will be deleted
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
// The minimum date of the messages to delete
MinDate int32 `json:"min_date"`
// The maximum date of the messages to delete
MaxDate int32 `json:"max_date"`
}
// Deletes all messages between the specified dates in a Saved Messages topic. Messages sent in the last 30 seconds will not be deleted
func (client *Client) DeleteSavedMessagesTopicMessagesByDate(req *DeleteSavedMessagesTopicMessagesByDateRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteSavedMessagesTopicMessagesByDate",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
"min_date": req.MinDate,
"max_date": req.MaxDate,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleSavedMessagesTopicIsPinnedRequest struct {
// Identifier of Saved Messages topic to pin or unpin
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
// Pass true to pin the topic; pass false to unpin it
IsPinned bool `json:"is_pinned"`
}
// Changes the pinned state of a Saved Messages topic. There can be up to getOption("pinned_saved_messages_topic_count_max") pinned topics. The limit can be increased with Telegram Premium
func (client *Client) ToggleSavedMessagesTopicIsPinned(req *ToggleSavedMessagesTopicIsPinnedRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "toggleSavedMessagesTopicIsPinned",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
"is_pinned": req.IsPinned,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetPinnedSavedMessagesTopicsRequest struct {
// Identifiers of the new pinned Saved Messages topics
SavedMessagesTopicIds []int64 `json:"saved_messages_topic_ids"`
}
// Changes the order of pinned Saved Messages topics
func (client *Client) SetPinnedSavedMessagesTopics(req *SetPinnedSavedMessagesTopicsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setPinnedSavedMessagesTopics",
},
Data: map[string]interface{}{
"saved_messages_topic_ids": req.SavedMessagesTopicIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetGroupsInCommonRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// Chat identifier starting from which to return chats; use 0 for the first request
OffsetChatId int64 `json:"offset_chat_id"`
// The maximum number of chats to be returned; up to 100
Limit int32 `json:"limit"`
}
// Returns a list of common group chats with a given user. Chats are sorted by their type and creation date
func (client *Client) GetGroupsInCommon(req *GetGroupsInCommonRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getGroupsInCommon",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"offset_chat_id": req.OffsetChatId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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 message from_message_id or a negative offset up to 99 to get additionally 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 or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
// Pass true to get only messages that are available 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 TDLib. This is an offline request if only_local is true
func (client *Client) GetChatHistory(req *GetChatHistoryRequest) (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatHistory",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
"only_local": req.OnlyLocal,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type GetMessageThreadHistoryRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message identifier, which thread history needs to be returned
MessageId int64 `json:"message_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 message from_message_id or a negative offset up to 99 to get additionally 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 or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
}
// Returns messages in a message thread of a message. Can be used only if message.can_get_message_thread == true. Message thread of a channel message is in the channel's linked supergroup. 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 TDLib
func (client *Client) GetMessageThreadHistory(req *GetMessageThreadHistoryRequest) (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageThreadHistory",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type DeleteChatHistoryRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Pass true to remove the chat from all chat lists
RemoveFromChatList bool `json:"remove_from_chat_list"`
// Pass true to delete chat history for all users
Revoke bool `json:"revoke"`
}
// Deletes all messages in the chat. Use chat.can_be_deleted_only_for_self and chat.can_be_deleted_for_all_users fields to find whether and how the method can be applied to the chat
func (client *Client) DeleteChatHistory(req *DeleteChatHistoryRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteChatHistory",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"remove_from_chat_list": req.RemoveFromChatList,
"revoke": req.Revoke,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
}
// Deletes a chat along with all messages in the corresponding chat for all chat members. For group chats this will release the usernames and remove all members. Use the field chat.can_be_deleted_for_all_users to find whether the method can be applied to the chat
func (client *Client) DeleteChat(req *DeleteChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
// Identifier of the sender of messages to search for; pass null to search for messages from any sender. Not supported in secret chats
SenderId MessageSender `json:"sender_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 message 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. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
// Additional filter for messages to search; pass null to search for all messages
Filter SearchMessagesFilter `json:"filter"`
// If not 0, only messages in the specified thread will be returned; supergroups only
MessageThreadId int64 `json:"message_thread_id"`
// If not 0, only messages in the specified Saved Messages topic will be returned; pass 0 to return all messages, or for chats other than Saved Messages
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
}
// 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 must be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit. A combination of query, sender_id, filter and message_thread_id search criteria is expected to be supported, only if it is required for Telegram official application implementation
func (client *Client) SearchChatMessages(req *SearchChatMessagesRequest) (*FoundChatMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"sender_id": req.SenderId,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
"filter": req.Filter,
"message_thread_id": req.MessageThreadId,
"saved_messages_topic_id": req.SavedMessagesTopicId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundChatMessages(result.Data)
}
type SearchMessagesRequest struct {
// Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
ChatList ChatList `json:"chat_list"`
// Query to search for
Query string `json:"query"`
// Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
Offset string `json:"offset"`
// The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
// Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, searchMessagesFilterFailedToSend, and searchMessagesFilterPinned are unsupported in this function
Filter SearchMessagesFilter `json:"filter"`
// If not 0, the minimum date of the messages to return
MinDate int32 `json:"min_date"`
// If not 0, the maximum date of the messages to return
MaxDate int32 `json:"max_date"`
}
// 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 TDLib and can be smaller than the specified limit
func (client *Client) SearchMessages(req *SearchMessagesRequest) (*FoundMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchMessages",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
"query": req.Query,
"offset": req.Offset,
"limit": req.Limit,
"filter": req.Filter,
"min_date": req.MinDate,
"max_date": req.MaxDate,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundMessages(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 must be used instead
Query string `json:"query"`
// Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
Offset string `json:"offset"`
// The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
// Additional filter for messages to search; pass null to search for all messages
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 TDLib
func (client *Client) SearchSecretMessages(req *SearchSecretMessagesRequest) (*FoundMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchSecretMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"offset": req.Offset,
"limit": req.Limit,
"filter": req.Filter,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundMessages(result.Data)
}
type SearchSavedMessagesRequest struct {
// If not 0, only messages in the specified Saved Messages topic will be considered; pass 0 to consider all messages
SavedMessagesTopicId int64 `json:"saved_messages_topic_id"`
// Tag to search for; pass null to return all suitable messages
Tag ReactionType `json:"tag"`
// Query to search for
Query string `json:"query"`
// Identifier of the message starting from which messages 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 message 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. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
}
// Searches for messages tagged by the given reaction and with the given words in the Saved Messages chat; for Telegram Premium users only. 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 TDLib and can be smaller than the specified limit
func (client *Client) SearchSavedMessages(req *SearchSavedMessagesRequest) (*FoundChatMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchSavedMessages",
},
Data: map[string]interface{}{
"saved_messages_topic_id": req.SavedMessagesTopicId,
"tag": req.Tag,
"query": req.Query,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundChatMessages(result.Data)
}
type SearchCallMessagesRequest struct {
// Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
Offset string `json:"offset"`
// The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
// Pass true to search only for messages with missed/declined 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 TDLib
func (client *Client) SearchCallMessages(req *SearchCallMessagesRequest) (*FoundMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchCallMessages",
},
Data: map[string]interface{}{
"offset": req.Offset,
"limit": req.Limit,
"only_missed": req.OnlyMissed,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundMessages(result.Data)
}
type SearchOutgoingDocumentMessagesRequest struct {
// Query to search for in document file name and message caption
Query string `json:"query"`
// The maximum number of messages to be returned; up to 100
Limit int32 `json:"limit"`
}
// Searches for outgoing messages with content of the type messageDocument in all chats except secret chats. Returns the results in reverse chronological order
func (client *Client) SearchOutgoingDocumentMessages(req *SearchOutgoingDocumentMessagesRequest) (*FoundMessages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchOutgoingDocumentMessages",
},
Data: map[string]interface{}{
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundMessages(result.Data)
}
type DeleteAllCallMessagesRequest struct {
// Pass true to delete the messages for all users
Revoke bool `json:"revoke"`
}
// Deletes all call messages
func (client *Client) DeleteAllCallMessages(req *DeleteAllCallMessagesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteAllCallMessages",
},
Data: map[string]interface{}{
"revoke": req.Revoke,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SearchChatRecentLocationMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The 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
func (client *Client) SearchChatRecentLocationMessages(req *SearchChatRecentLocationMessagesRequest) (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatRecentLocationMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
// Returns all active live locations that need to be updated by the application. The list is persistent across application restarts only if the message database is used
func (client *Client) GetActiveLiveLocationMessages() (*Messages, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getActiveLiveLocationMessages",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}