go-tdlib/client/function.go

19034 lines
592 KiB
Go
Raw Normal View History

2022-01-27 23:45:31 +00:00
// AUTOGENERATED
2018-08-30 14:55:42 +00:00
package client
import (
2023-03-26 09:37:06 +00:00
"errors"
2018-08-30 14:55:42 +00:00
)
2020-11-30 09:33:47 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) GetAuthorizationState() (AuthorizationState, error) {
2023-03-26 09:37:06 +00:00
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"`
// Pass true to automatically delete old files in background
EnableStorageOptimizer bool `json:"enable_storage_optimizer"`
// Pass true to ignore original file names for downloaded files. Otherwise, downloaded files are saved under names as close as possible to the original name
IgnoreFileNames bool `json:"ignore_file_names"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters
2018-10-16 20:32:57 +00:00
func (client *Client) SetTdlibParameters(req *SetTdlibParametersRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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,
"enable_storage_optimizer": req.EnableStorageOptimizer,
"ignore_file_names": req.IgnoreFileNames,
},
})
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"`
2018-10-16 20:32:57 +00:00
}
2023-02-04 22:54:46 +00:00
// 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
2022-09-18 01:34:29 +00:00
func (client *Client) SetAuthenticationPhoneNumber(req *SetAuthenticationPhoneNumberRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type SetAuthenticationEmailAddressRequest struct {
// The email address of the user
EmailAddress string `json:"email_address"`
2018-10-16 20:32:57 +00:00
}
2022-09-18 01:34:29 +00:00
// 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) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAuthenticationEmailAddress",
},
Data: map[string]interface{}{
"email_address": req.EmailAddress,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2022-09-18 01:34:29 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) ResendAuthenticationCode() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendAuthenticationCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckAuthenticationEmailCodeRequest struct {
// Email address authentication to check
Code EmailAddressAuthentication `json:"code"`
2022-09-18 01:34:29 +00:00
}
// Checks the authentication of a email address. Works only when the current authorization state is authorizationStateWaitEmailCode
func (client *Client) CheckAuthenticationEmailCode(req *CheckAuthenticationEmailCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationEmailCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckAuthenticationCodeRequest struct {
// Authentication code to check
Code string `json:"code"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode
2018-10-16 20:32:57 +00:00
func (client *Client) CheckAuthenticationCode(req *CheckAuthenticationCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type RequestQrCodeAuthenticationRequest struct {
// List of user identifiers of other users currently using the application
OtherUserIds []int64 `json:"other_user_ids"`
2020-02-03 12:56:20 +00:00
}
2023-02-04 22:54:46 +00:00
// 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
2020-02-03 12:56:20 +00:00
func (client *Client) RequestQrCodeAuthentication(req *RequestQrCodeAuthenticationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "requestQrCodeAuthentication",
},
Data: map[string]interface{}{
"other_user_ids": req.OtherUserIds,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2019-09-10 12:36:54 +00:00
}
// Finishes user registration. Works only when the current authorization state is authorizationStateWaitRegistration
func (client *Client) RegisterUser(req *RegisterUserRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "registerUser",
},
Data: map[string]interface{}{
"first_name": req.FirstName,
"last_name": req.LastName,
},
})
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"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// Checks the 2-step verification password for correctness. Works only when the current authorization state is authorizationStateWaitPassword
2018-10-16 20:32:57 +00:00
func (client *Client) CheckAuthenticationPassword(req *CheckAuthenticationPasswordRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationPassword",
},
Data: map[string]interface{}{
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2022-08-13 15:24:07 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) RequestAuthenticationPasswordRecovery() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "requestAuthenticationPasswordRecovery",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckAuthenticationPasswordRecoveryCodeRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
2021-12-30 05:55:02 +00:00
}
2022-08-13 15:24:07 +00:00
// 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
2021-12-30 05:55:02 +00:00
func (client *Client) CheckAuthenticationPasswordRecoveryCode(req *CheckAuthenticationPasswordRecoveryCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) RecoverAuthenticationPassword(req *RecoverAuthenticationPasswordRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SendAuthenticationFirebaseSmsRequest struct {
// SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application
Token string `json:"token"`
2023-02-04 22:54:46 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendAuthenticationFirebaseSms",
},
Data: map[string]interface{}{
"token": req.Token,
},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckAuthenticationBotTokenRequest struct {
// The bot token
Token string `json:"token"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) CheckAuthenticationBotToken(req *CheckAuthenticationBotTokenRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationBotToken",
},
Data: map[string]interface{}{
"token": req.Token,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "logOut",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-11-30 09:33:47 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) Close() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "close",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-11-30 09:33:47 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) Destroy() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "destroy",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ConfirmQrCodeAuthenticationRequest struct {
// A link from a QR code. The link must be scanned by the in-app camera
Link string `json:"link"`
2020-02-03 12:56:20 +00:00
}
// Confirms QR code authentication on another device. Returns created session on success
func (client *Client) ConfirmQrCodeAuthentication(req *ConfirmQrCodeAuthenticationRequest) (*Session, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "confirmQrCodeAuthentication",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSession(result.Data)
2020-02-03 12:56:20 +00:00
}
2022-12-07 20:04:16 +00:00
// 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
2019-06-07 10:56:06 +00:00
func (client *Client) GetCurrentState() (*Updates, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCurrentState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUpdates(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type SetDatabaseEncryptionKeyRequest struct {
// New encryption key
NewEncryptionKey []byte `json:"new_encryption_key"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain
2018-10-16 20:32:57 +00:00
func (client *Client) SetDatabaseEncryptionKey(req *SetDatabaseEncryptionKeyRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setDatabaseEncryptionKey",
},
Data: map[string]interface{}{
"new_encryption_key": req.NewEncryptionKey,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns the current state of 2-step verification
func (client *Client) GetPasswordState() (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetPassword(req *SetPasswordRequest) (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
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
2022-09-18 01:34:29 +00:00
func (client *Client) SetLoginEmailAddress(req *SetLoginEmailAddressRequest) (*EmailAddressAuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
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
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2022-09-18 01:34:29 +00:00
}
// Resends the login email address verification code
func (client *Client) ResendLoginEmailAddressCode() (*EmailAddressAuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendLoginEmailAddressCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckLoginEmailAddressCodeRequest struct {
// Email address authentication to check
Code EmailAddressAuthentication `json:"code"`
2022-09-18 01:34:29 +00:00
}
// Checks the login email address authentication
func (client *Client) CheckLoginEmailAddressCode(req *CheckLoginEmailAddressCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkLoginEmailAddressCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetRecoveryEmailAddressRequest struct {
// The 2-step verification password for the current user
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetRecoveryEmailAddress(req *GetRecoveryEmailAddressRequest) (*RecoveryEmailAddress, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecoveryEmailAddress",
},
Data: map[string]interface{}{
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalRecoveryEmailAddress(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetRecoveryEmailAddress(req *SetRecoveryEmailAddressRequest) (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPasswordState(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckRecoveryEmailAddressCodeRequest struct {
// Verification code to check
Code string `json:"code"`
2019-06-07 10:56:06 +00:00
}
// Checks the 2-step verification recovery email address verification code
func (client *Client) CheckRecoveryEmailAddressCode(req *CheckRecoveryEmailAddressCodeRequest) (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkRecoveryEmailAddressCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPasswordState(result.Data)
2019-06-07 10:56:06 +00:00
}
// Resends the 2-step verification recovery email address verification code
func (client *Client) ResendRecoveryEmailAddressCode() (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendRecoveryEmailAddressCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPasswordState(result.Data)
2019-06-07 10:56:06 +00:00
}
2021-12-30 05:55:02 +00:00
// Requests to send a 2-step verification password recovery code to an email address that was previously set up
2018-09-05 21:45:29 +00:00
func (client *Client) RequestPasswordRecovery() (*EmailAddressAuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "requestPasswordRecovery",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckPasswordRecoveryCodeRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
2021-12-30 05:55:02 +00:00
}
// Checks whether a 2-step verification password recovery code sent to an email address is valid
func (client *Client) CheckPasswordRecoveryCode(req *CheckPasswordRecoveryCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Recovers the 2-step verification password using a recovery code sent to an email address that was previously set up
2018-10-16 20:32:57 +00:00
func (client *Client) RecoverPassword(req *RecoverPasswordRequest) (*PasswordState, error) {
2023-03-26 09:37:06 +00:00
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)
2018-08-30 14:55:42 +00:00
}
2021-12-30 05:55:02 +00:00
// 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) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resetPassword",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeResetPasswordResultOk:
return UnmarshalResetPasswordResultOk(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeResetPasswordResultPending:
return UnmarshalResetPasswordResultPending(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeResetPasswordResultDeclined:
return UnmarshalResetPasswordResultDeclined(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2021-12-30 05:55:02 +00:00
}
// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date > 0
func (client *Client) CancelPasswordReset() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "cancelPasswordReset",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new temporary password for processing payments
2018-10-16 20:32:57 +00:00
func (client *Client) CreateTemporaryPassword(req *CreateTemporaryPasswordRequest) (*TemporaryPasswordState, error) {
2023-03-26 09:37:06 +00:00
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)
2018-08-30 14:55:42 +00:00
}
// Returns information about the current temporary password
func (client *Client) GetTemporaryPasswordState() (*TemporaryPasswordState, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getTemporaryPasswordState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTemporaryPasswordState(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns the current user
func (client *Client) GetMe() (*User, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMe",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetUserRequest struct {
// User identifier
UserId int64 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a user by their identifier. This is an offline request if the current user is not a bot
2018-10-16 20:32:57 +00:00
func (client *Client) GetUser(req *GetUserRequest) (*User, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUser",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetUserFullInfoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns full information about a user by their identifier
2018-10-16 20:32:57 +00:00
func (client *Client) GetUserFullInfo(req *GetUserFullInfoRequest) (*UserFullInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUserFullInfo",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUserFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBasicGroupRequest struct {
// Basic group identifier
BasicGroupId int64 `json:"basic_group_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a basic group by its identifier. This is an offline request if the current user is not a bot
2018-10-16 20:32:57 +00:00
func (client *Client) GetBasicGroup(req *GetBasicGroupRequest) (*BasicGroup, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBasicGroup",
},
Data: map[string]interface{}{
"basic_group_id": req.BasicGroupId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBasicGroup(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBasicGroupFullInfoRequest struct {
// Basic group identifier
BasicGroupId int64 `json:"basic_group_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns full information about a basic group by its identifier
2018-10-16 20:32:57 +00:00
func (client *Client) GetBasicGroupFullInfo(req *GetBasicGroupFullInfoRequest) (*BasicGroupFullInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBasicGroupFullInfo",
},
Data: map[string]interface{}{
"basic_group_id": req.BasicGroupId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBasicGroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetSupergroupRequest struct {
// Supergroup or channel identifier
SupergroupId int64 `json:"supergroup_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns information about a supergroup or a channel by its identifier. This is an offline request if the current user is not a bot
2018-10-16 20:32:57 +00:00
func (client *Client) GetSupergroup(req *GetSupergroupRequest) (*Supergroup, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSupergroup",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSupergroup(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetSupergroupFullInfoRequest struct {
// Supergroup or channel identifier
SupergroupId int64 `json:"supergroup_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns full information about a supergroup or a channel by its identifier, cached for up to 1 minute
2018-10-16 20:32:57 +00:00
func (client *Client) GetSupergroupFullInfo(req *GetSupergroupFullInfoRequest) (*SupergroupFullInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSupergroupFullInfo",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSupergroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetSecretChatRequest struct {
// Secret chat identifier
SecretChatId int32 `json:"secret_chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a secret chat by its identifier. This is an offline request
2018-10-16 20:32:57 +00:00
func (client *Client) GetSecretChat(req *GetSecretChatRequest) (*SecretChat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSecretChat",
},
Data: map[string]interface{}{
"secret_chat_id": req.SecretChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSecretChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns information about a chat by its identifier; this is an offline request if the current user is not a bot
2018-10-16 20:32:57 +00:00
func (client *Client) GetChat(req *GetChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a message
2018-10-16 20:32:57 +00:00
func (client *Client) GetMessage(req *GetMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
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
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessage(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2022-03-13 04:04:12 +00:00
}
// Returns information about a message, if it is available without sending network request. This is an offline request
2019-06-07 10:56:06 +00:00
func (client *Client) GetMessageLocally(req *GetMessageLocallyRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
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
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessage(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns information about a message that is replied by a given message. Also, returns the pinned message, the game message, the invoice message, and the topic creation message for messages of the types messagePinMessage, messageGameScore, messagePaymentSuccessful, messageChatSetBackground and topic messages without replied message respectively
2018-10-16 20:32:57 +00:00
func (client *Client) GetRepliedMessage(req *GetRepliedMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessage(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatPinnedMessageRequest struct {
// Identifier of the chat the message belongs to
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns information about a newest pinned message in the chat
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatPinnedMessage(req *GetChatPinnedMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
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"`
2020-11-30 09:33:47 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about messages. If a message is not found, returns null on the corresponding position of the result
2018-10-16 20:32:57 +00:00
func (client *Client) GetMessages(req *GetMessagesRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessages(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMessageThreadRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
2020-11-30 09:33:47 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
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
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageThreadInfo(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMessageViewersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
2021-12-30 05:55:02 +00:00
}
// 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
2023-03-11 11:13:56 +00:00
func (client *Client) GetMessageViewers(req *GetMessageViewersRequest) (*MessageViewers, error) {
2023-03-26 09:37:06 +00:00
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
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageViewers(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetFileRequest struct {
// Identifier of the file to get
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a file; this is an offline request
2018-10-16 20:32:57 +00:00
func (client *Client) GetFile(req *GetFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFile(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2023-09-16 07:09:40 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetRemoteFile(req *GetRemoteFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFile(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2021-12-30 05:55:02 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
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
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetChats(req *GetChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchPublicChatRequest struct {
// Username to be resolved
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2023-02-04 22:54:46 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SearchPublicChat(req *SearchPublicChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchPublicChat",
},
Data: map[string]interface{}{
"username": req.Username,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchPublicChatsRequest struct {
// Query to search for
Query string `json:"query"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SearchPublicChats(req *SearchPublicChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchPublicChats",
},
Data: map[string]interface{}{
"query": req.Query,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChats(req *SearchChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchChatsOnServerRequest struct {
// Query to search for
Query string `json:"query"`
// The maximum number of chats to be returned
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChatsOnServer(req *SearchChatsOnServerRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchChatsNearbyRequest struct {
// Current user location
Location *Location `json:"location"`
2020-02-03 12:56:20 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2020-02-03 12:56:20 +00:00
func (client *Client) SearchChatsNearby(req *SearchChatsNearbyRequest) (*ChatsNearby, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchChatsNearby",
},
Data: map[string]interface{}{
"location": req.Location,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatsNearby(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
// Returns a list of frequently used chats
2018-10-16 20:32:57 +00:00
func (client *Client) GetTopChats(req *GetTopChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveTopChatRequest struct {
// Category of frequently used chats
Category TopChatCategory `json:"category"`
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a chat from the list of frequently used chats. Supported only if the chat info database is enabled
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveTopChat(req *RemoveTopChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
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)
}
2023-03-26 09:37:06 +00:00
type AddRecentlyFoundChatRequest struct {
// Identifier of the chat to add
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) AddRecentlyFoundChat(req *AddRecentlyFoundChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addRecentlyFoundChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveRecentlyFoundChatRequest struct {
// Identifier of the chat to be removed
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a chat from the list of recently found chats
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveRecentlyFoundChat(req *RemoveRecentlyFoundChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeRecentlyFoundChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Clears the list of recently found chats
func (client *Client) ClearRecentlyFoundChats() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearRecentlyFoundChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetRecentlyOpenedChatsRequest struct {
// The maximum number of chats to be returned
Limit int32 `json:"limit"`
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns recently opened chats; this is an offline request. Returns chats in the order of last opening
2021-12-30 05:55:02 +00:00
func (client *Client) GetRecentlyOpenedChats(req *GetRecentlyOpenedChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecentlyOpenedChats",
},
Data: map[string]interface{}{
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckChatUsernameRequest struct {
2023-09-16 07:09:40 +00:00
// 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
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
// Username to be checked
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks whether a username can be set for a chat
2018-10-16 20:32:57 +00:00
func (client *Client) CheckChatUsername(req *CheckChatUsernameRequest) (CheckChatUsernameResult, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeCheckChatUsernameResultOk:
return UnmarshalCheckChatUsernameResultOk(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeCheckChatUsernameResultUsernameInvalid:
return UnmarshalCheckChatUsernameResultUsernameInvalid(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeCheckChatUsernameResultUsernameOccupied:
return UnmarshalCheckChatUsernameResultUsernameOccupied(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeCheckChatUsernameResultUsernamePurchasable:
return UnmarshalCheckChatUsernameResultUsernamePurchasable(result.Data)
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
case TypeCheckChatUsernameResultPublicChatsTooMany:
return UnmarshalCheckChatUsernameResultPublicChatsTooMany(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeCheckChatUsernameResultPublicGroupsUnavailable:
return UnmarshalCheckChatUsernameResultPublicGroupsUnavailable(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetCreatedPublicChatsRequest struct {
// Type of the public chats to return
Type PublicChatType `json:"type"`
2020-02-03 12:56:20 +00:00
}
// Returns a list of public chats of the specified type, owned by the user
func (client *Client) GetCreatedPublicChats(req *GetCreatedPublicChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCreatedPublicChats",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckCreatedPublicChatsLimitRequest struct {
// Type of the public chats, for which to check the limit
Type PublicChatType `json:"type"`
2020-02-03 12:56:20 +00:00
}
2022-06-21 18:10:07 +00:00
// 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
2020-02-03 12:56:20 +00:00
func (client *Client) CheckCreatedPublicChatsLimit(req *CheckCreatedPublicChatsLimitRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkCreatedPublicChatsLimit",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2020-11-30 09:33:47 +00:00
// 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
2020-02-03 12:56:20 +00:00
func (client *Client) GetSuitableDiscussionChats() (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSuitableDiscussionChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2020-02-03 12:56:20 +00:00
}
2022-06-21 18:10:07 +00:00
// 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
2020-02-03 12:56:20 +00:00
func (client *Client) GetInactiveSupergroupChats() (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInactiveSupergroupChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns a list of common group chats with a given user. Chats are sorted by their type and creation date
2018-10-16 20:32:57 +00:00
func (client *Client) GetGroupsInCommon(req *GetGroupsInCommonRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
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 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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatHistory(req *GetChatHistoryRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
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 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"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2020-11-30 09:33:47 +00:00
func (client *Client) GetMessageThreadHistory(req *GetMessageThreadHistoryRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteChatHistory(req *DeleteChatHistoryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
2022-11-07 18:50:52 +00:00
// 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
2021-12-30 05:55:02 +00:00
func (client *Client) DeleteChat(req *DeleteChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
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 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"`
2018-10-16 20:32:57 +00:00
}
2022-11-07 18:50:52 +00:00
// 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
2022-12-30 18:28:59 +00:00
func (client *Client) SearchChatMessages(req *SearchChatMessagesRequest) (*FoundChatMessages, error) {
2023-03-26 09:37:06 +00:00
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,
},
})
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2022-12-30 18:28:59 +00:00
func (client *Client) SearchMessages(req *SearchMessagesRequest) (*FoundMessages, error) {
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SearchSecretMessages(req *SearchSecretMessagesRequest) (*FoundMessages, error) {
2023-03-26 09:37:06 +00:00
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 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"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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
2022-12-30 18:28:59 +00:00
func (client *Client) SearchCallMessages(req *SearchCallMessagesRequest) (*FoundMessages, error) {
2023-03-26 09:37:06 +00:00
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"`
2022-03-13 04:04:12 +00:00
}
// 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) {
2023-03-26 09:37:06 +00:00
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
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFoundMessages(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteAllCallMessagesRequest struct {
// Pass true to delete the messages for all users
Revoke bool `json:"revoke"`
2021-12-30 05:55:02 +00:00
}
// Deletes all call messages
func (client *Client) DeleteAllCallMessages(req *DeleteAllCallMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteAllCallMessages",
},
Data: map[string]interface{}{
"revoke": req.Revoke,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchChatRecentLocationMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The maximum number of messages to be returned
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChatRecentLocationMessages(req *SearchChatRecentLocationMessagesRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
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)
2018-08-30 14:55:42 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
2018-08-30 14:55:42 +00:00
func (client *Client) GetActiveLiveLocationMessages() (*Messages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getActiveLiveLocationMessages",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessages(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns the last message sent in a chat no later than the specified date
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatMessageByDate(req *GetChatMessageByDateRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatMessageByDate",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"date": req.Date,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type GetChatSparseMessagePositionsRequest struct {
// Identifier of the chat in which to return information about message positions
ChatId int64 `json:"chat_id"`
// Filter for message content. Filters searchMessagesFilterEmpty, searchMessagesFilterMention, searchMessagesFilterUnreadMention, and searchMessagesFilterUnreadReaction are unsupported in this function
Filter SearchMessagesFilter `json:"filter"`
// The message identifier from which to return information about message positions
FromMessageId int64 `json:"from_message_id"`
// The expected number of message positions to be returned; 50-2000. A smaller number of positions can be returned, if there are not enough appropriate messages
Limit int32 `json:"limit"`
2021-12-30 05:55:02 +00:00
}
// Returns sparse positions of messages of the specified type in the chat to be used for shared media scroll implementation. Returns the results in reverse chronological order (i.e., in order of decreasing message_id). Cannot be used in secret chats or with searchMessagesFilterFailedToSend filter without an enabled message database
func (client *Client) GetChatSparseMessagePositions(req *GetChatSparseMessagePositionsRequest) (*MessagePositions, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatSparseMessagePositions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"filter": req.Filter,
"from_message_id": req.FromMessageId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessagePositions(result.Data)
}
type GetChatMessageCalendarRequest struct {
// Identifier of the chat in which to return information about messages
ChatId int64 `json:"chat_id"`
// Filter for message content. Filters searchMessagesFilterEmpty, searchMessagesFilterMention, searchMessagesFilterUnreadMention, and searchMessagesFilterUnreadReaction are unsupported in this function
Filter SearchMessagesFilter `json:"filter"`
// The message identifier from which to return information about messages; use 0 to get results from the last message
FromMessageId int64 `json:"from_message_id"`
2021-12-30 05:55:02 +00:00
}
// Returns information about the next messages of the specified type in the chat split by days. Returns the results in reverse chronological order. Can return partial result for the last returned day. Behavior of this method depends on the value of the option "utc_time_offset"
func (client *Client) GetChatMessageCalendar(req *GetChatMessageCalendarRequest) (*MessageCalendar, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatMessageCalendar",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"filter": req.Filter,
"from_message_id": req.FromMessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageCalendar(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"`
// Pass true to get the number of messages without sending network requests, or -1 if the number of messages is unknown locally
ReturnLocal bool `json:"return_local"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns approximate number of messages of the specified type in the chat
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatMessageCount(req *GetChatMessageCountRequest) (*Count, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatMessageCount",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"filter": req.Filter,
"return_local": req.ReturnLocal,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalCount(result.Data)
}
type GetChatMessagePositionRequest struct {
// Identifier of the chat in which to find message position
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// Filter for message content; searchMessagesFilterEmpty, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, and searchMessagesFilterFailedToSend are unsupported in this function
Filter SearchMessagesFilter `json:"filter"`
// If not 0, only messages in the specified thread will be considered; supergroups only
MessageThreadId int64 `json:"message_thread_id"`
2022-11-07 18:50:52 +00:00
}
// Returns approximate 1-based position of a message among messages, which can be found by the specified filter in the chat. Cannot be used in secret chats
func (client *Client) GetChatMessagePosition(req *GetChatMessagePositionRequest) (*Count, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatMessagePosition",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"filter": req.Filter,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalCount(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatScheduledMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2020-02-03 12:56:20 +00:00
}
// Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id)
func (client *Client) GetChatScheduledMessages(req *GetChatScheduledMessagesRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatScheduledMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type GetMessagePublicForwardsRequest struct {
// Chat identifier of the message
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// 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; must be positive and can't be greater than 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"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns forwarded copies of a channel message to different public channels. For optimal performance, the number of returned messages is chosen by TDLib
2020-11-30 09:33:47 +00:00
func (client *Client) GetMessagePublicForwards(req *GetMessagePublicForwardsRequest) (*FoundMessages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessagePublicForwards",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFoundMessages(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatSponsoredMessagesRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
2022-11-07 18:50:52 +00:00
// Returns sponsored messages to be shown in a chat; for channel chats only
func (client *Client) GetChatSponsoredMessages(req *GetChatSponsoredMessagesRequest) (*SponsoredMessages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatSponsoredMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSponsoredMessages(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
type ClickChatSponsoredMessageRequest struct {
// Chat identifier of the sponsored message
ChatId int64 `json:"chat_id"`
// Identifier of the sponsored message
MessageId int64 `json:"message_id"`
}
// Informs TDLib that the user opened the sponsored chat via the button, the name, the photo, or a mention in the sponsored message
func (client *Client) ClickChatSponsoredMessage(req *ClickChatSponsoredMessageRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "clickChatSponsoredMessage",
},
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 UnmarshalOk(result.Data)
}
2023-03-26 09:37:06 +00:00
type RemoveNotificationRequest struct {
// Identifier of notification group to which the notification belongs
NotificationGroupId int32 `json:"notification_group_id"`
// Identifier of removed notification
NotificationId int32 `json:"notification_id"`
2019-06-07 10:56:06 +00:00
}
// Removes an active notification from notification list. Needs to be called only if the notification is removed by the current user
func (client *Client) RemoveNotification(req *RemoveNotificationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeNotification",
},
Data: map[string]interface{}{
"notification_group_id": req.NotificationGroupId,
"notification_id": req.NotificationId,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveNotificationGroupRequest struct {
// Notification group identifier
NotificationGroupId int32 `json:"notification_group_id"`
// The maximum identifier of removed notifications
MaxNotificationId int32 `json:"max_notification_id"`
2019-06-07 10:56:06 +00:00
}
// Removes a group of active notifications. Needs to be called only if the notification group is removed by the current user
func (client *Client) RemoveNotificationGroup(req *RemoveNotificationGroupRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeNotificationGroup",
},
Data: map[string]interface{}{
"notification_group_id": req.NotificationGroupId,
"max_notification_id": req.MaxNotificationId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetMessageLinkRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// If not 0, timestamp from which the video/audio/video note/voice note playing must start, in seconds. The media can be in the message content or in its web page preview
MediaTimestamp int32 `json:"media_timestamp"`
// Pass true to create a link for the whole media album
ForAlbum bool `json:"for_album"`
// Pass true to create a link to the message as a channel post comment, in a message thread, or a forum topic
InMessageThread bool `json:"in_message_thread"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns an HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels, or if message.can_get_media_timestamp_links and a media timestamp link is generated. This is an offline request
2020-11-30 09:33:47 +00:00
func (client *Client) GetMessageLink(req *GetMessageLinkRequest) (*MessageLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"media_timestamp": req.MediaTimestamp,
"for_album": req.ForAlbum,
"in_message_thread": req.InMessageThread,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageLink(result.Data)
}
type GetMessageEmbeddingCodeRequest 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 to return an HTML code for embedding of the whole media album
ForAlbum bool `json:"for_album"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns an HTML code for embedding the message. Available only for messages in supergroups and channels with a username
func (client *Client) GetMessageEmbeddingCode(req *GetMessageEmbeddingCodeRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageEmbeddingCode",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"for_album": req.ForAlbum,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMessageLinkInfoRequest struct {
// The message link
Url string `json:"url"`
2019-09-10 12:36:54 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns information about a public or private message link. Can be called for any internal link of the type internalLinkTypeMessage
2019-09-10 12:36:54 +00:00
func (client *Client) GetMessageLinkInfo(req *GetMessageLinkInfoRequest) (*MessageLinkInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLinkInfo",
},
Data: map[string]interface{}{
"url": req.Url,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageLinkInfo(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type TranslateTextRequest struct {
// Text to translate
Text *FormattedText `json:"text"`
// Language code of the language to which the message is translated. Must be one of "af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "zh-CN", "zh", "zh-Hans", "zh-TW", "zh-Hant", "co", "hr", "cs", "da", "nl", "en", "eo", "et", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu"
ToLanguageCode string `json:"to_language_code"`
2022-02-06 18:36:17 +00:00
}
2023-02-04 22:54:46 +00:00
// Translates a text to the given language. If the current user is a Telegram Premium user, then text formatting is preserved
func (client *Client) TranslateText(req *TranslateTextRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "translateText",
},
Data: map[string]interface{}{
"text": req.Text,
"to_language_code": req.ToLanguageCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFormattedText(result.Data)
}
type TranslateMessageTextRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Language code of the language to which the message is translated. Must be one of "af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "zh-CN", "zh", "zh-Hans", "zh-TW", "zh-Hant", "co", "hr", "cs", "da", "nl", "en", "eo", "et", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu"
ToLanguageCode string `json:"to_language_code"`
2023-02-04 22:54:46 +00:00
}
// Extracts text or caption of the given message and translates it to the given language. If the current user is a Telegram Premium user, then text formatting is preserved
func (client *Client) TranslateMessageText(req *TranslateMessageTextRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "translateMessageText",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"to_language_code": req.ToLanguageCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFormattedText(result.Data)
}
type RecognizeSpeechRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
2022-06-21 18:10:07 +00:00
}
2022-11-07 18:50:52 +00:00
// Recognizes speech in a video note or a voice note message. The message must be successfully sent and must not be scheduled. May return an error with a message "MSG_VOICE_TOO_LONG" if media duration is too big to be recognized
2022-06-21 18:10:07 +00:00
func (client *Client) RecognizeSpeech(req *RecognizeSpeechRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "recognizeSpeech",
},
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 UnmarshalOk(result.Data)
}
type RateSpeechRecognitionRequest 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 the speech recognition is good
IsGood bool `json:"is_good"`
2022-06-21 18:10:07 +00:00
}
2022-11-07 18:50:52 +00:00
// Rates recognized speech in a video note or a voice note message
2022-06-21 18:10:07 +00:00
func (client *Client) RateSpeechRecognition(req *RateSpeechRecognitionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "rateSpeechRecognition",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"is_good": req.IsGood,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatAvailableMessageSendersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
// Returns list of message sender identifiers, which can be used to send messages in a chat
2022-11-07 18:50:52 +00:00
func (client *Client) GetChatAvailableMessageSenders(req *GetChatAvailableMessageSendersRequest) (*ChatMessageSenders, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatAvailableMessageSenders",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatMessageSenders(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SetChatMessageSenderRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New message sender for the chat
MessageSenderId MessageSender `json:"message_sender_id"`
2021-12-30 05:55:02 +00:00
}
// Selects a message sender to send messages in a chat
func (client *Client) SetChatMessageSender(req *SetChatMessageSenderRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatMessageSender",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_sender_id": req.MessageSenderId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SendMessageRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// If not 0, a message thread identifier in which the message will be sent
MessageThreadId int64 `json:"message_thread_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the replied message or story; pass null if none
ReplyTo MessageReplyTo `json:"reply_to"`
2023-03-26 09:37:06 +00:00
// Options to be used to send the message; pass null to use default options
Options *MessageSendOptions `json:"options"`
// Markup for replying to the message; pass null if none; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// The content of the message to be sent
InputMessageContent InputMessageContent `json:"input_message_content"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a message. Returns the sent message
2018-10-16 20:32:57 +00:00
func (client *Client) SendMessage(req *SendMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
2023-07-24 18:35:55 +00:00
"reply_to": req.ReplyTo,
2023-03-26 09:37:06 +00:00
"options": req.Options,
"reply_markup": req.ReplyMarkup,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type SendMessageAlbumRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// If not 0, a message thread identifier in which the messages will be sent
MessageThreadId int64 `json:"message_thread_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the replied message or story; pass null if none
ReplyTo MessageReplyTo `json:"reply_to"`
2023-03-26 09:37:06 +00:00
// Options to be used to send the messages; pass null to use default options
Options *MessageSendOptions `json:"options"`
// Contents of messages to be sent. At most 10 messages can be added to an album
InputMessageContents []InputMessageContent `json:"input_message_contents"`
// Pass true to get fake messages instead of actually sending them
OnlyPreview bool `json:"only_preview"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Sends 2-10 messages grouped together into an album. Currently, only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages
2018-10-16 20:32:57 +00:00
func (client *Client) SendMessageAlbum(req *SendMessageAlbumRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendMessageAlbum",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
2023-07-24 18:35:55 +00:00
"reply_to": req.ReplyTo,
2023-03-26 09:37:06 +00:00
"options": req.Options,
"input_message_contents": req.InputMessageContents,
"only_preview": req.OnlyPreview,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type SendBotStartMessageRequest struct {
// Identifier of the bot
BotUserId int64 `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://core.telegram.org/bots#deep-linking)
Parameter string `json:"parameter"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SendBotStartMessage(req *SendBotStartMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendBotStartMessage",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"chat_id": req.ChatId,
"parameter": req.Parameter,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type SendInlineQueryResultMessageRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// If not 0, a message thread identifier in which the message will be sent
MessageThreadId int64 `json:"message_thread_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the replied message or story; pass null if none
ReplyTo MessageReplyTo `json:"reply_to"`
2023-03-26 09:37:06 +00:00
// Options to be used to send the message; pass null to use default options
Options *MessageSendOptions `json:"options"`
// Identifier of the inline query
QueryId JsonInt64 `json:"query_id"`
2023-08-15 18:28:13 +00:00
// Identifier of the inline query result
2023-03-26 09:37:06 +00:00
ResultId string `json:"result_id"`
// Pass true to hide the bot, via which the message is sent. Can be used only for bots getOption("animation_search_bot_username"), getOption("photo_search_bot_username"), and getOption("venue_search_bot_username")
HideViaBot bool `json:"hide_via_bot"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends the result of an inline query as a message. Returns the sent message. Always clears a chat draft message
2018-10-16 20:32:57 +00:00
func (client *Client) SendInlineQueryResultMessage(req *SendInlineQueryResultMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendInlineQueryResultMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
2023-07-24 18:35:55 +00:00
"reply_to": req.ReplyTo,
2023-03-26 09:37:06 +00:00
"options": req.Options,
"query_id": req.QueryId,
"result_id": req.ResultId,
"hide_via_bot": req.HideViaBot,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type ForwardMessagesRequest struct {
// Identifier of the chat to which to forward messages
ChatId int64 `json:"chat_id"`
// If not 0, a message thread identifier in which the message will be sent; for forum threads only
MessageThreadId int64 `json:"message_thread_id"`
// Identifier of the chat from which to forward messages
FromChatId int64 `json:"from_chat_id"`
// Identifiers of the messages to forward. Message identifiers must be in a strictly increasing order. At most 100 messages can be forwarded simultaneously
MessageIds []int64 `json:"message_ids"`
// Options to be used to send the messages; pass null to use default options
Options *MessageSendOptions `json:"options"`
// Pass true to copy content of the messages without reference to the original sender. Always true if the messages are forwarded to a secret chat or are local
SendCopy bool `json:"send_copy"`
// Pass true to remove media captions of message copies. Ignored if send_copy is false
RemoveCaption bool `json:"remove_caption"`
// Pass true to get fake messages instead of actually forwarding them
OnlyPreview bool `json:"only_preview"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) ForwardMessages(req *ForwardMessagesRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "forwardMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"from_chat_id": req.FromChatId,
"message_ids": req.MessageIds,
"options": req.Options,
"send_copy": req.SendCopy,
"remove_caption": req.RemoveCaption,
"only_preview": req.OnlyPreview,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type ResendMessagesRequest struct {
// Identifier of the chat to send messages
ChatId int64 `json:"chat_id"`
// Identifiers of the messages to resend. Message identifiers must be in a strictly increasing order
MessageIds []int64 `json:"message_ids"`
2019-09-10 12:36:54 +00:00
}
// Resends messages which failed to send. Can be called only for messages for which messageSendingStateFailed.can_retry is true and after specified in messageSendingStateFailed.retry_after time passed. If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message
func (client *Client) ResendMessages(req *ResendMessagesRequest) (*Messages, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessages(result.Data)
2018-10-23 12:38:10 +00:00
}
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
func (client *Client) SendChatScreenshotTakenNotification(req *SendChatScreenshotTakenNotificationRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "sendChatScreenshotTakenNotification",
},
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)
}
2023-03-26 09:37:06 +00:00
type AddLocalMessageRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// Identifier of the sender of the message
SenderId MessageSender `json:"sender_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the replied message or story; pass null if none
ReplyTo MessageReplyTo `json:"reply_to"`
2023-03-26 09:37:06 +00:00
// 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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) AddLocalMessage(req *AddLocalMessageRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addLocalMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"sender_id": req.SenderId,
2023-07-24 18:35:55 +00:00
"reply_to": req.ReplyTo,
2023-03-26 09:37:06 +00:00
"disable_notification": req.DisableNotification,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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 delete messages for all chat members. Always true for supergroups, channels and secret chats
Revoke bool `json:"revoke"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Deletes messages
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteMessages(req *DeleteMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
"revoke": req.Revoke,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteChatMessagesBySenderRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the sender of messages to delete
SenderId MessageSender `json:"sender_id"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Deletes all messages sent by the specified message sender in a chat. Supported only for supergroups; requires can_delete_messages administrator privileges
func (client *Client) DeleteChatMessagesBySender(req *DeleteChatMessagesBySenderRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteChatMessagesBySender",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"sender_id": req.SenderId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteChatMessagesByDateRequest struct {
// Chat identifier
ChatId int64 `json:"chat_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"`
// Pass true to delete chat messages for all users; private chats only
Revoke bool `json:"revoke"`
2021-12-30 05:55:02 +00:00
}
// Deletes all messages between the specified dates in a chat. Supported only for private chats and basic groups. Messages sent in the last 30 seconds will not be deleted
func (client *Client) DeleteChatMessagesByDate(req *DeleteChatMessagesByDateRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteChatMessagesByDate",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"min_date": req.MinDate,
"max_date": req.MaxDate,
"revoke": req.Revoke,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; pass null if none; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New text content of the message. Must be of type inputMessageText
InputMessageContent InputMessageContent `json:"input_message_content"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageText(req *EditMessageTextRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageText",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; pass null if none; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New location content of the message; pass null to stop sharing the live location
Location *Location `json:"location"`
// The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown
Heading int32 `json:"heading"`
// The new maximum distance for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled
ProximityAlertRadius int32 `json:"proximity_alert_radius"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageLiveLocation(req *EditMessageLiveLocationRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageLiveLocation",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
"location": req.Location,
"heading": req.Heading,
"proximity_alert_radius": req.ProximityAlertRadius,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; pass null if none; 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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Edits the content of a message with an animation, an audio, a document, a photo or a video, including message caption. If only the caption needs to be edited, use editMessageCaption instead. The media can't be edited if the message was set to self-destruct or to a self-destructing media. The type of message content in an album can't be changed with exception of replacing a photo with a video or vice versa. Returns the edited message after the edit is completed on the server side
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageMedia(req *EditMessageMediaRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageMedia",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; pass null if none; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New message content caption; 0-getOption("message_caption_length_max") characters; pass null to remove caption
Caption *FormattedText `json:"caption"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Edits the message content caption. Returns the edited message after the edit is completed on the server side
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageCaption(req *EditMessageCaptionRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageCaption",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
"caption": req.Caption,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; pass null if none
ReplyMarkup ReplyMarkup `json:"reply_markup"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Edits the message reply markup; for bots only. Returns the edited message after the edit is completed on the server side
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageReplyMarkup(req *EditMessageReplyMarkupRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageReplyMarkup",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type EditInlineMessageTextRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// The new message reply markup; pass null if none
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New text content of the message. Must be of type inputMessageText
InputMessageContent InputMessageContent `json:"input_message_content"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Edits the text of an inline text or game message sent via a bot; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) EditInlineMessageText(req *EditInlineMessageTextRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editInlineMessageText",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"reply_markup": req.ReplyMarkup,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type EditInlineMessageLiveLocationRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// The new message reply markup; pass null if none
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New location content of the message; pass null to stop sharing the live location
Location *Location `json:"location"`
// The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown
Heading int32 `json:"heading"`
// The new maximum distance for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled
ProximityAlertRadius int32 `json:"proximity_alert_radius"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Edits the content of a live location in an inline message sent via a bot; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) EditInlineMessageLiveLocation(req *EditInlineMessageLiveLocationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editInlineMessageLiveLocation",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"reply_markup": req.ReplyMarkup,
"location": req.Location,
"heading": req.Heading,
"proximity_alert_radius": req.ProximityAlertRadius,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type EditInlineMessageMediaRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// The new message reply markup; pass null if none; 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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) EditInlineMessageMedia(req *EditInlineMessageMediaRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editInlineMessageMedia",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"reply_markup": req.ReplyMarkup,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type EditInlineMessageCaptionRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// The new message reply markup; pass null if none
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New message content caption; pass null to remove caption; 0-getOption("message_caption_length_max") characters
Caption *FormattedText `json:"caption"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Edits the caption of an inline message sent via a bot; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) EditInlineMessageCaption(req *EditInlineMessageCaptionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editInlineMessageCaption",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"reply_markup": req.ReplyMarkup,
"caption": req.Caption,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type EditInlineMessageReplyMarkupRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// The new message reply markup; pass null if none
ReplyMarkup ReplyMarkup `json:"reply_markup"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Edits the reply markup of an inline message sent via a bot; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) EditInlineMessageReplyMarkup(req *EditInlineMessageReplyMarkupRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editInlineMessageReplyMarkup",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"reply_markup": req.ReplyMarkup,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type EditMessageSchedulingStateRequest struct {
// The chat the message belongs to
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// The new message scheduling state; pass null to send the message immediately
SchedulingState MessageSchedulingState `json:"scheduling_state"`
2020-02-03 12:56:20 +00:00
}
// Edits the time when a scheduled message will be sent. Scheduling state of all messages in the same album or forwarded together with the message will be also changed
func (client *Client) EditMessageSchedulingState(req *EditMessageSchedulingStateRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editMessageSchedulingState",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"scheduling_state": req.SchedulingState,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2022-11-07 18:50:52 +00:00
// Returns list of custom emojis, which can be used as forum topic icon by all users
func (client *Client) GetForumTopicDefaultIcons() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getForumTopicDefaultIcons",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type CreateForumTopicRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Name of the topic; 1-128 characters
Name string `json:"name"`
// Icon of the topic. Icon color must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. Telegram Premium users can use any custom emoji as topic icon, other users can use only a custom emoji returned by getForumTopicDefaultIcons
Icon *ForumTopicIcon `json:"icon"`
2022-11-07 18:50:52 +00:00
}
// Creates a topic in a forum supergroup chat; requires can_manage_topics rights in the supergroup
func (client *Client) CreateForumTopic(req *CreateForumTopicRequest) (*ForumTopicInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createForumTopic",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"name": req.Name,
"icon": req.Icon,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalForumTopicInfo(result.Data)
}
type EditForumTopicRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
// New name of the topic; 0-128 characters. If empty, the previous topic name is kept
Name string `json:"name"`
// Pass true to edit the icon of the topic. Icon of the General topic can't be edited
EditIconCustomEmoji bool `json:"edit_icon_custom_emoji"`
// Identifier of the new custom emoji for topic icon; pass 0 to remove the custom emoji. Ignored if edit_icon_custom_emoji is false. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons
IconCustomEmojiId JsonInt64 `json:"icon_custom_emoji_id"`
2022-11-07 18:50:52 +00:00
}
2022-12-30 18:28:59 +00:00
// Edits title and icon of a topic in a forum supergroup chat; requires can_manage_topics administrator right in the supergroup unless the user is creator of the topic
2022-11-07 18:50:52 +00:00
func (client *Client) EditForumTopic(req *EditForumTopicRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editForumTopic",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"name": req.Name,
"edit_icon_custom_emoji": req.EditIconCustomEmoji,
"icon_custom_emoji_id": req.IconCustomEmojiId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetForumTopicRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
2022-12-07 20:04:16 +00:00
}
// Returns information about a forum topic
func (client *Client) GetForumTopic(req *GetForumTopicRequest) (*ForumTopic, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getForumTopic",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalForumTopic(result.Data)
2022-12-07 20:04:16 +00:00
}
2023-03-26 09:37:06 +00:00
type GetForumTopicLinkRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
2022-12-07 20:04:16 +00:00
}
// Returns an HTTPS link to a topic in a forum chat. This is an offline request
2022-12-30 18:28:59 +00:00
func (client *Client) GetForumTopicLink(req *GetForumTopicLinkRequest) (*MessageLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getForumTopicLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageLink(result.Data)
}
type GetForumTopicsRequest struct {
// Identifier of the forum chat
ChatId int64 `json:"chat_id"`
// Query to search for in the forum topic's name
Query string `json:"query"`
// The date starting from which the results need to be fetched. Use 0 or any date in the future to get results from the last topic
OffsetDate int32 `json:"offset_date"`
// The message identifier of the last message in the last found topic, or 0 for the first request
OffsetMessageId int64 `json:"offset_message_id"`
// The message thread identifier of the last found topic, or 0 for the first request
OffsetMessageThreadId int64 `json:"offset_message_thread_id"`
// The maximum number of forum topics to be returned; up to 100. For optimal performance, the number of returned forum topics is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
2022-12-07 20:04:16 +00:00
}
// Returns found forum topics in a forum chat. This is a temporary method for getting information about topic list from the server
func (client *Client) GetForumTopics(req *GetForumTopicsRequest) (*ForumTopics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getForumTopics",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"offset_date": req.OffsetDate,
"offset_message_id": req.OffsetMessageId,
"offset_message_thread_id": req.OffsetMessageThreadId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalForumTopics(result.Data)
}
type SetForumTopicNotificationSettingsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
// New notification settings for the forum topic. If the topic is muted for more than 366 days, it is considered to be muted forever
NotificationSettings *ChatNotificationSettings `json:"notification_settings"`
2022-12-07 20:04:16 +00:00
}
// Changes the notification settings of a forum topic
func (client *Client) SetForumTopicNotificationSettings(req *SetForumTopicNotificationSettingsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setForumTopicNotificationSettings",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"notification_settings": req.NotificationSettings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleForumTopicIsClosedRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
// Pass true to close the topic; pass false to reopen it
IsClosed bool `json:"is_closed"`
2022-11-07 18:50:52 +00:00
}
2022-12-30 18:28:59 +00:00
// Toggles whether a topic is closed in a forum supergroup chat; requires can_manage_topics administrator right in the supergroup unless the user is creator of the topic
2022-11-07 18:50:52 +00:00
func (client *Client) ToggleForumTopicIsClosed(req *ToggleForumTopicIsClosedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleForumTopicIsClosed",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"is_closed": req.IsClosed,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleGeneralForumTopicIsHiddenRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Pass true to hide and close the General topic; pass false to unhide it
IsHidden bool `json:"is_hidden"`
2022-12-07 20:04:16 +00:00
}
2022-12-30 18:28:59 +00:00
// Toggles whether a General topic is hidden in a forum supergroup chat; requires can_manage_topics administrator right in the supergroup
2022-12-07 20:04:16 +00:00
func (client *Client) ToggleGeneralForumTopicIsHidden(req *ToggleGeneralForumTopicIsHiddenRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGeneralForumTopicIsHidden",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"is_hidden": req.IsHidden,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleForumTopicIsPinnedRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
// Pass true to pin the topic; pass false to unpin it
IsPinned bool `json:"is_pinned"`
2022-12-30 18:28:59 +00:00
}
// Changes the pinned state of a forum topic; requires can_manage_topics administrator right in the supergroup. There can be up to getOption("pinned_forum_topic_count_max") pinned forum topics
func (client *Client) ToggleForumTopicIsPinned(req *ToggleForumTopicIsPinnedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleForumTopicIsPinned",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"is_pinned": req.IsPinned,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetPinnedForumTopicsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The new list of pinned forum topics
MessageThreadIds []int64 `json:"message_thread_ids"`
2022-12-30 18:28:59 +00:00
}
// Changes the order of pinned forum topics
func (client *Client) SetPinnedForumTopics(req *SetPinnedForumTopicsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setPinnedForumTopics",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_ids": req.MessageThreadIds,
},
})
if err != nil {
return nil, err
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-30 18:28:59 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteForumTopicRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier of the forum topic
MessageThreadId int64 `json:"message_thread_id"`
2022-11-07 18:50:52 +00:00
}
2022-12-30 18:28:59 +00:00
// Deletes all messages in a forum topic; requires can_delete_messages administrator right in the supergroup unless the user is creator of the topic, the topic has no messages from other users and has at most 11 messages
2022-11-07 18:50:52 +00:00
func (client *Client) DeleteForumTopic(req *DeleteForumTopicRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteForumTopic",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type GetEmojiReactionRequest struct {
// Text representation of the reaction
Emoji string `json:"emoji"`
2022-09-18 01:34:29 +00:00
}
// Returns information about a emoji reaction. Returns a 404 error if the reaction is not found
func (client *Client) GetEmojiReaction(req *GetEmojiReactionRequest) (*EmojiReaction, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getEmojiReaction",
},
Data: map[string]interface{}{
"emoji": req.Emoji,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojiReaction(result.Data)
2022-09-18 01:34:29 +00:00
}
2022-11-07 18:50:52 +00:00
// Returns TGS stickers with generic animations for custom emoji reactions
func (client *Client) GetCustomEmojiReactionAnimations() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCustomEmojiReactionAnimations",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMessageAvailableReactionsRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Number of reaction per row, 5-25
RowSize int32 `json:"row_size"`
2022-02-06 18:36:17 +00:00
}
2022-09-18 01:34:29 +00:00
// Returns reactions, which can be added to a message. The list can change after updateActiveEmojiReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message
2022-02-06 18:36:17 +00:00
func (client *Client) GetMessageAvailableReactions(req *GetMessageAvailableReactionsRequest) (*AvailableReactions, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageAvailableReactions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"row_size": req.RowSize,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAvailableReactions(result.Data)
2022-03-13 04:04:12 +00:00
}
2022-09-18 01:34:29 +00:00
// Clears the list of recently used reactions
func (client *Client) ClearRecentReactions() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearRecentReactions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AddMessageReactionRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Type of the reaction to add
ReactionType ReactionType `json:"reaction_type"`
// Pass true if the reaction is added with a big animation
IsBig bool `json:"is_big"`
// Pass true if the reaction needs to be added to recent reactions
UpdateRecentReactions bool `json:"update_recent_reactions"`
2022-02-06 18:36:17 +00:00
}
2022-09-18 01:34:29 +00:00
// Adds a reaction to a message. Use getMessageAvailableReactions to receive the list of available reactions for the message
func (client *Client) AddMessageReaction(req *AddMessageReactionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addMessageReaction",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reaction_type": req.ReactionType,
"is_big": req.IsBig,
"update_recent_reactions": req.UpdateRecentReactions,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RemoveMessageReactionRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Type of the reaction to remove
ReactionType ReactionType `json:"reaction_type"`
2022-09-18 01:34:29 +00:00
}
// Removes a reaction from a message. A chosen reaction can always be removed
func (client *Client) RemoveMessageReaction(req *RemoveMessageReactionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeMessageReaction",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reaction_type": req.ReactionType,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetMessageAddedReactionsRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Type of the reactions to return; pass null to return all added reactions
ReactionType ReactionType `json:"reaction_type"`
// 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 reactions to be returned; must be positive and can't be greater than 100
Limit int32 `json:"limit"`
2022-02-06 18:36:17 +00:00
}
// Returns reactions added for a message, along with their sender
func (client *Client) GetMessageAddedReactions(req *GetMessageAddedReactionsRequest) (*AddedReactions, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageAddedReactions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reaction_type": req.ReactionType,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAddedReactions(result.Data)
}
type SetDefaultReactionTypeRequest struct {
// New type of the default reaction
ReactionType ReactionType `json:"reaction_type"`
2022-09-18 01:34:29 +00:00
}
// Changes type of default reaction for the current user
func (client *Client) SetDefaultReactionType(req *SetDefaultReactionTypeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setDefaultReactionType",
},
Data: map[string]interface{}{
"reaction_type": req.ReactionType,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetTextEntitiesRequest struct {
2023-07-24 18:35:55 +00:00
// The text in which to look for entities
2023-03-26 09:37:06 +00:00
Text string `json:"text"`
2018-10-16 20:32:57 +00:00
}
2022-11-07 18:50:52 +00:00
// Returns all entities (mentions, hashtags, cashtags, bot commands, bank card numbers, URLs, and email addresses) found in the text. Can be called synchronously
func GetTextEntities(req *GetTextEntitiesRequest) (*TextEntities, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getTextEntities",
},
Data: map[string]interface{}{
"text": req.Text,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTextEntities(result.Data)
2018-08-30 14:55:42 +00:00
}
// deprecated
2022-11-07 18:50:52 +00:00
// Returns all entities (mentions, hashtags, cashtags, bot commands, bank card numbers, URLs, and email addresses) found in the text. Can be called synchronously
func (client *Client) GetTextEntities(req *GetTextEntitiesRequest) (*TextEntities, error) {
2023-03-26 09:37:06 +00:00
return GetTextEntities(req)}
2023-03-26 09:37:06 +00:00
type ParseTextEntitiesRequest struct {
// The text to parse
Text string `json:"text"`
// Text parse mode
ParseMode TextParseMode `json:"parse_mode"`
2018-10-16 20:32:57 +00:00
}
2022-11-07 18:50:52 +00:00
// Parses Bold, Italic, Underline, Strikethrough, Spoiler, CustomEmoji, Code, Pre, PreCode, TextUrl and MentionName entities from a marked-up text. Can be called synchronously
func ParseTextEntities(req *ParseTextEntitiesRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "parseTextEntities",
},
Data: map[string]interface{}{
"text": req.Text,
"parse_mode": req.ParseMode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFormattedText(result.Data)
2018-08-30 14:55:42 +00:00
}
// deprecated
2022-11-07 18:50:52 +00:00
// Parses Bold, Italic, Underline, Strikethrough, Spoiler, CustomEmoji, Code, Pre, PreCode, TextUrl and MentionName entities from a marked-up text. Can be called synchronously
func (client *Client) ParseTextEntities(req *ParseTextEntitiesRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
return ParseTextEntities(req)}
2023-03-26 09:37:06 +00:00
type ParseMarkdownRequest struct {
// The text to parse. For example, "__italic__ ~~strikethrough~~ ||spoiler|| **bold** `code` ```pre``` __[italic__ text_url](telegram.org) __italic**bold italic__bold**"
Text *FormattedText `json:"text"`
2020-11-30 09:33:47 +00:00
}
// Parses Markdown entities in a human-friendly format, ignoring markup errors. Can be called synchronously
func ParseMarkdown(req *ParseMarkdownRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "parseMarkdown",
},
Data: map[string]interface{}{
"text": req.Text,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFormattedText(result.Data)
2020-11-30 09:33:47 +00:00
}
// deprecated
// Parses Markdown entities in a human-friendly format, ignoring markup errors. Can be called synchronously
func (client *Client) ParseMarkdown(req *ParseMarkdownRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
return ParseMarkdown(req)}
2023-03-26 09:37:06 +00:00
type GetMarkdownTextRequest struct {
// The text
Text *FormattedText `json:"text"`
2020-11-30 09:33:47 +00:00
}
// Replaces text entities with Markdown formatting in a human-friendly format. Entities that can't be represented in Markdown unambiguously are kept as is. Can be called synchronously
func GetMarkdownText(req *GetMarkdownTextRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getMarkdownText",
},
Data: map[string]interface{}{
"text": req.Text,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFormattedText(result.Data)
2020-11-30 09:33:47 +00:00
}
// deprecated
// Replaces text entities with Markdown formatting in a human-friendly format. Entities that can't be represented in Markdown unambiguously are kept as is. Can be called synchronously
func (client *Client) GetMarkdownText(req *GetMarkdownTextRequest) (*FormattedText, error) {
2023-03-26 09:37:06 +00:00
return GetMarkdownText(req)}
2023-03-26 09:37:06 +00:00
type GetFileMimeTypeRequest struct {
// The name of the file or path to the file
FileName string `json:"file_name"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. Can be called synchronously
func GetFileMimeType(req *GetFileMimeTypeRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getFileMimeType",
},
Data: map[string]interface{}{
"file_name": req.FileName,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
// deprecated
// Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. Can be called synchronously
func (client *Client) GetFileMimeType(req *GetFileMimeTypeRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
return GetFileMimeType(req)}
2023-03-26 09:37:06 +00:00
type GetFileExtensionRequest struct {
// The MIME type of the file
MimeType string `json:"mime_type"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. Can be called synchronously
func GetFileExtension(req *GetFileExtensionRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getFileExtension",
},
Data: map[string]interface{}{
"mime_type": req.MimeType,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
// deprecated
// Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. Can be called synchronously
func (client *Client) GetFileExtension(req *GetFileExtensionRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
return GetFileExtension(req)}
2023-03-26 09:37:06 +00:00
type CleanFileNameRequest struct {
// File name or path to the file
FileName string `json:"file_name"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// 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. Can be called synchronously
func CleanFileName(req *CleanFileNameRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "cleanFileName",
},
Data: map[string]interface{}{
"file_name": req.FileName,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-10-23 12:38:10 +00:00
}
// deprecated
// 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. Can be called synchronously
func (client *Client) CleanFileName(req *CleanFileNameRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
return CleanFileName(req)}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// 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. Can be called synchronously
func GetLanguagePackString(req *GetLanguagePackStringRequest) (LanguagePackStringValue, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getLanguagePackString",
},
Data: map[string]interface{}{
"language_pack_database_path": req.LanguagePackDatabasePath,
"localization_target": req.LocalizationTarget,
"language_pack_id": req.LanguagePackId,
"key": req.Key,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeLanguagePackStringValueOrdinary:
return UnmarshalLanguagePackStringValueOrdinary(result.Data)
case TypeLanguagePackStringValuePluralized:
return UnmarshalLanguagePackStringValuePluralized(result.Data)
case TypeLanguagePackStringValueDeleted:
return UnmarshalLanguagePackStringValueDeleted(result.Data)
default:
return nil, errors.New("invalid type")
}
2018-10-23 12:38:10 +00:00
}
// deprecated
// 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. Can be called synchronously
func (client *Client) GetLanguagePackString(req *GetLanguagePackStringRequest) (LanguagePackStringValue, error) {
2023-03-26 09:37:06 +00:00
return GetLanguagePackString(req)}
2023-03-26 09:37:06 +00:00
type GetJsonValueRequest struct {
// The JSON-serialized string
Json string `json:"json"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Converts a JSON-serialized string to corresponding JsonValue object. Can be called synchronously
func GetJsonValue(req *GetJsonValueRequest) (JsonValue, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getJsonValue",
},
Data: map[string]interface{}{
"json": req.Json,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeJsonValueNull:
return UnmarshalJsonValueNull(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueBoolean:
return UnmarshalJsonValueBoolean(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueNumber:
return UnmarshalJsonValueNumber(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueString:
return UnmarshalJsonValueString(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueArray:
return UnmarshalJsonValueArray(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueObject:
return UnmarshalJsonValueObject(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-10-23 12:38:10 +00:00
}
// deprecated
// Converts a JSON-serialized string to corresponding JsonValue object. Can be called synchronously
func (client *Client) GetJsonValue(req *GetJsonValueRequest) (JsonValue, error) {
2023-03-26 09:37:06 +00:00
return GetJsonValue(req)}
2023-03-26 09:37:06 +00:00
type GetJsonStringRequest struct {
// The JsonValue object
JsonValue JsonValue `json:"json_value"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Converts a JsonValue object to corresponding JSON-serialized string. Can be called synchronously
func GetJsonString(req *GetJsonStringRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getJsonString",
},
Data: map[string]interface{}{
"json_value": req.JsonValue,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-10-23 12:38:10 +00:00
}
// deprecated
// Converts a JsonValue object to corresponding JSON-serialized string. Can be called synchronously
func (client *Client) GetJsonString(req *GetJsonStringRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
return GetJsonString(req)}
2023-03-26 09:37:06 +00:00
type GetThemeParametersJsonStringRequest struct {
// Theme parameters to convert to JSON
Theme *ThemeParameters `json:"theme"`
2022-04-24 20:33:39 +00:00
}
// Converts a themeParameters object to corresponding JSON-serialized string. Can be called synchronously
func GetThemeParametersJsonString(req *GetThemeParametersJsonStringRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getThemeParametersJsonString",
},
Data: map[string]interface{}{
"theme": req.Theme,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2022-04-24 20:33:39 +00:00
}
// deprecated
// Converts a themeParameters object to corresponding JSON-serialized string. Can be called synchronously
func (client *Client) GetThemeParametersJsonString(req *GetThemeParametersJsonStringRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
return GetThemeParametersJsonString(req)}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
type SetPollAnswerRequest struct {
// Identifier of the chat to which the poll belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message containing the poll
MessageId int64 `json:"message_id"`
// 0-based identifiers of answer options, chosen by the user. User can choose more than 1 answer option only is the poll allows multiple answers
OptionIds []int32 `json:"option_ids"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Changes the user answer to a poll. A poll in quiz mode can be answered only once
2019-06-07 10:56:06 +00:00
func (client *Client) SetPollAnswer(req *SetPollAnswerRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setPollAnswer",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"option_ids": req.OptionIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetPollVotersRequest struct {
// Identifier of the chat to which the poll belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message containing the poll
MessageId int64 `json:"message_id"`
// 0-based identifier of the answer option
OptionId int32 `json:"option_id"`
2023-07-24 18:35:55 +00:00
// Number of voters to skip in the result; must be non-negative
2023-03-26 09:37:06 +00:00
Offset int32 `json:"offset"`
2023-07-24 18:35:55 +00:00
// The maximum number of voters to be returned; must be positive and can't be greater than 50. For optimal performance, the number of returned voters is chosen by TDLib and can be smaller than the specified limit, even if the end of the voter list has not been reached
2023-03-26 09:37:06 +00:00
Limit int32 `json:"limit"`
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns message senders voted for the specified option in a non-anonymous polls. For optimal performance, the number of returned users is chosen by TDLib
func (client *Client) GetPollVoters(req *GetPollVotersRequest) (*MessageSenders, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPollVoters",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"option_id": req.OptionId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-07-24 18:35:55 +00:00
return UnmarshalMessageSenders(result.Data)
2023-03-26 09:37:06 +00:00
}
type StopPollRequest struct {
// Identifier of the chat to which the poll belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message containing the poll
MessageId int64 `json:"message_id"`
// The new message reply markup; pass null if none; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Stops a poll. A poll in a message can be stopped when the message has can_be_edited flag set
func (client *Client) StopPoll(req *StopPollRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "stopPoll",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"reply_markup": req.ReplyMarkup,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type HideSuggestedActionRequest struct {
// Suggested action to hide
Action SuggestedAction `json:"action"`
2020-11-30 09:33:47 +00:00
}
// Hides a suggested action
func (client *Client) HideSuggestedAction(req *HideSuggestedActionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "hideSuggestedAction",
},
Data: map[string]interface{}{
"action": req.Action,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetLoginUrlInfoRequest struct {
// Chat identifier of the message with the button
ChatId int64 `json:"chat_id"`
// Message identifier of the message with the button
MessageId int64 `json:"message_id"`
// Button identifier
ButtonId int64 `json:"button_id"`
2020-02-03 12:56:20 +00:00
}
// Returns information about a button of type inlineKeyboardButtonTypeLoginUrl. The method needs to be called when the user presses the button
func (client *Client) GetLoginUrlInfo(req *GetLoginUrlInfoRequest) (LoginUrlInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getLoginUrlInfo",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"button_id": req.ButtonId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeLoginUrlInfoOpen:
return UnmarshalLoginUrlInfoOpen(result.Data)
case TypeLoginUrlInfoRequestConfirmation:
return UnmarshalLoginUrlInfoRequestConfirmation(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type GetLoginUrlRequest struct {
// Chat identifier of the message with the button
ChatId int64 `json:"chat_id"`
// Message identifier of the message with the button
MessageId int64 `json:"message_id"`
// Button identifier
ButtonId int64 `json:"button_id"`
// Pass true to allow the bot to send messages to the current user
AllowWriteAccess bool `json:"allow_write_access"`
2020-02-03 12:56:20 +00:00
}
// Returns an HTTP URL which can be used to automatically authorize the user on a website after clicking an inline button of type inlineKeyboardButtonTypeLoginUrl. Use the method getLoginUrlInfo to find whether a prior user confirmation is needed. If an error is returned, then the button must be handled as an ordinary URL button
func (client *Client) GetLoginUrl(req *GetLoginUrlRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getLoginUrl",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"button_id": req.ButtonId,
"allow_write_access": req.AllowWriteAccess,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
}
type ShareUserWithBotRequest struct {
// Identifier of the chat with the bot
ChatId int64 `json:"chat_id"`
// Identifier of the message with the button
MessageId int64 `json:"message_id"`
// Identifier of the button
ButtonId int32 `json:"button_id"`
// Identifier of the shared user
SharedUserId int64 `json:"shared_user_id"`
// Pass true to check that the user can be shared by the button instead of actually sharing them
OnlyCheck bool `json:"only_check"`
2023-02-04 22:54:46 +00:00
}
// Shares a user after pressing a keyboardButtonTypeRequestUser button with the bot
func (client *Client) ShareUserWithBot(req *ShareUserWithBotRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "shareUserWithBot",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"button_id": req.ButtonId,
"shared_user_id": req.SharedUserId,
"only_check": req.OnlyCheck,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ShareChatWithBotRequest struct {
// Identifier of the chat with the bot
ChatId int64 `json:"chat_id"`
// Identifier of the message with the button
MessageId int64 `json:"message_id"`
// Identifier of the button
ButtonId int32 `json:"button_id"`
// Identifier of the shared chat
SharedChatId int64 `json:"shared_chat_id"`
// Pass true to check that the chat can be shared by the button instead of actually sharing it. Doesn't check bot_is_member and bot_administrator_rights restrictions. If the bot must be a member, then all chats from getGroupsInCommon and all chats, where the user can add the bot, are suitable. In the latter case the bot will be automatically added to the chat. If the bot must be an administrator, then all chats, where the bot already has requested rights or can be added to administrators by the user, are suitable. In the latter case the bot will be automatically granted requested rights
OnlyCheck bool `json:"only_check"`
2023-02-04 22:54:46 +00:00
}
// Shares a chat after pressing a keyboardButtonTypeRequestChat button with the bot
func (client *Client) ShareChatWithBot(req *ShareChatWithBotRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "shareChatWithBot",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"button_id": req.ButtonId,
"shared_chat_id": req.SharedChatId,
"only_check": req.OnlyCheck,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetInlineQueryResultsRequest struct {
2023-07-24 18:35:55 +00:00
// Identifier of the target bot
2023-03-26 09:37:06 +00:00
BotUserId int64 `json:"bot_user_id"`
// Identifier of the chat where the query was sent
ChatId int64 `json:"chat_id"`
// Location of the user; pass null if unknown or the bot doesn't need user's location
UserLocation *Location `json:"user_location"`
// Text of the query
Query string `json:"query"`
2023-08-15 18:28:13 +00:00
// Offset of the first entry to return; use empty string to get the first chunk of results
2023-03-26 09:37:06 +00:00
Offset string `json:"offset"`
2019-06-07 10:56:06 +00:00
}
// 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
func (client *Client) GetInlineQueryResults(req *GetInlineQueryResultsRequest) (*InlineQueryResults, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInlineQueryResults",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"chat_id": req.ChatId,
"user_location": req.UserLocation,
"query": req.Query,
"offset": req.Offset,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalInlineQueryResults(result.Data)
}
type AnswerInlineQueryRequest struct {
// Identifier of the inline query
InlineQueryId JsonInt64 `json:"inline_query_id"`
// Pass true if results may be cached and returned only for the user that sent the query. By default, results may be returned to any user who sends the same query
IsPersonal bool `json:"is_personal"`
// Button to be shown above inline query results; pass null if none
Button *InlineQueryResultsButton `json:"button"`
// 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"`
2019-06-07 10:56:06 +00:00
}
// Sets the result of an inline query; for bots only
func (client *Client) AnswerInlineQuery(req *AnswerInlineQueryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerInlineQuery",
},
Data: map[string]interface{}{
"inline_query_id": req.InlineQueryId,
"is_personal": req.IsPersonal,
"button": req.Button,
"results": req.Results,
"cache_time": req.CacheTime,
"next_offset": req.NextOffset,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SearchWebAppRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// Short name of the Web App
WebAppShortName string `json:"web_app_short_name"`
2023-03-11 11:13:56 +00:00
}
// Returns information about a Web App by its short name. Returns a 404 error if the Web App is not found
func (client *Client) SearchWebApp(req *SearchWebAppRequest) (*FoundWebApp, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchWebApp",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"web_app_short_name": req.WebAppShortName,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundWebApp(result.Data)
}
type GetWebAppLinkUrlRequest struct {
// Identifier of the chat in which the link was clicked; pass 0 if none
ChatId int64 `json:"chat_id"`
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// Short name of the Web App
WebAppShortName string `json:"web_app_short_name"`
// Start parameter from internalLinkTypeWebApp
StartParameter string `json:"start_parameter"`
// Preferred Web App theme; pass null to use the default theme
Theme *ThemeParameters `json:"theme"`
// Short name of the application; 0-64 English letters, digits, and underscores
ApplicationName string `json:"application_name"`
// Pass true if the current user allowed the bot to send them messages
AllowWriteAccess bool `json:"allow_write_access"`
2023-03-11 11:13:56 +00:00
}
// Returns an HTTPS URL of a Web App to open after a link of the type internalLinkTypeWebApp is clicked
func (client *Client) GetWebAppLinkUrl(req *GetWebAppLinkUrlRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getWebAppLinkUrl",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"bot_user_id": req.BotUserId,
"web_app_short_name": req.WebAppShortName,
"start_parameter": req.StartParameter,
"theme": req.Theme,
"application_name": req.ApplicationName,
"allow_write_access": req.AllowWriteAccess,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
}
type GetWebAppUrlRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
2023-09-16 07:09:40 +00:00
// The URL from a keyboardButtonTypeWebApp button, inlineQueryResultsButtonTypeWebApp button, an internalLinkTypeSideMenuBot link, or an empty when the bot is opened from the side menu
2023-03-26 09:37:06 +00:00
Url string `json:"url"`
// Preferred Web App theme; pass null to use the default theme
Theme *ThemeParameters `json:"theme"`
// Short name of the application; 0-64 English letters, digits, and underscores
ApplicationName string `json:"application_name"`
2022-04-24 20:33:39 +00:00
}
2023-09-16 07:09:40 +00:00
// Returns an HTTPS URL of a Web App to open from the side menu, a keyboardButtonTypeWebApp button, an inlineQueryResultsButtonTypeWebApp button, or an internalLinkTypeSideMenuBot link
2022-04-24 20:33:39 +00:00
func (client *Client) GetWebAppUrl(req *GetWebAppUrlRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getWebAppUrl",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"url": req.Url,
"theme": req.Theme,
"application_name": req.ApplicationName,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
}
type SendWebAppDataRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// Text of the keyboardButtonTypeWebApp button, which opened the Web App
ButtonText string `json:"button_text"`
2023-07-24 18:35:55 +00:00
// The data
2023-03-26 09:37:06 +00:00
Data string `json:"data"`
2022-04-24 20:33:39 +00:00
}
2022-06-21 18:10:07 +00:00
// Sends data received from a keyboardButtonTypeWebApp Web App to a bot
2022-04-24 20:33:39 +00:00
func (client *Client) SendWebAppData(req *SendWebAppDataRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendWebAppData",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"button_text": req.ButtonText,
"data": req.Data,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type OpenWebAppRequest struct {
// Identifier of the chat in which the Web App is opened. The Web App can't be opened in secret chats
ChatId int64 `json:"chat_id"`
// Identifier of the bot, providing the Web App
BotUserId int64 `json:"bot_user_id"`
2023-09-16 07:09:40 +00:00
// The URL from an inlineKeyboardButtonTypeWebApp button, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an empty string otherwise
2023-03-26 09:37:06 +00:00
Url string `json:"url"`
// Preferred Web App theme; pass null to use the default theme
Theme *ThemeParameters `json:"theme"`
// Short name of the application; 0-64 English letters, digits, and underscores
ApplicationName string `json:"application_name"`
// If not 0, a message thread identifier in which the message will be sent
MessageThreadId int64 `json:"message_thread_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the replied message or story for the message sent by the Web App; pass null if none
ReplyTo MessageReplyTo `json:"reply_to"`
2022-04-24 20:33:39 +00:00
}
2023-09-16 07:09:40 +00:00
// Informs TDLib that a Web App is being opened from the attachment menu, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an inlineKeyboardButtonTypeWebApp button. For each bot, a confirmation alert about data sent to the bot must be shown once
2022-04-24 20:33:39 +00:00
func (client *Client) OpenWebApp(req *OpenWebAppRequest) (*WebAppInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "openWebApp",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"bot_user_id": req.BotUserId,
"url": req.Url,
"theme": req.Theme,
"application_name": req.ApplicationName,
"message_thread_id": req.MessageThreadId,
2023-07-24 18:35:55 +00:00
"reply_to": req.ReplyTo,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalWebAppInfo(result.Data)
}
type CloseWebAppRequest struct {
// Identifier of Web App launch, received from openWebApp
WebAppLaunchId JsonInt64 `json:"web_app_launch_id"`
2022-04-24 20:33:39 +00:00
}
2022-06-21 18:10:07 +00:00
// Informs TDLib that a previously opened Web App was closed
2022-04-24 20:33:39 +00:00
func (client *Client) CloseWebApp(req *CloseWebAppRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "closeWebApp",
},
Data: map[string]interface{}{
"web_app_launch_id": req.WebAppLaunchId,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-03-26 09:37:06 +00:00
type AnswerWebAppQueryRequest struct {
// Identifier of the Web App query
WebAppQueryId string `json:"web_app_query_id"`
// The result of the query
Result InputInlineQueryResult `json:"result"`
2022-04-24 20:33:39 +00:00
}
2022-06-21 18:10:07 +00:00
// Sets the result of interaction with a Web App and sends corresponding message on behalf of the user to the chat from which the query originated; for bots only
2022-04-24 20:33:39 +00:00
func (client *Client) AnswerWebAppQuery(req *AnswerWebAppQueryRequest) (*SentWebAppMessage, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerWebAppQuery",
},
Data: map[string]interface{}{
"web_app_query_id": req.WebAppQueryId,
"result": req.Result,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalSentWebAppMessage(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"`
2019-06-07 10:56:06 +00:00
}
// 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
func (client *Client) GetCallbackQueryAnswer(req *GetCallbackQueryAnswerRequest) (*CallbackQueryAnswer, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCallbackQueryAnswer",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
// Pass true to show an alert 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"`
2019-06-07 10:56:06 +00:00
}
// Sets the result of a callback query; for bots only
func (client *Client) AnswerCallbackQuery(req *AnswerCallbackQueryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerCallbackQuery",
},
Data: map[string]interface{}{
"callback_query_id": req.CallbackQueryId,
"text": req.Text,
"show_alert": req.ShowAlert,
"url": req.Url,
"cache_time": req.CacheTime,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sets the result of a shipping query; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) AnswerShippingQuery(req *AnswerShippingQueryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerShippingQuery",
},
Data: map[string]interface{}{
"shipping_query_id": req.ShippingQueryId,
"shipping_options": req.ShippingOptions,
"error_message": req.ErrorMessage,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sets the result of a pre-checkout query; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) AnswerPreCheckoutQuery(req *AnswerPreCheckoutQueryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerPreCheckoutQuery",
},
Data: map[string]interface{}{
"pre_checkout_query_id": req.PreCheckoutQueryId,
"error_message": req.ErrorMessage,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetGameScoreRequest struct {
// The chat to which the message with the game belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Pass true to edit the game message to include the current scoreboard
EditMessage bool `json:"edit_message"`
// User identifier
UserId int64 `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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Updates the game score of the specified user in the game; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) SetGameScore(req *SetGameScoreRequest) (*Message, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setGameScore",
},
Data: map[string]interface{}{
"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 {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
type SetInlineGameScoreRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// Pass true to edit the game message to include the current scoreboard
EditMessage bool `json:"edit_message"`
// User identifier
UserId int64 `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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Updates the game score of the specified user in a game; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) SetInlineGameScore(req *SetInlineGameScoreRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setInlineGameScore",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"edit_message": req.EditMessage,
"user_id": req.UserId,
"score": req.Score,
"force": req.Force,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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 int64 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetGameHighScores(req *GetGameHighScoresRequest) (*GameHighScores, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getGameHighScores",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalGameHighScores(result.Data)
}
type GetInlineGameHighScoresRequest struct {
// Inline message identifier
InlineMessageId string `json:"inline_message_id"`
// User identifier
UserId int64 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns game high scores and some part of the high score table in the range of the specified user; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) GetInlineGameHighScores(req *GetInlineGameHighScoresRequest) (*GameHighScores, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInlineGameHighScores",
},
Data: map[string]interface{}{
"inline_message_id": req.InlineMessageId,
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalGameHighScores(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteChatReplyMarkupRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The message identifier of the used keyboard
MessageId int64 `json:"message_id"`
2018-10-16 20:32:57 +00:00
}
2022-12-07 20:04:16 +00:00
// Deletes the default reply markup from a chat. Must be called after a one-time keyboard or a replyMarkupForceReply reply markup has been used. An updateChatReplyMarkup update will be sent if the reply markup is changed
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteChatReplyMarkup(req *DeleteChatReplyMarkupRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteChatReplyMarkup",
},
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 UnmarshalOk(result.Data)
}
type SendChatActionRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// If not 0, a message thread identifier in which the action was performed
MessageThreadId int64 `json:"message_thread_id"`
// The action description; pass null to cancel the currently active action
Action ChatAction `json:"action"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a notification about user activity in a chat
2018-10-16 20:32:57 +00:00
func (client *Client) SendChatAction(req *SendChatActionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendChatAction",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
"action": req.Action,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type OpenChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Informs TDLib that 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)
2018-10-16 20:32:57 +00:00
func (client *Client) OpenChat(req *OpenChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "openChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CloseChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Informs TDLib that the chat is closed by the user. Many useful activities depend on the chat being opened or closed
2018-10-16 20:32:57 +00:00
func (client *Client) CloseChat(req *CloseChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "closeChat",
},
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 ViewMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The identifiers of the messages being viewed
MessageIds []int64 `json:"message_ids"`
// Source of the message view; pass null to guess the source based on chat open state
Source MessageSource `json:"source"`
// Pass true to mark as read the specified messages even the chat is closed
ForceRead bool `json:"force_read"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Informs TDLib that messages are being viewed by the user. Sponsored messages must be marked as viewed only when the entire text of the message is shown on the screen (excluding the button). 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)
2018-10-16 20:32:57 +00:00
func (client *Client) ViewMessages(req *ViewMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "viewMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
"source": req.Source,
"force_read": req.ForceRead,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Informs TDLib that 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
2018-10-16 20:32:57 +00:00
func (client *Client) OpenMessageContent(req *OpenMessageContentRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "openMessageContent",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ClickAnimatedEmojiMessageRequest struct {
// Chat identifier of the message
ChatId int64 `json:"chat_id"`
// Identifier of the clicked message
MessageId int64 `json:"message_id"`
2021-12-30 05:55:02 +00:00
}
// Informs TDLib that a message with an animated emoji was clicked by the user. Returns a big animated sticker to be played or a 404 error if usual animation needs to be played
func (client *Client) ClickAnimatedEmojiMessage(req *ClickAnimatedEmojiMessageRequest) (*Sticker, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clickAnimatedEmojiMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSticker(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetInternalLinkRequest struct {
// Expected type of the link
Type InternalLinkType `json:"type"`
// Pass true to create an HTTPS link (only available for some link types); pass false to create a tg: link
IsHttp bool `json:"is_http"`
2023-03-11 11:13:56 +00:00
}
// Returns an HTTPS or a tg: link with the given type. Can be called before authorization
func (client *Client) GetInternalLink(req *GetInternalLinkRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInternalLink",
},
Data: map[string]interface{}{
"type": req.Type,
"is_http": req.IsHttp,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type GetInternalLinkTypeRequest struct {
// The link
Link string `json:"link"`
2021-12-30 05:55:02 +00:00
}
// Returns information about the type of an internal link. Returns a 404 error if the link is not internal. Can be called before authorization
func (client *Client) GetInternalLinkType(req *GetInternalLinkTypeRequest) (InternalLinkType, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInternalLinkType",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeInternalLinkTypeActiveSessions:
return UnmarshalInternalLinkTypeActiveSessions(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeAttachmentMenuBot:
return UnmarshalInternalLinkTypeAttachmentMenuBot(result.Data)
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeAuthenticationCode:
return UnmarshalInternalLinkTypeAuthenticationCode(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeBackground:
return UnmarshalInternalLinkTypeBackground(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeBotAddToChannel:
return UnmarshalInternalLinkTypeBotAddToChannel(result.Data)
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeBotStart:
return UnmarshalInternalLinkTypeBotStart(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeBotStartInGroup:
return UnmarshalInternalLinkTypeBotStartInGroup(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeChangePhoneNumber:
return UnmarshalInternalLinkTypeChangePhoneNumber(result.Data)
2021-12-30 05:55:02 +00:00
2023-07-24 18:35:55 +00:00
case TypeInternalLinkTypeChatFolderInvite:
return UnmarshalInternalLinkTypeChatFolderInvite(result.Data)
case TypeInternalLinkTypeChatFolderSettings:
return UnmarshalInternalLinkTypeChatFolderSettings(result.Data)
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeChatInvite:
return UnmarshalInternalLinkTypeChatInvite(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeDefaultMessageAutoDeleteTimerSettings:
return UnmarshalInternalLinkTypeDefaultMessageAutoDeleteTimerSettings(result.Data)
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeEditProfileSettings:
return UnmarshalInternalLinkTypeEditProfileSettings(result.Data)
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeGame:
return UnmarshalInternalLinkTypeGame(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeInstantView:
return UnmarshalInternalLinkTypeInstantView(result.Data)
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeInvoice:
return UnmarshalInternalLinkTypeInvoice(result.Data)
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeLanguagePack:
return UnmarshalInternalLinkTypeLanguagePack(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeLanguageSettings:
return UnmarshalInternalLinkTypeLanguageSettings(result.Data)
2022-03-31 08:54:35 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeMessage:
return UnmarshalInternalLinkTypeMessage(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeMessageDraft:
return UnmarshalInternalLinkTypeMessageDraft(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypePassportDataRequest:
return UnmarshalInternalLinkTypePassportDataRequest(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypePhoneNumberConfirmation:
return UnmarshalInternalLinkTypePhoneNumberConfirmation(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypePremiumFeatures:
return UnmarshalInternalLinkTypePremiumFeatures(result.Data)
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypePrivacyAndSecuritySettings:
return UnmarshalInternalLinkTypePrivacyAndSecuritySettings(result.Data)
2022-03-31 08:54:35 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeProxy:
return UnmarshalInternalLinkTypeProxy(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypePublicChat:
return UnmarshalInternalLinkTypePublicChat(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeQrCodeAuthentication:
return UnmarshalInternalLinkTypeQrCodeAuthentication(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeRestorePurchases:
return UnmarshalInternalLinkTypeRestorePurchases(result.Data)
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeSettings:
return UnmarshalInternalLinkTypeSettings(result.Data)
2021-12-30 05:55:02 +00:00
2023-09-16 07:09:40 +00:00
case TypeInternalLinkTypeSideMenuBot:
return UnmarshalInternalLinkTypeSideMenuBot(result.Data)
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeStickerSet:
return UnmarshalInternalLinkTypeStickerSet(result.Data)
2021-12-30 05:55:02 +00:00
2023-07-24 18:35:55 +00:00
case TypeInternalLinkTypeStory:
return UnmarshalInternalLinkTypeStory(result.Data)
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeTheme:
return UnmarshalInternalLinkTypeTheme(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeThemeSettings:
return UnmarshalInternalLinkTypeThemeSettings(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeUnknownDeepLink:
return UnmarshalInternalLinkTypeUnknownDeepLink(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeUnsupportedProxy:
return UnmarshalInternalLinkTypeUnsupportedProxy(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeUserPhoneNumber:
return UnmarshalInternalLinkTypeUserPhoneNumber(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeUserToken:
return UnmarshalInternalLinkTypeUserToken(result.Data)
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeVideoChat:
return UnmarshalInternalLinkTypeVideoChat(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeInternalLinkTypeWebApp:
return UnmarshalInternalLinkTypeWebApp(result.Data)
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetExternalLinkInfoRequest struct {
// The link
Link string `json:"link"`
2021-12-30 05:55:02 +00:00
}
// Returns information about an action to be done when the current user clicks an external link. Don't use this method for links from secret chats if web page preview is disabled in secret chats
func (client *Client) GetExternalLinkInfo(req *GetExternalLinkInfoRequest) (LoginUrlInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getExternalLinkInfo",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeLoginUrlInfoOpen:
return UnmarshalLoginUrlInfoOpen(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeLoginUrlInfoRequestConfirmation:
return UnmarshalLoginUrlInfoRequestConfirmation(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetExternalLinkRequest struct {
// The HTTP link
Link string `json:"link"`
// Pass true if the current user allowed the bot, returned in getExternalLinkInfo, to send them messages
AllowWriteAccess bool `json:"allow_write_access"`
2021-12-30 05:55:02 +00:00
}
// Returns an HTTP URL which can be used to automatically authorize the current user on a website after clicking an HTTP link. Use the method getExternalLinkInfo to find whether a prior user confirmation is needed
func (client *Client) GetExternalLink(req *GetExternalLinkRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getExternalLink",
},
Data: map[string]interface{}{
"link": req.Link,
"allow_write_access": req.AllowWriteAccess,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type ReadAllChatMentionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Marks all mentions in a chat as read
2018-10-16 20:32:57 +00:00
func (client *Client) ReadAllChatMentions(req *ReadAllChatMentionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "readAllChatMentions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ReadAllMessageThreadMentionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message thread identifier in which mentions are marked as read
MessageThreadId int64 `json:"message_thread_id"`
2022-11-07 18:50:52 +00:00
}
// Marks all mentions in a forum topic as read
func (client *Client) ReadAllMessageThreadMentions(req *ReadAllMessageThreadMentionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "readAllMessageThreadMentions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type ReadAllChatReactionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2022-02-06 18:36:17 +00:00
}
2022-11-07 18:50:52 +00:00
// Marks all reactions in a chat or a forum topic as read
2022-02-06 18:36:17 +00:00
func (client *Client) ReadAllChatReactions(req *ReadAllChatReactionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "readAllChatReactions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-02-06 18:36:17 +00:00
}
2023-03-26 09:37:06 +00:00
type ReadAllMessageThreadReactionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message thread identifier in which reactions are marked as read
MessageThreadId int64 `json:"message_thread_id"`
2022-11-07 18:50:52 +00:00
}
// Marks all reactions in a forum topic as read
func (client *Client) ReadAllMessageThreadReactions(req *ReadAllMessageThreadReactionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "readAllMessageThreadReactions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type CreatePrivateChatRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// Pass true to create the chat without a network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns an existing chat corresponding to a given user
2018-10-16 20:32:57 +00:00
func (client *Client) CreatePrivateChat(req *CreatePrivateChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createPrivateChat",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"force": req.Force,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CreateBasicGroupChatRequest struct {
// Basic group identifier
BasicGroupId int64 `json:"basic_group_id"`
// Pass true to create the chat without a network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns an existing chat corresponding to a known basic group
2018-10-16 20:32:57 +00:00
func (client *Client) CreateBasicGroupChat(req *CreateBasicGroupChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createBasicGroupChat",
},
Data: map[string]interface{}{
"basic_group_id": req.BasicGroupId,
"force": req.Force,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CreateSupergroupChatRequest struct {
// Supergroup or channel identifier
SupergroupId int64 `json:"supergroup_id"`
// Pass true to create the chat without a network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns an existing chat corresponding to a known supergroup or channel
2018-10-16 20:32:57 +00:00
func (client *Client) CreateSupergroupChat(req *CreateSupergroupChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createSupergroupChat",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"force": req.Force,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CreateSecretChatRequest struct {
// Secret chat identifier
SecretChatId int32 `json:"secret_chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns an existing chat corresponding to a known secret chat
2018-10-16 20:32:57 +00:00
func (client *Client) CreateSecretChat(req *CreateSecretChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createSecretChat",
},
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 UnmarshalChat(result.Data)
}
type CreateNewBasicGroupChatRequest struct {
// Identifiers of users to be added to the basic group; may be empty to create a basic group without other members
UserIds []int64 `json:"user_ids"`
// Title of the new basic group; 1-128 characters
Title string `json:"title"`
// Message auto-delete time value, in seconds; must be from 0 up to 365 * 86400 and be divisible by 86400. If 0, then messages aren't deleted automatically
MessageAutoDeleteTime int32 `json:"message_auto_delete_time"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new basic group and sends a corresponding messageBasicGroupChatCreate. Returns the newly created chat
2018-10-16 20:32:57 +00:00
func (client *Client) CreateNewBasicGroupChat(req *CreateNewBasicGroupChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewBasicGroupChat",
},
Data: map[string]interface{}{
"user_ids": req.UserIds,
"title": req.Title,
"message_auto_delete_time": req.MessageAutoDeleteTime,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChat(result.Data)
}
type CreateNewSupergroupChatRequest struct {
// Title of the new chat; 1-128 characters
Title string `json:"title"`
// Pass true to create a forum supergroup chat
IsForum bool `json:"is_forum"`
// Pass true to create a channel chat; ignored if a forum is created
IsChannel bool `json:"is_channel"`
// Chat description; 0-255 characters
Description string `json:"description"`
// Chat location if a location-based supergroup is being created; pass null to create an ordinary supergroup chat
Location *ChatLocation `json:"location"`
// Message auto-delete time value, in seconds; must be from 0 up to 365 * 86400 and be divisible by 86400. If 0, then messages aren't deleted automatically
MessageAutoDeleteTime int32 `json:"message_auto_delete_time"`
// Pass true to create a supergroup for importing messages using importMessage
ForImport bool `json:"for_import"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new supergroup or channel and sends a corresponding messageSupergroupChatCreate. Returns the newly created chat
2018-10-16 20:32:57 +00:00
func (client *Client) CreateNewSupergroupChat(req *CreateNewSupergroupChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewSupergroupChat",
},
Data: map[string]interface{}{
"title": req.Title,
"is_forum": req.IsForum,
"is_channel": req.IsChannel,
"description": req.Description,
"location": req.Location,
"message_auto_delete_time": req.MessageAutoDeleteTime,
"for_import": req.ForImport,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChat(result.Data)
}
type CreateNewSecretChatRequest struct {
// Identifier of the target user
UserId int64 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new secret chat. Returns the newly created chat
2018-10-16 20:32:57 +00:00
func (client *Client) CreateNewSecretChat(req *CreateNewSecretChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewSecretChat",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type UpgradeBasicGroupChatToSupergroupChatRequest struct {
// Identifier of the chat to upgrade
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Creates a new supergroup from an existing basic group and sends a corresponding messageChatUpgradeTo and messageChatUpgradeFrom; requires creator privileges. Deactivates the original basic group
2018-10-16 20:32:57 +00:00
func (client *Client) UpgradeBasicGroupChatToSupergroupChat(req *UpgradeBasicGroupChatToSupergroupChatRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "upgradeBasicGroupChatToSupergroupChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatListsToAddChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2020-11-30 09:33:47 +00:00
}
// Returns chat lists to which the chat can be added. This is an offline request
func (client *Client) GetChatListsToAddChat(req *GetChatListsToAddChatRequest) (*ChatLists, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatListsToAddChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatLists(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type AddChatToListRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The chat list. Use getChatListsToAddChat to get suitable chat lists
ChatList ChatList `json:"chat_list"`
2020-02-03 12:56:20 +00:00
}
2020-11-30 09:33:47 +00:00
// Adds a chat to a chat list. A chat can't be simultaneously in Main and Archive chat lists, so it is automatically removed from another one if needed
func (client *Client) AddChatToList(req *AddChatToListRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addChatToList",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"chat_list": req.ChatList,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns information about a chat folder by its identifier
func (client *Client) GetChatFolder(req *GetChatFolderRequest) (*ChatFolder, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolder",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolder(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type CreateChatFolderRequest struct {
// The new chat folder
Folder *ChatFolder `json:"folder"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Creates new chat folder. Returns information about the created chat folder. There can be up to getOption("chat_folder_count_max") chat folders, but the limit can be increased with Telegram Premium
func (client *Client) CreateChatFolder(req *CreateChatFolderRequest) (*ChatFolderInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "createChatFolder",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"folder": req.Folder,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInfo(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type EditChatFolderRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// The edited chat folder
Folder *ChatFolder `json:"folder"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Edits existing chat folder. Returns information about the edited chat folder
func (client *Client) EditChatFolder(req *EditChatFolderRequest) (*ChatFolderInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "editChatFolder",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"folder": req.Folder,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInfo(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type DeleteChatFolderRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// Identifiers of the chats to leave. The chats must be pinned or always included in the folder
LeaveChatIds []int64 `json:"leave_chat_ids"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Deletes existing chat folder
func (client *Client) DeleteChatFolder(req *DeleteChatFolderRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "deleteChatFolder",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"leave_chat_ids": req.LeaveChatIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderChatsToLeaveRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns identifiers of pinned or always included chats from a chat folder, which are suggested to be left when the chat folder is deleted
func (client *Client) GetChatFolderChatsToLeave(req *GetChatFolderChatsToLeaveRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolderChatsToLeave",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-07-24 18:35:55 +00:00
return UnmarshalChats(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderChatCountRequest struct {
// The new chat folder
Folder *ChatFolder `json:"folder"`
}
// Returns approximate number of chats in a being created chat folder. Main and archive chat lists must be fully preloaded for this function to work correctly
func (client *Client) GetChatFolderChatCount(req *GetChatFolderChatCountRequest) (*Count, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolderChatCount",
},
Data: map[string]interface{}{
"folder": req.Folder,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalCount(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type ReorderChatFoldersRequest struct {
// Identifiers of chat folders in the new correct order
ChatFolderIds []int32 `json:"chat_folder_ids"`
// Position of the main chat list among chat folders, 0-based. Can be non-zero only for Premium users
MainChatListPosition int32 `json:"main_chat_list_position"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the order of chat folders
func (client *Client) ReorderChatFolders(req *ReorderChatFoldersRequest) (*Ok, error) {
result, err := client.Send(Request{
2023-03-26 09:37:06 +00:00
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "reorderChatFolders",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_ids": req.ChatFolderIds,
"main_chat_list_position": req.MainChatListPosition,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns recommended chat folders for the current user
func (client *Client) GetRecommendedChatFolders() (*RecommendedChatFolders, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getRecommendedChatFolders",
2023-03-26 09:37:06 +00:00
},
2023-07-24 18:35:55 +00:00
Data: map[string]interface{}{},
2023-03-26 09:37:06 +00:00
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalRecommendedChatFolders(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderDefaultIconNameRequest struct {
// Chat folder
Folder *ChatFolder `json:"folder"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns default icon name for a folder. Can be called synchronously
func GetChatFolderDefaultIconName(req *GetChatFolderDefaultIconNameRequest) (*ChatFolderIcon, error) {
result, err := Execute(Request{
2023-03-26 09:37:06 +00:00
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolderDefaultIconName",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"folder": req.Folder,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderIcon(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
// deprecated
// Returns default icon name for a folder. Can be called synchronously
func (client *Client) GetChatFolderDefaultIconName(req *GetChatFolderDefaultIconNameRequest) (*ChatFolderIcon, error) {
return GetChatFolderDefaultIconName(req)}
type GetChatsForChatFolderInviteLinkRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
2019-09-10 12:36:54 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns identifiers of chats from a chat folder, suitable for adding to a chat folder invite link
func (client *Client) GetChatsForChatFolderInviteLink(req *GetChatsForChatFolderInviteLinkRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatsForChatFolderInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChats(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
type CreateChatFolderInviteLinkRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// Name of the link; 0-32 characters
Name string `json:"name"`
// Identifiers of chats to be accessible by the invite link. Use getChatsForChatFolderInviteLink to get suitable chats. Basic groups will be automatically converted to supergroups before link creation
ChatIds []int64 `json:"chat_ids"`
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
// Creates a new invite link for a chat folder. A link can be created for a chat folder if it has only pinned and included chats
func (client *Client) CreateChatFolderInviteLink(req *CreateChatFolderInviteLinkRequest) (*ChatFolderInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "createChatFolderInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"name": req.Name,
"chat_ids": req.ChatIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInviteLink(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderInviteLinksRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns invite links created by the current user for a shareable chat folder
func (client *Client) GetChatFolderInviteLinks(req *GetChatFolderInviteLinksRequest) (*ChatFolderInviteLinks, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolderInviteLinks",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInviteLinks(result.Data)
2023-03-26 09:37:06 +00:00
}
2023-07-24 18:35:55 +00:00
type EditChatFolderInviteLinkRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// Invite link to be edited
InviteLink string `json:"invite_link"`
// New name of the link; 0-32 characters
Name string `json:"name"`
// New identifiers of chats to be accessible by the invite link. Use getChatsForChatFolderInviteLink to get suitable chats. Basic groups will be automatically converted to supergroups before link editing
ChatIds []int64 `json:"chat_ids"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Edits an invite link for a chat folder
func (client *Client) EditChatFolderInviteLink(req *EditChatFolderInviteLinkRequest) (*ChatFolderInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "editChatFolderInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"invite_link": req.InviteLink,
"name": req.Name,
"chat_ids": req.ChatIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInviteLink(result.Data)
2023-03-26 09:37:06 +00:00
}
2023-07-24 18:35:55 +00:00
type DeleteChatFolderInviteLinkRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// Invite link to be deleted
InviteLink string `json:"invite_link"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Deletes an invite link for a chat folder
func (client *Client) DeleteChatFolderInviteLink(req *DeleteChatFolderInviteLinkRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "deleteChatFolderInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"invite_link": req.InviteLink,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-07-24 18:35:55 +00:00
type CheckChatFolderInviteLinkRequest struct {
// Invite link to be checked
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
// Checks the validity of an invite link for a chat folder and returns information about the corresponding chat folder
func (client *Client) CheckChatFolderInviteLink(req *CheckChatFolderInviteLinkRequest) (*ChatFolderInviteLinkInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "checkChatFolderInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"invite_link": req.InviteLink,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChatFolderInviteLinkInfo(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
type AddChatFolderByInviteLinkRequest struct {
// Invite link for the chat folder
InviteLink string `json:"invite_link"`
// Identifiers of the chats added to the chat folder. The chats are automatically joined if they aren't joined yet
ChatIds []int64 `json:"chat_ids"`
2023-02-04 22:54:46 +00:00
}
2023-07-24 18:35:55 +00:00
// Adds a chat folder by an invite link
func (client *Client) AddChatFolderByInviteLink(req *AddChatFolderByInviteLinkRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "addChatFolderByInviteLink",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"invite_link": req.InviteLink,
"chat_ids": req.ChatIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatFolderNewChatsRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns new chats added to a shareable chat folder by its owner. The method must be called at most once in getOption("chat_folder_new_chats_update_period") for the given chat folder
func (client *Client) GetChatFolderNewChats(req *GetChatFolderNewChatsRequest) (*Chats, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatFolderNewChats",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalChats(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-07-24 18:35:55 +00:00
type ProcessChatFolderNewChatsRequest struct {
// Chat folder identifier
ChatFolderId int32 `json:"chat_folder_id"`
// Identifiers of the new chats, which are added to the chat folder. The chats are automatically joined if they aren't joined yet
AddedChatIds []int64 `json:"added_chat_ids"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Process new chats added to a shareable chat folder by its owner
func (client *Client) ProcessChatFolderNewChats(req *ProcessChatFolderNewChatsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "processChatFolderNewChats",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_folder_id": req.ChatFolderId,
"added_chat_ids": req.AddedChatIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns settings for automatic moving of chats to and from the Archive chat lists
func (client *Client) GetArchiveChatListSettings() (*ArchiveChatListSettings, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getArchiveChatListSettings",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-02-06 18:36:17 +00:00
2023-07-24 18:35:55 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalArchiveChatListSettings(result.Data)
}
type SetArchiveChatListSettingsRequest struct {
// New settings
Settings *ArchiveChatListSettings `json:"settings"`
}
// Changes settings for automatic moving of chats to and from the Archive chat lists
func (client *Client) SetArchiveChatListSettings(req *SetArchiveChatListSettingsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setArchiveChatListSettings",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"settings": req.Settings,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-02-06 18:36:17 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatTitleRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New title of the chat; 1-128 characters
Title string `json:"title"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the chat title. Supported only for basic groups, supergroups and channels. Requires can_change_info administrator right
func (client *Client) SetChatTitle(req *SetChatTitleRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatTitle",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"title": req.Title,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatPhotoRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New chat photo; pass null to delete the chat photo
Photo InputChatPhoto `json:"photo"`
2019-09-10 12:36:54 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the photo of a chat. Supported only for basic groups, supergroups and channels. Requires can_change_info administrator right
func (client *Client) SetChatPhoto(req *SetChatPhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatPhoto",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"photo": req.Photo,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatMessageAutoDeleteTimeRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New time value, in seconds; unless the chat is secret, it must be from 0 up to 365 * 86400 and be divisible by 86400. If 0, then messages aren't deleted automatically
MessageAutoDeleteTime int32 `json:"message_auto_delete_time"`
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the message auto-delete or self-destruct (for secret chats) time in a chat. Requires change_info administrator right in basic groups, supergroups and channels Message auto-delete time can't be changed in a chat with the current user (Saved Messages) and the chat 777000 (Telegram).
func (client *Client) SetChatMessageAutoDeleteTime(req *SetChatMessageAutoDeleteTimeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatMessageAutoDeleteTime",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"message_auto_delete_time": req.MessageAutoDeleteTime,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatPermissionsRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New non-administrator members permissions in the chat
Permissions *ChatPermissions `json:"permissions"`
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the chat members permissions. Supported only for basic groups and supergroups. Requires can_restrict_members administrator right
func (client *Client) SetChatPermissions(req *SetChatPermissionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatPermissions",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"permissions": req.Permissions,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatBackgroundRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// The input background to use; pass null to create a new filled background or to remove the current background
Background InputBackground `json:"background"`
// Background type; pass null to remove the current background
Type BackgroundType `json:"type"`
// Dimming of the background in dark themes, as a percentage; 0-100
DarkThemeDimming int32 `json:"dark_theme_dimming"`
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the background in a specific chat. Supported only in private and secret chats with non-deleted users
func (client *Client) SetChatBackground(req *SetChatBackgroundRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatBackground",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"background": req.Background,
"type": req.Type,
"dark_theme_dimming": req.DarkThemeDimming,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetChatThemeRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// Name of the new chat theme; pass an empty string to return the default theme
ThemeName string `json:"theme_name"`
2019-06-07 10:56:06 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the chat theme. Supported only in private and secret chats
func (client *Client) SetChatTheme(req *SetChatThemeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatTheme",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"theme_name": req.ThemeName,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetChatDraftMessageRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// If not 0, a message thread identifier in which the draft was changed
MessageThreadId int64 `json:"message_thread_id"`
// New draft message; pass null to remove the draft
DraftMessage *DraftMessage `json:"draft_message"`
2019-06-07 10:56:06 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the draft message in a chat
func (client *Client) SetChatDraftMessage(req *SetChatDraftMessageRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatDraftMessage",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"message_thread_id": req.MessageThreadId,
"draft_message": req.DraftMessage,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatNotificationSettingsRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New notification settings for the chat. If the chat is muted for more than 366 days, it is considered to be muted forever
NotificationSettings *ChatNotificationSettings `json:"notification_settings"`
2020-11-30 09:33:47 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the notification settings of a chat. Notification settings of a chat with the current user (Saved Messages) can't be changed
func (client *Client) SetChatNotificationSettings(req *SetChatNotificationSettingsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatNotificationSettings",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"notification_settings": req.NotificationSettings,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-07-24 18:35:55 +00:00
type ToggleChatHasProtectedContentRequest struct {
// Chat identifier
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New value of has_protected_content
HasProtectedContent bool `json:"has_protected_content"`
2022-11-07 18:50:52 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the ability of users to save, forward, or copy chat content. Supported only for basic groups, supergroups and channels. Requires owner privileges
func (client *Client) ToggleChatHasProtectedContent(req *ToggleChatHasProtectedContentRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "toggleChatHasProtectedContent",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"has_protected_content": req.HasProtectedContent,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-07-24 18:35:55 +00:00
type ToggleChatIsTranslatableRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New value of is_translatable
IsTranslatable bool `json:"is_translatable"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the translatable state of a chat; for Telegram Premium users only
func (client *Client) ToggleChatIsTranslatable(req *ToggleChatIsTranslatableRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "toggleChatIsTranslatable",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"is_translatable": req.IsTranslatable,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-07-24 18:35:55 +00:00
type ToggleChatIsMarkedAsUnreadRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New value of is_marked_as_unread
IsMarkedAsUnread bool `json:"is_marked_as_unread"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the marked as unread state of a chat
func (client *Client) ToggleChatIsMarkedAsUnread(req *ToggleChatIsMarkedAsUnreadRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "toggleChatIsMarkedAsUnread",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"is_marked_as_unread": req.IsMarkedAsUnread,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type ToggleChatDefaultDisableNotificationRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New value of default_disable_notification
DefaultDisableNotification bool `json:"default_disable_notification"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the value of the default disable_notification parameter, used when a message is sent to a chat
func (client *Client) ToggleChatDefaultDisableNotification(req *ToggleChatDefaultDisableNotificationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "toggleChatDefaultDisableNotification",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"default_disable_notification": req.DefaultDisableNotification,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetChatAvailableReactionsRequest struct {
// Identifier of the chat
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// Reactions available in the chat. All emoji reactions must be active
AvailableReactions ChatAvailableReactions `json:"available_reactions"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes reactions, available in a chat. Available for basic groups, supergroups, and channels. Requires can_change_info administrator right
func (client *Client) SetChatAvailableReactions(req *SetChatAvailableReactionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatAvailableReactions",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"available_reactions": req.AvailableReactions,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetChatClientDataRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New value of client_data
ClientData string `json:"client_data"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes application-specific data associated with a chat
func (client *Client) SetChatClientData(req *SetChatClientDataRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatClientData",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"client_data": req.ClientData,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetChatDescriptionRequest struct {
// Identifier of the chat
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New chat description; 0-255 characters
Description string `json:"description"`
2021-12-30 05:55:02 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes information about a chat. Available for basic groups, supergroups, and channels. Requires can_change_info administrator right
func (client *Client) SetChatDescription(req *SetChatDescriptionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatDescription",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"description": req.Description,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatDiscussionGroupRequest struct {
// Identifier of the channel chat. Pass 0 to remove a link from the supergroup passed in the second argument to a linked channel chat (requires can_pin_messages rights in the supergroup)
ChatId int64 `json:"chat_id"`
// Identifier of a new channel's discussion group. Use 0 to remove the discussion group. Use the method getSuitableDiscussionChats to find all suitable groups. Basic group chats must be first upgraded to supergroup chats. If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable must be used first to change that
DiscussionChatId int64 `json:"discussion_chat_id"`
}
// Changes the discussion group of a channel chat; requires can_change_info administrator right in the channel if it is specified
func (client *Client) SetChatDiscussionGroup(req *SetChatDiscussionGroupRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatDiscussionGroup",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"discussion_chat_id": req.DiscussionChatId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-07-24 18:35:55 +00:00
type SetChatLocationRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New location for the chat; must be valid and not null
Location *ChatLocation `json:"location"`
}
2020-02-03 12:56:20 +00:00
2023-07-24 18:35:55 +00:00
// Changes the location of a chat. Available only for some location-based supergroups, use supergroupFullInfo.can_set_location to check whether the method is allowed to use
func (client *Client) SetChatLocation(req *SetChatLocationRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatLocation",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"location": req.Location,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-07-24 18:35:55 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatSlowModeDelayRequest struct {
2023-03-26 09:37:06 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// New slow mode delay for the chat, in seconds; must be one of 0, 10, 30, 60, 300, 900, 3600
SlowModeDelay int32 `json:"slow_mode_delay"`
2020-02-03 12:56:20 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the slow mode delay of a chat. Available only for supergroups; requires can_restrict_members rights
func (client *Client) SetChatSlowModeDelay(req *SetChatSlowModeDelayRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "setChatSlowModeDelay",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"slow_mode_delay": req.SlowModeDelay,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type PinChatMessageRequest struct {
// Identifier of the chat
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the new pinned message
MessageId int64 `json:"message_id"`
// Pass true to disable notification about the pinned message. Notifications are always disabled in channels and private chats
DisableNotification bool `json:"disable_notification"`
// Pass true to pin the message only for self; private chats only
OnlyForSelf bool `json:"only_for_self"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Pins a message in a chat; requires can_pin_messages rights or can_edit_messages rights in the channel
func (client *Client) PinChatMessage(req *PinChatMessageRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "pinChatMessage",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"message_id": req.MessageId,
"disable_notification": req.DisableNotification,
"only_for_self": req.OnlyForSelf,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2023-03-26 09:37:06 +00:00
}
2023-07-24 18:35:55 +00:00
type UnpinChatMessageRequest struct {
// Identifier of the chat
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2023-07-24 18:35:55 +00:00
// Identifier of the removed pinned message
MessageId int64 `json:"message_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Removes a pinned message from a chat; requires can_pin_messages rights in the group or can_edit_messages rights in the channel
func (client *Client) UnpinChatMessage(req *UnpinChatMessageRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "unpinChatMessage",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-07-24 18:35:55 +00:00
"message_id": req.MessageId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type UnpinAllChatMessagesRequest struct {
// Identifier of the chat
2023-03-26 09:37:06 +00:00
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Removes all pinned messages from a chat; requires can_pin_messages rights in the group or can_edit_messages rights in the channel
func (client *Client) UnpinAllChatMessages(req *UnpinAllChatMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "unpinAllChatMessages",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type UnpinAllMessageThreadMessagesRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Message thread identifier in which messages will be unpinned
MessageThreadId int64 `json:"message_thread_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Removes all pinned messages from a forum topic; requires can_pin_messages rights in the supergroup
func (client *Client) UnpinAllMessageThreadMessages(req *UnpinAllMessageThreadMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "unpinAllMessageThreadMessages",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_id": req.ChatId,
"message_thread_id": req.MessageThreadId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type JoinChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
// Adds the current user as a new member to a chat. Private and secret chats can't be joined using this method. May return an error with a message "INVITE_REQUEST_SENT" if only a join request was created
func (client *Client) JoinChat(req *JoinChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "joinChat",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_id": req.ChatId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
type LeaveChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
}
// Removes the current user from chat members. Private and secret chats can't be left using this method
func (client *Client) LeaveChat(req *LeaveChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "leaveChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
type AddChatMemberRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the user
UserId int64 `json:"user_id"`
// The number of earlier messages from the chat to be forwarded to the new member; up to 100. Ignored for supergroups and channels, or if the added user is a bot
ForwardLimit int32 `json:"forward_limit"`
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
// Adds a new member to a chat. Members can't be added to private or secret chats
func (client *Client) AddChatMember(req *AddChatMemberRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "addChatMember",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_id": req.ChatId,
"user_id": req.UserId,
"forward_limit": req.ForwardLimit,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
type AddChatMembersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifiers of the users to be added to the chat. The maximum number of added users is 20 for supergroups and 100 for channels
UserIds []int64 `json:"user_ids"`
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
// Adds multiple new members to a chat. Currently, this method is only available for supergroups and channels. This method can't be used to join a chat. Members can't be added to a channel if it has more than 200 members
func (client *Client) AddChatMembers(req *AddChatMembersRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "addChatMembers",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_id": req.ChatId,
"user_ids": req.UserIds,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-07-24 18:35:55 +00:00
type SetChatMemberStatusRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Member identifier. Chats can be only banned and unbanned in supergroups and channels
MemberId MessageSender `json:"member_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 transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if some additional parameters needs to be passed
func (client *Client) SetChatMemberStatus(req *SetChatMemberStatusRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatMemberStatus",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"member_id": req.MemberId,
"status": req.Status,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type BanChatMemberRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Member identifier
MemberId MessageSender `json:"member_id"`
// Point in time (Unix timestamp) when the user will be unbanned; 0 if never. If the user is banned for more than 366 days or for less than 30 seconds from the current time, the user is considered to be banned forever. Ignored in basic groups and if a chat is banned
BannedUntilDate int32 `json:"banned_until_date"`
// Pass true to delete all messages in the chat for the user that is being removed. Always true for supergroups and channels
RevokeMessages bool `json:"revoke_messages"`
}
// Bans a member in a chat. Members can't be banned in private or secret chats. In supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first
func (client *Client) BanChatMember(req *BanChatMemberRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "banChatMember",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"member_id": req.MemberId,
"banned_until_date": req.BannedUntilDate,
"revoke_messages": req.RevokeMessages,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Checks whether the current session can be used to transfer a chat ownership to another user
func (client *Client) CanTransferOwnership() (CanTransferOwnershipResult, error) {
result, err := client.Send(Request{
meta: meta{
Type: "canTransferOwnership",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeCanTransferOwnershipResultOk:
return UnmarshalCanTransferOwnershipResultOk(result.Data)
case TypeCanTransferOwnershipResultPasswordNeeded:
return UnmarshalCanTransferOwnershipResultPasswordNeeded(result.Data)
case TypeCanTransferOwnershipResultPasswordTooFresh:
return UnmarshalCanTransferOwnershipResultPasswordTooFresh(result.Data)
case TypeCanTransferOwnershipResultSessionTooFresh:
return UnmarshalCanTransferOwnershipResultSessionTooFresh(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type TransferChatOwnershipRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the user to which transfer the ownership. The ownership can't be transferred to a bot or to a deleted user
UserId int64 `json:"user_id"`
// The 2-step verification password of the current user
Password string `json:"password"`
}
// Changes the owner of a chat. The current user must be a current owner of the chat. Use the method canTransferOwnership to check whether the ownership can be transferred from the current session. Available only for supergroups and channel chats
func (client *Client) TransferChatOwnership(req *TransferChatOwnershipRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "transferChatOwnership",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatMemberRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Member identifier
MemberId MessageSender `json:"member_id"`
}
// Returns information about a single member of a chat
func (client *Client) GetChatMember(req *GetChatMemberRequest) (*ChatMember, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatMember",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"member_id": req.MemberId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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; up to 200
Limit int32 `json:"limit"`
// The type of users to search for; pass null to search among all chat members
Filter ChatMembersFilter `json:"filter"`
}
// Searches for a specified query in the first name, last name and usernames of the members of a specified chat. Requires administrator rights in channels
func (client *Client) SearchChatMembers(req *SearchChatMembersRequest) (*ChatMembers, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatMembers",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"limit": req.Limit,
"filter": req.Filter,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatMembers(result.Data)
}
type GetChatAdministratorsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
}
// Returns a list of administrators of the chat with their custom titles
func (client *Client) GetChatAdministrators(req *GetChatAdministratorsRequest) (*ChatAdministrators, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatAdministrators",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatAdministrators(result.Data)
}
type ClearAllDraftMessagesRequest struct {
// Pass true to keep local message drafts in secret chats
ExcludeSecretChats bool `json:"exclude_secret_chats"`
}
// Clears message drafts in all chats
func (client *Client) ClearAllDraftMessages(req *ClearAllDraftMessagesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "clearAllDraftMessages",
},
Data: map[string]interface{}{
"exclude_secret_chats": req.ExcludeSecretChats,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetSavedNotificationSoundRequest struct {
// Identifier of the notification sound
NotificationSoundId JsonInt64 `json:"notification_sound_id"`
}
// Returns saved notification sound by its identifier. Returns a 404 error if there is no saved notification sound with the specified identifier
func (client *Client) GetSavedNotificationSound(req *GetSavedNotificationSoundRequest) (*NotificationSounds, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSavedNotificationSound",
},
Data: map[string]interface{}{
"notification_sound_id": req.NotificationSoundId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalNotificationSounds(result.Data)
}
// Returns list of saved notification sounds. If a sound isn't in the list, then default sound needs to be used
func (client *Client) GetSavedNotificationSounds() (*NotificationSounds, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSavedNotificationSounds",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalNotificationSounds(result.Data)
}
type AddSavedNotificationSoundRequest struct {
// Notification sound file to add
Sound InputFile `json:"sound"`
}
// Adds a new notification sound to the list of saved notification sounds. The new notification sound is added to the top of the list. If it is already in the list, its position isn't changed
func (client *Client) AddSavedNotificationSound(req *AddSavedNotificationSoundRequest) (*NotificationSound, error) {
result, err := client.Send(Request{
meta: meta{
Type: "addSavedNotificationSound",
},
Data: map[string]interface{}{
"sound": req.Sound,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalNotificationSound(result.Data)
}
type RemoveSavedNotificationSoundRequest struct {
// Identifier of the notification sound
NotificationSoundId JsonInt64 `json:"notification_sound_id"`
}
// Removes a notification sound from the list of saved notification sounds
func (client *Client) RemoveSavedNotificationSound(req *RemoveSavedNotificationSoundRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "removeSavedNotificationSound",
},
Data: map[string]interface{}{
"notification_sound_id": req.NotificationSoundId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatNotificationSettingsExceptionsRequest struct {
// If specified, only chats from the scope will be returned; pass null to return chats from all scopes
Scope NotificationSettingsScope `json:"scope"`
// Pass true to include in the response chats with only non-default sound
CompareSound bool `json:"compare_sound"`
}
// Returns list of chats with non-default notification settings for new messages
func (client *Client) GetChatNotificationSettingsExceptions(req *GetChatNotificationSettingsExceptionsRequest) (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatNotificationSettingsExceptions",
},
Data: map[string]interface{}{
"scope": req.Scope,
"compare_sound": req.CompareSound,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(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
func (client *Client) GetScopeNotificationSettings(req *GetScopeNotificationSettingsRequest) (*ScopeNotificationSettings, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getScopeNotificationSettings",
},
Data: map[string]interface{}{
"scope": req.Scope,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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
func (client *Client) SetScopeNotificationSettings(req *SetScopeNotificationSettingsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setScopeNotificationSettings",
},
Data: map[string]interface{}{
"scope": req.Scope,
"notification_settings": req.NotificationSettings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Resets all notification settings to their default values. By default, all chats are unmuted and message previews are shown
func (client *Client) ResetAllNotificationSettings() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resetAllNotificationSettings",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleChatIsPinnedRequest struct {
// Chat list in which to change the pinned state of the chat
ChatList ChatList `json:"chat_list"`
// Chat identifier
ChatId int64 `json:"chat_id"`
// Pass true to pin the chat; pass false to unpin it
IsPinned bool `json:"is_pinned"`
}
// Changes the pinned state of a chat. There can be up to getOption("pinned_chat_count_max")/getOption("pinned_archived_chat_count_max") pinned non-secret chats and the same number of secret chats in the main/archive chat list. The limit can be increased with Telegram Premium
func (client *Client) ToggleChatIsPinned(req *ToggleChatIsPinnedRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "toggleChatIsPinned",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
"chat_id": req.ChatId,
"is_pinned": req.IsPinned,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetPinnedChatsRequest struct {
// Chat list in which to change the order of pinned chats
ChatList ChatList `json:"chat_list"`
// The new list of pinned chats
ChatIds []int64 `json:"chat_ids"`
}
// Changes the order of pinned chats
func (client *Client) SetPinnedChats(req *SetPinnedChatsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setPinnedChats",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
"chat_ids": req.ChatIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ReadChatListRequest struct {
// Chat list in which to mark all chats as read
ChatList ChatList `json:"chat_list"`
}
// Traverse all chats in a chat list and marks all messages in the chats as read
func (client *Client) ReadChatList(req *ReadChatListRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "readChatList",
},
Data: map[string]interface{}{
"chat_list": req.ChatList,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetStoryRequest struct {
// Identifier of the chat that posted the story
StorySenderChatId int64 `json:"story_sender_chat_id"`
// Story identifier
StoryId int32 `json:"story_id"`
// Pass true to get only locally available information without sending network requests
OnlyLocal bool `json:"only_local"`
}
// Returns a story
func (client *Client) GetStory(req *GetStoryRequest) (*Story, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getStory",
},
Data: map[string]interface{}{
"story_sender_chat_id": req.StorySenderChatId,
"story_id": req.StoryId,
"only_local": req.OnlyLocal,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStory(result.Data)
}
2023-08-15 18:28:13 +00:00
// Checks whether the current user can send a story
func (client *Client) CanSendStory() (CanSendStoryResult, error) {
result, err := client.Send(Request{
meta: meta{
Type: "canSendStory",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeCanSendStoryResultOk:
return UnmarshalCanSendStoryResultOk(result.Data)
case TypeCanSendStoryResultPremiumNeeded:
return UnmarshalCanSendStoryResultPremiumNeeded(result.Data)
case TypeCanSendStoryResultActiveStoryLimitExceeded:
return UnmarshalCanSendStoryResultActiveStoryLimitExceeded(result.Data)
case TypeCanSendStoryResultWeeklyLimitExceeded:
return UnmarshalCanSendStoryResultWeeklyLimitExceeded(result.Data)
case TypeCanSendStoryResultMonthlyLimitExceeded:
return UnmarshalCanSendStoryResultMonthlyLimitExceeded(result.Data)
default:
return nil, errors.New("invalid type")
}
}
2023-07-24 18:35:55 +00:00
type SendStoryRequest struct {
// Content of the story
Content InputStoryContent `json:"content"`
2023-08-15 18:28:13 +00:00
// Clickable rectangle areas to be shown on the story media; pass null if none
Areas *InputStoryAreas `json:"areas"`
2023-07-24 18:35:55 +00:00
// Story caption; pass null to use an empty caption; 0-getOption("story_caption_length_max") characters
Caption *FormattedText `json:"caption"`
// The privacy settings for the story
PrivacySettings StoryPrivacySettings `json:"privacy_settings"`
2023-08-15 18:28:13 +00:00
// Period after which the story is moved to archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400 for Telegram Premium users, and 86400 otherwise
2023-07-24 18:35:55 +00:00
ActivePeriod int32 `json:"active_period"`
// Pass true to keep the story accessible after expiration
IsPinned bool `json:"is_pinned"`
// Pass true if the content of the story must be protected from forwarding and screenshotting
ProtectContent bool `json:"protect_content"`
}
2023-08-15 18:28:13 +00:00
// Sends a new story. Returns a temporary story
2023-07-24 18:35:55 +00:00
func (client *Client) SendStory(req *SendStoryRequest) (*Story, error) {
result, err := client.Send(Request{
meta: meta{
Type: "sendStory",
},
Data: map[string]interface{}{
"content": req.Content,
2023-08-15 18:28:13 +00:00
"areas": req.Areas,
2023-07-24 18:35:55 +00:00
"caption": req.Caption,
"privacy_settings": req.PrivacySettings,
"active_period": req.ActivePeriod,
"is_pinned": req.IsPinned,
"protect_content": req.ProtectContent,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStory(result.Data)
}
type EditStoryRequest struct {
// Identifier of the story to edit
StoryId int32 `json:"story_id"`
// New content of the story; pass null to keep the current content
Content InputStoryContent `json:"content"`
2023-08-15 18:28:13 +00:00
// New clickable rectangle areas to be shown on the story media; pass null to keep the current areas. Areas can't be edited if story content isn't changed
Areas *InputStoryAreas `json:"areas"`
2023-07-24 18:35:55 +00:00
// New story caption; pass null to keep the current caption
Caption *FormattedText `json:"caption"`
}
// Changes content and caption of a previously sent story
func (client *Client) EditStory(req *EditStoryRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "editStory",
},
Data: map[string]interface{}{
"story_id": req.StoryId,
"content": req.Content,
2023-08-15 18:28:13 +00:00
"areas": req.Areas,
2023-07-24 18:35:55 +00:00
"caption": req.Caption,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetStoryPrivacySettingsRequest struct {
// Identifier of the story
StoryId int32 `json:"story_id"`
// The new privacy settigs for the story
PrivacySettings StoryPrivacySettings `json:"privacy_settings"`
}
// Changes privacy settings of a previously sent story
func (client *Client) SetStoryPrivacySettings(req *SetStoryPrivacySettingsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setStoryPrivacySettings",
},
Data: map[string]interface{}{
"story_id": req.StoryId,
"privacy_settings": req.PrivacySettings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleStoryIsPinnedRequest struct {
// Identifier of the story
StoryId int32 `json:"story_id"`
// Pass true to make the story accessible after expiration; pass false to make it private
IsPinned bool `json:"is_pinned"`
}
// Toggles whether a story is accessible after expiration
func (client *Client) ToggleStoryIsPinned(req *ToggleStoryIsPinnedRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "toggleStoryIsPinned",
},
Data: map[string]interface{}{
"story_id": req.StoryId,
"is_pinned": req.IsPinned,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteStoryRequest struct {
// Identifier of the story to delete
StoryId int32 `json:"story_id"`
}
// Deletes a previously sent story
func (client *Client) DeleteStory(req *DeleteStoryRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "deleteStory",
},
Data: map[string]interface{}{
"story_id": req.StoryId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns list of chats with non-default notification settings for stories
func (client *Client) GetStoryNotificationSettingsExceptions() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getStoryNotificationSettingsExceptions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type LoadActiveStoriesRequest struct {
// The story list in which to load active stories
StoryList StoryList `json:"story_list"`
}
// Loads more active stories from a story list. The loaded stories will be sent through updates. Active stories are sorted by the pair (active_stories.order, active_stories.story_sender_chat_id) in descending order. Returns a 404 error if all active stories have been loaded
func (client *Client) LoadActiveStories(req *LoadActiveStoriesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "loadActiveStories",
},
Data: map[string]interface{}{
"story_list": req.StoryList,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetChatActiveStoriesListRequest struct {
// Identifier of the chat that posted stories
ChatId int64 `json:"chat_id"`
// New list for active stories posted by the chat
StoryList StoryList `json:"story_list"`
}
// Changes story list in which stories from the chat are shown
func (client *Client) SetChatActiveStoriesList(req *SetChatActiveStoriesListRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatActiveStoriesList",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"story_list": req.StoryList,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatActiveStoriesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
}
// Returns the list of active stories posted by the given chat
func (client *Client) GetChatActiveStories(req *GetChatActiveStoriesRequest) (*ChatActiveStories, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getChatActiveStories",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatActiveStories(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-07-24 18:35:55 +00:00
type GetChatPinnedStoriesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the story starting from which stories must be returned; use 0 to get results from the last story
FromStoryId int32 `json:"from_story_id"`
// The maximum number of stories to be returned For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
}
// Returns the list of pinned stories posted by the given chat. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). For optimal performance, the number of returned stories is chosen by TDLib
func (client *Client) GetChatPinnedStories(req *GetChatPinnedStoriesRequest) (*Stories, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getChatPinnedStories",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"chat_id": req.ChatId,
"from_story_id": req.FromStoryId,
"limit": req.Limit,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalStories(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-07-24 18:35:55 +00:00
type GetArchivedStoriesRequest struct {
// Identifier of the story starting from which stories must be returned; use 0 to get results from the last story
FromStoryId int32 `json:"from_story_id"`
// The maximum number of stories to be returned For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns the list of all stories of the current user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). For optimal performance, the number of returned stories is chosen by TDLib
func (client *Client) GetArchivedStories(req *GetArchivedStoriesRequest) (*Stories, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getArchivedStories",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"from_story_id": req.FromStoryId,
"limit": req.Limit,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
return UnmarshalStories(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
type OpenStoryRequest struct {
// The identifier of the sender of the opened story
StorySenderChatId int64 `json:"story_sender_chat_id"`
// The identifier of the story
StoryId int32 `json:"story_id"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Informs TDLib that a story is opened and is being viewed by the user
func (client *Client) OpenStory(req *OpenStoryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "openStory",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"story_sender_chat_id": req.StorySenderChatId,
"story_id": req.StoryId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-07-24 18:35:55 +00:00
type CloseStoryRequest struct {
// The identifier of the sender of the story to close
StorySenderChatId int64 `json:"story_sender_chat_id"`
// The identifier of the story
StoryId int32 `json:"story_id"`
}
// Informs TDLib that a story is closed by the user
func (client *Client) CloseStory(req *CloseStoryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "closeStory",
},
Data: map[string]interface{}{
"story_sender_chat_id": req.StorySenderChatId,
"story_id": req.StoryId,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-08-15 18:28:13 +00:00
type GetStoryAvailableReactionsRequest struct {
// Number of reaction per row, 5-25
RowSize int32 `json:"row_size"`
}
// Returns reactions, which can be chosen for a story
func (client *Client) GetStoryAvailableReactions(req *GetStoryAvailableReactionsRequest) (*AvailableReactions, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getStoryAvailableReactions",
},
Data: map[string]interface{}{
"row_size": req.RowSize,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAvailableReactions(result.Data)
}
type SetStoryReactionRequest struct {
// The identifier of the sender of the story
StorySenderChatId int64 `json:"story_sender_chat_id"`
// The identifier of the story
StoryId int32 `json:"story_id"`
// Type of the reaction to set; pass null to remove the reaction. `reactionTypeCustomEmoji` reactions can be used only by Telegram Premium users
ReactionType ReactionType `json:"reaction_type"`
// Pass true if the reaction needs to be added to recent reactions
UpdateRecentReactions bool `json:"update_recent_reactions"`
}
// Changes chosen reaction on a story
func (client *Client) SetStoryReaction(req *SetStoryReactionRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setStoryReaction",
},
Data: map[string]interface{}{
"story_sender_chat_id": req.StorySenderChatId,
"story_id": req.StoryId,
"reaction_type": req.ReactionType,
"update_recent_reactions": req.UpdateRecentReactions,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-07-24 18:35:55 +00:00
type GetStoryViewersRequest struct {
// Story identifier
StoryId int32 `json:"story_id"`
2023-08-15 18:28:13 +00:00
// Query to search for in names and usernames of the viewers; may be empty to get all relevant viewers
Query string `json:"query"`
// Pass true to get only contacts; pass false to get all relevant viewers
OnlyContacts bool `json:"only_contacts"`
// Pass true to get viewers with reaction first; pass false to get viewers sorted just by view_date
PreferWithReaction bool `json:"prefer_with_reaction"`
// 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 story viewers to return
2023-07-24 18:35:55 +00:00
Limit int32 `json:"limit"`
2020-11-30 09:33:47 +00:00
}
2023-08-15 18:28:13 +00:00
// Returns viewers of a story. The method can be called if story.can_get_viewers == true
func (client *Client) GetStoryViewers(req *GetStoryViewersRequest) (*StoryViewers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "getStoryViewers",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"story_id": req.StoryId,
2023-08-15 18:28:13 +00:00
"query": req.Query,
"only_contacts": req.OnlyContacts,
"prefer_with_reaction": req.PreferWithReaction,
"offset": req.Offset,
2023-07-24 18:35:55 +00:00
"limit": req.Limit,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-08-15 18:28:13 +00:00
return UnmarshalStoryViewers(result.Data)
2023-03-26 09:37:06 +00:00
}
2023-07-24 18:35:55 +00:00
type ReportStoryRequest struct {
// The identifier of the sender of the story to report
StorySenderChatId int64 `json:"story_sender_chat_id"`
// The identifier of the story to report
StoryId int32 `json:"story_id"`
// The reason for reporting the story
Reason ReportReason `json:"reason"`
// Additional report details; 0-1024 characters
Text string `json:"text"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Reports a story to the Telegram moderators
func (client *Client) ReportStory(req *ReportStoryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-07-24 18:35:55 +00:00
Type: "reportStory",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"story_sender_chat_id": req.StorySenderChatId,
"story_id": req.StoryId,
"reason": req.Reason,
"text": req.Text,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-08-15 18:28:13 +00:00
// Activates stealth mode for stories, which hides all views of stories from the current user in the last "story_stealth_mode_past_period" seconds and for the next "story_stealth_mode_future_period" seconds; for Telegram Premium users only
func (client *Client) ActivateStoryStealthMode() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "activateStoryStealthMode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-03-26 09:37:06 +00:00
type GetAttachmentMenuBotRequest struct {
// Bot's user identifier
BotUserId int64 `json:"bot_user_id"`
2022-04-24 20:33:39 +00:00
}
2023-09-16 07:09:40 +00:00
// Returns information about a bot that can be added to attachment or side menu
2022-04-24 20:33:39 +00:00
func (client *Client) GetAttachmentMenuBot(req *GetAttachmentMenuBotRequest) (*AttachmentMenuBot, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAttachmentMenuBot",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAttachmentMenuBot(result.Data)
}
type ToggleBotIsAddedToAttachmentMenuRequest struct {
// Bot's user identifier
BotUserId int64 `json:"bot_user_id"`
// Pass true to add the bot to attachment menu; pass false to remove the bot from attachment menu
IsAdded bool `json:"is_added"`
// Pass true if the current user allowed the bot to send them messages. Ignored if is_added is false
AllowWriteAccess bool `json:"allow_write_access"`
2022-04-24 20:33:39 +00:00
}
2023-09-16 07:09:40 +00:00
// Adds or removes a bot to attachment and side menu. Bot can be added to the menu, only if userTypeBot.can_be_added_to_attachment_menu == true
2022-04-24 20:33:39 +00:00
func (client *Client) ToggleBotIsAddedToAttachmentMenu(req *ToggleBotIsAddedToAttachmentMenuRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleBotIsAddedToAttachmentMenu",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"is_added": req.IsAdded,
"allow_write_access": req.AllowWriteAccess,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2022-12-30 18:28:59 +00:00
// Returns up to 8 emoji statuses, which must be shown right after the default Premium Badge in the emoji status list
2022-09-18 01:34:29 +00:00
func (client *Client) GetThemedEmojiStatuses() (*EmojiStatuses, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getThemedEmojiStatuses",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojiStatuses(result.Data)
2022-09-18 01:34:29 +00:00
}
// Returns recent emoji statuses
func (client *Client) GetRecentEmojiStatuses() (*EmojiStatuses, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecentEmojiStatuses",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojiStatuses(result.Data)
2022-09-18 01:34:29 +00:00
}
// Returns default emoji statuses
func (client *Client) GetDefaultEmojiStatuses() (*EmojiStatuses, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDefaultEmojiStatuses",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojiStatuses(result.Data)
2022-09-18 01:34:29 +00:00
}
// Clears the list of recently used emoji statuses
func (client *Client) ClearRecentEmojiStatuses() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearRecentEmojiStatuses",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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/addFileToDownloads was called will be downloaded first
Priority int32 `json:"priority"`
// The starting position from which the file needs to be downloaded
Offset int64 `json:"offset"`
// Number of bytes which need to be downloaded starting from the "offset" position before the download will automatically be canceled; use 0 to download without a limit
Limit int64 `json:"limit"`
// Pass true to return response only after the file download has succeeded, has failed, has been canceled, or a new downloadFile request with different offset/limit parameters was sent; pass false to return file state immediately, just after the download has been started
Synchronous bool `json:"synchronous"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
2018-10-16 20:32:57 +00:00
func (client *Client) DownloadFile(req *DownloadFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "downloadFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"priority": req.Priority,
"offset": req.Offset,
"limit": req.Limit,
"synchronous": req.Synchronous,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type GetFileDownloadedPrefixSizeRequest struct {
// Identifier of the file
FileId int32 `json:"file_id"`
// Offset from which downloaded prefix size needs to be calculated
Offset int64 `json:"offset"`
2019-06-07 10:56:06 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns file downloaded prefix size from a given offset, in bytes
2022-06-21 18:10:07 +00:00
func (client *Client) GetFileDownloadedPrefixSize(req *GetFileDownloadedPrefixSizeRequest) (*FileDownloadedPrefixSize, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getFileDownloadedPrefixSize",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"offset": req.Offset,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFileDownloadedPrefixSize(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Stops the downloading of a file. If a file has already been downloaded, does nothing
2018-10-16 20:32:57 +00:00
func (client *Client) CancelDownloadFile(req *CancelDownloadFileRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "cancelDownloadFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"only_if_pending": req.OnlyIfPending,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type GetSuggestedFileNameRequest struct {
// Identifier of the file
FileId int32 `json:"file_id"`
// Directory in which the file is supposed to be saved
Directory string `json:"directory"`
2021-12-30 05:55:02 +00:00
}
// Returns suggested name for saving a file in a given directory
func (client *Client) GetSuggestedFileName(req *GetSuggestedFileNameRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSuggestedFileName",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"directory": req.Directory,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type PreliminaryUploadFileRequest struct {
// File to upload
File InputFile `json:"file"`
// File type; pass null if unknown
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 preliminaryUploadFile was called will be uploaded first
Priority int32 `json:"priority"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// Preliminary uploads a file to the cloud before sending it in a message, which can be useful for uploading of being recorded voice and video notes. Updates 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
func (client *Client) PreliminaryUploadFile(req *PreliminaryUploadFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "preliminaryUploadFile",
},
Data: map[string]interface{}{
"file": req.File,
"file_type": req.FileType,
"priority": req.Priority,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFile(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CancelPreliminaryUploadFileRequest struct {
// Identifier of the file to stop uploading
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// Stops the preliminary uploading of a file. Supported only for files uploaded by using preliminaryUploadFile. For other files the behavior is undefined
func (client *Client) CancelPreliminaryUploadFile(req *CancelPreliminaryUploadFileRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "cancelPreliminaryUploadFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type WriteGeneratedFilePartRequest struct {
// The identifier of the generation process
GenerationId JsonInt64 `json:"generation_id"`
// The offset from which to write the data to the file
Offset int64 `json:"offset"`
// The data to write
Data []byte `json:"data"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Writes a part of a generated file. This method is intended to be used only if the application has no direct access to TDLib's file system, because it is usually slower than a direct write to the destination file
2019-06-07 10:56:06 +00:00
func (client *Client) WriteGeneratedFilePart(req *WriteGeneratedFilePartRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "writeGeneratedFilePart",
},
Data: map[string]interface{}{
"generation_id": req.GenerationId,
"offset": req.Offset,
"data": req.Data,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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 int64 `json:"expected_size"`
// The number of bytes already generated
LocalPrefixSize int64 `json:"local_prefix_size"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Informs TDLib on a file generation progress
2018-10-16 20:32:57 +00:00
func (client *Client) SetFileGenerationProgress(req *SetFileGenerationProgressRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setFileGenerationProgress",
},
Data: map[string]interface{}{
"generation_id": req.GenerationId,
"expected_size": req.ExpectedSize,
"local_prefix_size": req.LocalPrefixSize,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type FinishFileGenerationRequest struct {
// The identifier of the generation process
GenerationId JsonInt64 `json:"generation_id"`
// If passed, the file generation has failed and must be terminated; pass null if the file generation succeeded
Error *Error `json:"error"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Finishes the file generation
2018-10-16 20:32:57 +00:00
func (client *Client) FinishFileGeneration(req *FinishFileGenerationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "finishFileGeneration",
},
Data: map[string]interface{}{
"generation_id": req.GenerationId,
"error": req.Error,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ReadFilePartRequest struct {
// Identifier of the file. The file must be located in the TDLib file cache
FileId int32 `json:"file_id"`
// The offset from which to read the file
Offset int64 `json:"offset"`
// Number of bytes to read. An error will be returned if there are not enough bytes available in the file from the specified position. Pass 0 to read all available data from the specified position
Count int64 `json:"count"`
2021-12-30 05:55:02 +00:00
}
// Reads a part of a file from the TDLib file cache and returns read bytes. This method is intended to be used only if the application has no direct access to TDLib's file system, because it is usually slower than a direct read from the file
func (client *Client) ReadFilePart(req *ReadFilePartRequest) (*FilePart, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "readFilePart",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"offset": req.Offset,
"count": req.Count,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFilePart(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteFileRequest struct {
// Identifier of the file to delete
FileId int32 `json:"file_id"`
2021-12-30 05:55:02 +00:00
}
// Deletes a file from the TDLib file cache
func (client *Client) DeleteFile(req *DeleteFileRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteFile",
},
Data: map[string]interface{}{
"file_id": req.FileId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AddFileToDownloadsRequest struct {
// Identifier of the file to download
FileId int32 `json:"file_id"`
// Chat identifier of the message with the file
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_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/addFileToDownloads was called will be downloaded first
Priority int32 `json:"priority"`
2022-03-13 04:04:12 +00:00
}
// Adds a file from a message to the list of file downloads. Download progress and completion of the download will be notified through updateFile updates. If message database is used, the list of file downloads is persistent across application restarts. The downloading is independent from download using downloadFile, i.e. it continues if downloadFile is canceled or is used to download a part of the file
func (client *Client) AddFileToDownloads(req *AddFileToDownloadsRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addFileToDownloads",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"chat_id": req.ChatId,
"message_id": req.MessageId,
"priority": req.Priority,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type ToggleDownloadIsPausedRequest struct {
// Identifier of the downloaded file
FileId int32 `json:"file_id"`
// Pass true if the download is paused
IsPaused bool `json:"is_paused"`
2022-03-13 04:04:12 +00:00
}
// Changes pause state of a file in the file download list
func (client *Client) ToggleDownloadIsPaused(req *ToggleDownloadIsPausedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleDownloadIsPaused",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"is_paused": req.IsPaused,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleAllDownloadsArePausedRequest struct {
// Pass true to pause all downloads; pass false to unpause them
ArePaused bool `json:"are_paused"`
2022-03-13 04:04:12 +00:00
}
// Changes pause state of all files in the file download list
func (client *Client) ToggleAllDownloadsArePaused(req *ToggleAllDownloadsArePausedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleAllDownloadsArePaused",
},
Data: map[string]interface{}{
"are_paused": req.ArePaused,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveFileFromDownloadsRequest struct {
// Identifier of the downloaded file
FileId int32 `json:"file_id"`
// Pass true to delete the file from the TDLib file cache
DeleteFromCache bool `json:"delete_from_cache"`
2022-03-13 04:04:12 +00:00
}
// Removes a file from the file download list
func (client *Client) RemoveFileFromDownloads(req *RemoveFileFromDownloadsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeFileFromDownloads",
},
Data: map[string]interface{}{
"file_id": req.FileId,
"delete_from_cache": req.DeleteFromCache,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RemoveAllFilesFromDownloadsRequest struct {
// Pass true to remove only active downloads, including paused
OnlyActive bool `json:"only_active"`
// Pass true to remove only completed downloads
OnlyCompleted bool `json:"only_completed"`
// Pass true to delete the file from the TDLib file cache
DeleteFromCache bool `json:"delete_from_cache"`
2022-03-13 04:04:12 +00:00
}
// Removes all files from the file download list
func (client *Client) RemoveAllFilesFromDownloads(req *RemoveAllFilesFromDownloadsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeAllFilesFromDownloads",
},
Data: map[string]interface{}{
"only_active": req.OnlyActive,
"only_completed": req.OnlyCompleted,
"delete_from_cache": req.DeleteFromCache,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SearchFileDownloadsRequest struct {
// Query to search for; may be empty to return all downloaded files
Query string `json:"query"`
// Pass true to search only for active downloads, including paused
OnlyActive bool `json:"only_active"`
// Pass true to search only for completed downloads
OnlyCompleted bool `json:"only_completed"`
// 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 files to be returned
Limit int32 `json:"limit"`
2022-03-13 04:04:12 +00:00
}
// Searches for files in the file download list or recently downloaded files from the list
func (client *Client) SearchFileDownloads(req *SearchFileDownloadsRequest) (*FoundFileDownloads, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchFileDownloads",
},
Data: map[string]interface{}{
"query": req.Query,
"only_active": req.OnlyActive,
"only_completed": req.OnlyCompleted,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundFileDownloads(result.Data)
}
type GetMessageFileTypeRequest struct {
// Beginning of the message file; up to 100 first lines
MessageFileHead string `json:"message_file_head"`
2021-12-30 05:55:02 +00:00
}
2022-06-21 18:10:07 +00:00
// Returns information about a file with messages exported from another application
2021-12-30 05:55:02 +00:00
func (client *Client) GetMessageFileType(req *GetMessageFileTypeRequest) (MessageFileType, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageFileType",
},
Data: map[string]interface{}{
"message_file_head": req.MessageFileHead,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeMessageFileTypePrivate:
return UnmarshalMessageFileTypePrivate(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeMessageFileTypeGroup:
return UnmarshalMessageFileTypeGroup(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeMessageFileTypeUnknown:
return UnmarshalMessageFileTypeUnknown(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMessageImportConfirmationTextRequest struct {
// Identifier of a chat to which the messages will be imported. It must be an identifier of a private chat with a mutual contact or an identifier of a supergroup chat with can_change_info administrator right
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
// Returns a confirmation text to be shown to the user before starting message import
func (client *Client) GetMessageImportConfirmationText(req *GetMessageImportConfirmationTextRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageImportConfirmationText",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type ImportMessagesRequest struct {
// Identifier of a chat to which the messages will be imported. It must be an identifier of a private chat with a mutual contact or an identifier of a supergroup chat with can_change_info administrator right
ChatId int64 `json:"chat_id"`
// File with messages to import. Only inputFileLocal and inputFileGenerated are supported. The file must not be previously uploaded
MessageFile InputFile `json:"message_file"`
// Files used in the imported messages. Only inputFileLocal and inputFileGenerated are supported. The files must not be previously uploaded
AttachedFiles []InputFile `json:"attached_files"`
2021-12-30 05:55:02 +00:00
}
// Imports messages exported from another app
func (client *Client) ImportMessages(req *ImportMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "importMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_file": req.MessageFile,
"attached_files": req.AttachedFiles,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type ReplacePrimaryChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
// Replaces current primary invite link for a chat with a new primary invite link. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right
func (client *Client) ReplacePrimaryChatInviteLink(req *ReplacePrimaryChatInviteLinkRequest) (*ChatInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "replacePrimaryChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLink(result.Data)
}
type CreateChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link name; 0-32 characters
Name string `json:"name"`
// Point in time (Unix timestamp) when the link will expire; pass 0 if never
ExpirationDate int32 `json:"expiration_date"`
// The maximum number of chat members that can join the chat via the link simultaneously; 0-99999; pass 0 if not limited
MemberLimit int32 `json:"member_limit"`
// Pass true if users joining the chat via the link need to be approved by chat administrators. In this case, member_limit must be 0
CreatesJoinRequest bool `json:"creates_join_request"`
2021-12-30 05:55:02 +00:00
}
// Creates a new invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat
func (client *Client) CreateChatInviteLink(req *CreateChatInviteLinkRequest) (*ChatInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"name": req.Name,
"expiration_date": req.ExpirationDate,
"member_limit": req.MemberLimit,
"creates_join_request": req.CreatesJoinRequest,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLink(result.Data)
}
type EditChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link to be edited
InviteLink string `json:"invite_link"`
// Invite link name; 0-32 characters
Name string `json:"name"`
// Point in time (Unix timestamp) when the link will expire; pass 0 if never
ExpirationDate int32 `json:"expiration_date"`
// The maximum number of chat members that can join the chat via the link simultaneously; 0-99999; pass 0 if not limited
MemberLimit int32 `json:"member_limit"`
// Pass true if users joining the chat via the link need to be approved by chat administrators. In this case, member_limit must be 0
CreatesJoinRequest bool `json:"creates_join_request"`
2021-12-30 05:55:02 +00:00
}
// Edits a non-primary invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
func (client *Client) EditChatInviteLink(req *EditChatInviteLinkRequest) (*ChatInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
"name": req.Name,
"expiration_date": req.ExpirationDate,
"member_limit": req.MemberLimit,
"creates_join_request": req.CreatesJoinRequest,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLink(result.Data)
}
type GetChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link to get
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
// Returns information about an invite link. Requires administrator privileges and can_invite_users right in the chat to get own links and owner privileges to get other links
func (client *Client) GetChatInviteLink(req *GetChatInviteLinkRequest) (*ChatInviteLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatInviteLink(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetChatInviteLinkCountsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
// Returns list of chat administrators with number of their invite links. Requires owner privileges in the chat
func (client *Client) GetChatInviteLinkCounts(req *GetChatInviteLinkCountsRequest) (*ChatInviteLinkCounts, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatInviteLinkCounts",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLinkCounts(result.Data)
}
type GetChatInviteLinksRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// User identifier of a chat administrator. Must be an identifier of the current user for non-owner
CreatorUserId int64 `json:"creator_user_id"`
// Pass true if revoked links needs to be returned instead of active or expired
IsRevoked bool `json:"is_revoked"`
// Creation date of an invite link starting after which to return invite links; use 0 to get results from the beginning
OffsetDate int32 `json:"offset_date"`
// Invite link starting after which to return invite links; use empty string to get results from the beginning
OffsetInviteLink string `json:"offset_invite_link"`
// The maximum number of invite links to return; up to 100
Limit int32 `json:"limit"`
2021-12-30 05:55:02 +00:00
}
// Returns invite links for a chat created by specified administrator. Requires administrator privileges and can_invite_users right in the chat to get own links and owner privileges to get other links
func (client *Client) GetChatInviteLinks(req *GetChatInviteLinksRequest) (*ChatInviteLinks, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatInviteLinks",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"creator_user_id": req.CreatorUserId,
"is_revoked": req.IsRevoked,
"offset_date": req.OffsetDate,
"offset_invite_link": req.OffsetInviteLink,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLinks(result.Data)
}
type GetChatInviteLinkMembersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link for which to return chat members
InviteLink string `json:"invite_link"`
// A chat member from which to return next chat members; pass null to get results from the beginning
OffsetMember *ChatInviteLinkMember `json:"offset_member"`
// The maximum number of chat members to return; up to 100
Limit int32 `json:"limit"`
2021-12-30 05:55:02 +00:00
}
// Returns chat members joined a chat via an invite link. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
func (client *Client) GetChatInviteLinkMembers(req *GetChatInviteLinkMembersRequest) (*ChatInviteLinkMembers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatInviteLinkMembers",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
"offset_member": req.OffsetMember,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatInviteLinkMembers(result.Data)
}
type RevokeChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link to be revoked
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
// Revokes invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links. If a primary link is revoked, then additionally to the revoked link returns new primary link
func (client *Client) RevokeChatInviteLink(req *RevokeChatInviteLinkRequest) (*ChatInviteLinks, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "revokeChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatInviteLinks(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteRevokedChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link to revoke
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
// Deletes revoked chat invite links. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
func (client *Client) DeleteRevokedChatInviteLink(req *DeleteRevokedChatInviteLinkRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteRevokedChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteAllRevokedChatInviteLinksRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// User identifier of a chat administrator, which links will be deleted. Must be an identifier of the current user for non-owner
CreatorUserId int64 `json:"creator_user_id"`
2021-12-30 05:55:02 +00:00
}
// Deletes all revoked chat invite links created by a given chat administrator. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
func (client *Client) DeleteAllRevokedChatInviteLinks(req *DeleteAllRevokedChatInviteLinksRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteAllRevokedChatInviteLinks",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"creator_user_id": req.CreatorUserId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckChatInviteLinkRequest struct {
// Invite link to be checked
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
// Checks the validity of an invite link for a chat and returns information about the corresponding chat
func (client *Client) CheckChatInviteLink(req *CheckChatInviteLinkRequest) (*ChatInviteLinkInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkChatInviteLink",
},
Data: map[string]interface{}{
"invite_link": req.InviteLink,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatInviteLinkInfo(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type JoinChatByInviteLinkRequest struct {
// Invite link to use
InviteLink string `json:"invite_link"`
2021-12-30 05:55:02 +00:00
}
2022-06-21 18:10:07 +00:00
// Uses an invite link to add the current user to the chat if possible. May return an error with a message "INVITE_REQUEST_SENT" if only a join request was created
2021-12-30 05:55:02 +00:00
func (client *Client) JoinChatByInviteLink(req *JoinChatByInviteLinkRequest) (*Chat, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "joinChatByInviteLink",
},
Data: map[string]interface{}{
"invite_link": req.InviteLink,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChat(result.Data)
}
type GetChatJoinRequestsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link for which to return join requests. If empty, all join requests will be returned. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
InviteLink string `json:"invite_link"`
// A query to search for in the first names, last names and usernames of the users to return
Query string `json:"query"`
// A chat join request from which to return next requests; pass null to get results from the beginning
OffsetRequest *ChatJoinRequest `json:"offset_request"`
// The maximum number of requests to join the chat to return
Limit int32 `json:"limit"`
2021-12-30 05:55:02 +00:00
}
// Returns pending join requests in a chat
func (client *Client) GetChatJoinRequests(req *GetChatJoinRequestsRequest) (*ChatJoinRequests, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatJoinRequests",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
"query": req.Query,
"offset_request": req.OffsetRequest,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatJoinRequests(result.Data)
}
type ProcessChatJoinRequestRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the user that sent the request
UserId int64 `json:"user_id"`
// Pass true to approve the request; pass false to decline it
Approve bool `json:"approve"`
2021-12-30 05:55:02 +00:00
}
// Handles a pending join request in a chat
func (client *Client) ProcessChatJoinRequest(req *ProcessChatJoinRequestRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "processChatJoinRequest",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
"approve": req.Approve,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ProcessChatJoinRequestsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Invite link for which to process join requests. If empty, all join requests will be processed. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
InviteLink string `json:"invite_link"`
// Pass true to approve all requests; pass false to decline them
Approve bool `json:"approve"`
2021-12-30 05:55:02 +00:00
}
// Handles all pending join requests for a given link in a chat
func (client *Client) ProcessChatJoinRequests(req *ProcessChatJoinRequestsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "processChatJoinRequests",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"invite_link": req.InviteLink,
"approve": req.Approve,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CreateCallRequest struct {
// Identifier of the user to be called
UserId int64 `json:"user_id"`
// The call protocols supported by the application
Protocol *CallProtocol `json:"protocol"`
// Pass true to create a video call
IsVideo bool `json:"is_video"`
2021-12-30 05:55:02 +00:00
}
// Creates a new call
func (client *Client) CreateCall(req *CreateCallRequest) (*CallId, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createCall",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"protocol": req.Protocol,
"is_video": req.IsVideo,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalCallId(result.Data)
}
type AcceptCallRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// The call protocols supported by the application
Protocol *CallProtocol `json:"protocol"`
2021-12-30 05:55:02 +00:00
}
// Accepts an incoming call
func (client *Client) AcceptCall(req *AcceptCallRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "acceptCall",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"protocol": req.Protocol,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SendCallSignalingDataRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// The data
Data []byte `json:"data"`
2021-12-30 05:55:02 +00:00
}
// Sends call signaling data
func (client *Client) SendCallSignalingData(req *SendCallSignalingDataRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCallSignalingData",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"data": req.Data,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DiscardCallRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// Pass true if the user was disconnected
IsDisconnected bool `json:"is_disconnected"`
// The call duration, in seconds
Duration int32 `json:"duration"`
// Pass true if the call was a video call
IsVideo bool `json:"is_video"`
// Identifier of the connection used during the call
ConnectionId JsonInt64 `json:"connection_id"`
2021-12-30 05:55:02 +00:00
}
// Discards a call
func (client *Client) DiscardCall(req *DiscardCallRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "discardCall",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"is_disconnected": req.IsDisconnected,
"duration": req.Duration,
"is_video": req.IsVideo,
"connection_id": req.ConnectionId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
// List of the exact types of problems with the call, specified by the user
Problems []CallProblem `json:"problems"`
2021-12-30 05:55:02 +00:00
}
// Sends a call rating
func (client *Client) SendCallRating(req *SendCallRatingRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCallRating",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"rating": req.Rating,
"comment": req.Comment,
"problems": req.Problems,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2021-12-30 05:55:02 +00:00
}
2022-05-09 11:35:19 +00:00
// Sends debug information for a call to Telegram servers
2021-12-30 05:55:02 +00:00
func (client *Client) SendCallDebugInformation(req *SendCallDebugInformationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCallDebugInformation",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"debug_information": req.DebugInformation,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SendCallLogRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// Call log file. Only inputFileLocal and inputFileGenerated are supported
LogFile InputFile `json:"log_file"`
2022-05-09 11:35:19 +00:00
}
// Sends log file for a call to Telegram servers
func (client *Client) SendCallLog(req *SendCallLogRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCallLog",
},
Data: map[string]interface{}{
"call_id": req.CallId,
"log_file": req.LogFile,
},
})
if err != nil {
return nil, err
}
2022-05-09 11:35:19 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-05-09 11:35:19 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-05-09 11:35:19 +00:00
}
2023-03-26 09:37:06 +00:00
type GetVideoChatAvailableParticipantsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2021-12-30 05:55:02 +00:00
}
// Returns list of participant identifiers, on whose behalf a video chat in the chat can be joined
func (client *Client) GetVideoChatAvailableParticipants(req *GetVideoChatAvailableParticipantsRequest) (*MessageSenders, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getVideoChatAvailableParticipants",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageSenders(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SetVideoChatDefaultParticipantRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Default group call participant identifier to join the video chats
DefaultParticipantId MessageSender `json:"default_participant_id"`
2021-12-30 05:55:02 +00:00
}
// Changes default participant identifier, on whose behalf a video chat in the chat will be joined
func (client *Client) SetVideoChatDefaultParticipant(req *SetVideoChatDefaultParticipantRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setVideoChatDefaultParticipant",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"default_participant_id": req.DefaultParticipantId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type CreateVideoChatRequest struct {
// Identifier of a chat in which the video chat will be created
ChatId int64 `json:"chat_id"`
// Group call title; if empty, chat title will be used
Title string `json:"title"`
// Point in time (Unix timestamp) when the group call is supposed to be started by an administrator; 0 to start the video chat immediately. The date must be at least 10 seconds and at most 8 days in the future
StartDate int32 `json:"start_date"`
// Pass true to create an RTMP stream instead of an ordinary video chat; requires creator privileges
IsRtmpStream bool `json:"is_rtmp_stream"`
2021-12-30 05:55:02 +00:00
}
// Creates a video chat (a group call bound to a chat). Available only for basic groups, supergroups and channels; requires can_manage_video_chats rights
func (client *Client) CreateVideoChat(req *CreateVideoChatRequest) (*GroupCallId, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createVideoChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"title": req.Title,
"start_date": req.StartDate,
"is_rtmp_stream": req.IsRtmpStream,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalGroupCallId(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type GetVideoChatRtmpUrlRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2022-03-13 04:04:12 +00:00
}
// Returns RTMP URL for streaming to the chat; requires creator privileges
func (client *Client) GetVideoChatRtmpUrl(req *GetVideoChatRtmpUrlRequest) (*RtmpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getVideoChatRtmpUrl",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalRtmpUrl(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type ReplaceVideoChatRtmpUrlRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2022-03-13 04:04:12 +00:00
}
// Replaces the current RTMP URL for streaming to the chat; requires creator privileges
func (client *Client) ReplaceVideoChatRtmpUrl(req *ReplaceVideoChatRtmpUrlRequest) (*RtmpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "replaceVideoChatRtmpUrl",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalRtmpUrl(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type GetGroupCallRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2021-12-30 05:55:02 +00:00
}
// Returns information about a group call
func (client *Client) GetGroupCall(req *GetGroupCallRequest) (*GroupCall, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getGroupCall",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalGroupCall(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type StartScheduledGroupCallRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2021-12-30 05:55:02 +00:00
}
// Starts a scheduled group call
func (client *Client) StartScheduledGroupCall(req *StartScheduledGroupCallRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "startScheduledGroupCall",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleGroupCallEnabledStartNotificationRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// New value of the enabled_start_notification setting
EnabledStartNotification bool `json:"enabled_start_notification"`
2021-12-30 05:55:02 +00:00
}
// Toggles whether the current user will receive a notification when the group call will start; scheduled group calls only
func (client *Client) ToggleGroupCallEnabledStartNotification(req *ToggleGroupCallEnabledStartNotificationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallEnabledStartNotification",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"enabled_start_notification": req.EnabledStartNotification,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type JoinGroupCallRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Identifier of a group call participant, which will be used to join the call; pass null to join as self; video chats only
ParticipantId MessageSender `json:"participant_id"`
// Caller audio channel synchronization source identifier; received from tgcalls
AudioSourceId int32 `json:"audio_source_id"`
// Group call join payload; received from tgcalls
Payload string `json:"payload"`
// Pass true to join the call with muted microphone
IsMuted bool `json:"is_muted"`
// Pass true if the user's video is enabled
IsMyVideoEnabled bool `json:"is_my_video_enabled"`
// If non-empty, invite hash to be used to join the group call without being muted by administrators
InviteHash string `json:"invite_hash"`
2021-12-30 05:55:02 +00:00
}
// Joins an active group call. Returns join response payload for tgcalls
func (client *Client) JoinGroupCall(req *JoinGroupCallRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "joinGroupCall",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"participant_id": req.ParticipantId,
"audio_source_id": req.AudioSourceId,
"payload": req.Payload,
"is_muted": req.IsMuted,
"is_my_video_enabled": req.IsMyVideoEnabled,
"invite_hash": req.InviteHash,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type StartGroupCallScreenSharingRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Screen sharing audio channel synchronization source identifier; received from tgcalls
AudioSourceId int32 `json:"audio_source_id"`
// Group call join payload; received from tgcalls
Payload string `json:"payload"`
2021-12-30 05:55:02 +00:00
}
// Starts screen sharing in a joined group call. Returns join response payload for tgcalls
func (client *Client) StartGroupCallScreenSharing(req *StartGroupCallScreenSharingRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "startGroupCallScreenSharing",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"audio_source_id": req.AudioSourceId,
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type ToggleGroupCallScreenSharingIsPausedRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Pass true to pause screen sharing; pass false to unpause it
IsPaused bool `json:"is_paused"`
2021-12-30 05:55:02 +00:00
}
// Pauses or unpauses screen sharing in a joined group call
func (client *Client) ToggleGroupCallScreenSharingIsPaused(req *ToggleGroupCallScreenSharingIsPausedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallScreenSharingIsPaused",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"is_paused": req.IsPaused,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type EndGroupCallScreenSharingRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2021-12-30 05:55:02 +00:00
}
// Ends screen sharing in a joined group call
func (client *Client) EndGroupCallScreenSharing(req *EndGroupCallScreenSharingRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "endGroupCallScreenSharing",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type SetGroupCallTitleRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// New group call title; 1-64 characters
Title string `json:"title"`
2021-12-30 05:55:02 +00:00
}
// Sets group call title. Requires groupCall.can_be_managed group call flag
func (client *Client) SetGroupCallTitle(req *SetGroupCallTitleRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setGroupCallTitle",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"title": req.Title,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleGroupCallMuteNewParticipantsRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// New value of the mute_new_participants setting
MuteNewParticipants bool `json:"mute_new_participants"`
2021-12-30 05:55:02 +00:00
}
// Toggles whether new participants of a group call can be unmuted only by administrators of the group call. Requires groupCall.can_toggle_mute_new_participants group call flag
func (client *Client) ToggleGroupCallMuteNewParticipants(req *ToggleGroupCallMuteNewParticipantsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallMuteNewParticipants",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"mute_new_participants": req.MuteNewParticipants,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type InviteGroupCallParticipantsRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// User identifiers. At most 10 users can be invited simultaneously
UserIds []int64 `json:"user_ids"`
2021-12-30 05:55:02 +00:00
}
// Invites users to an active group call. Sends a service message of type messageInviteToGroupCall for video chats
func (client *Client) InviteGroupCallParticipants(req *InviteGroupCallParticipantsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "inviteGroupCallParticipants",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"user_ids": req.UserIds,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetGroupCallInviteLinkRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Pass true if the invite link needs to contain an invite hash, passing which to joinGroupCall would allow the invited user to unmute themselves. Requires groupCall.can_be_managed group call flag
CanSelfUnmute bool `json:"can_self_unmute"`
2021-12-30 05:55:02 +00:00
}
// Returns invite link to a video chat in a public chat
func (client *Client) GetGroupCallInviteLink(req *GetGroupCallInviteLinkRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getGroupCallInviteLink",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"can_self_unmute": req.CanSelfUnmute,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type RevokeGroupCallInviteLinkRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2021-12-30 05:55:02 +00:00
}
// Revokes invite link for a group call. Requires groupCall.can_be_managed group call flag
func (client *Client) RevokeGroupCallInviteLink(req *RevokeGroupCallInviteLinkRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "revokeGroupCallInviteLink",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type StartGroupCallRecordingRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Group call recording title; 0-64 characters
Title string `json:"title"`
// Pass true to record a video file instead of an audio file
RecordVideo bool `json:"record_video"`
// Pass true to use portrait orientation for video instead of landscape one
UsePortraitOrientation bool `json:"use_portrait_orientation"`
2021-12-30 05:55:02 +00:00
}
// Starts recording of an active group call. Requires groupCall.can_be_managed group call flag
func (client *Client) StartGroupCallRecording(req *StartGroupCallRecordingRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "startGroupCallRecording",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"title": req.Title,
"record_video": req.RecordVideo,
"use_portrait_orientation": req.UsePortraitOrientation,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type EndGroupCallRecordingRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2019-06-07 10:56:06 +00:00
}
2021-12-30 05:55:02 +00:00
// Ends recording of an active group call. Requires groupCall.can_be_managed group call flag
func (client *Client) EndGroupCallRecording(req *EndGroupCallRecordingRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "endGroupCallRecording",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleGroupCallIsMyVideoPausedRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Pass true if the current user's video is paused
IsMyVideoPaused bool `json:"is_my_video_paused"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether current user's video is paused
func (client *Client) ToggleGroupCallIsMyVideoPaused(req *ToggleGroupCallIsMyVideoPausedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallIsMyVideoPaused",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"is_my_video_paused": req.IsMyVideoPaused,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleGroupCallIsMyVideoEnabledRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Pass true if the current user's video is enabled
IsMyVideoEnabled bool `json:"is_my_video_enabled"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether current user's video is enabled
func (client *Client) ToggleGroupCallIsMyVideoEnabled(req *ToggleGroupCallIsMyVideoEnabledRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallIsMyVideoEnabled",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"is_my_video_enabled": req.IsMyVideoEnabled,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetGroupCallParticipantIsSpeakingRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Group call participant's synchronization audio source identifier, or 0 for the current user
AudioSource int32 `json:"audio_source"`
// Pass true if the user is speaking
IsSpeaking bool `json:"is_speaking"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Informs TDLib that speaking state of a participant of an active group has changed
func (client *Client) SetGroupCallParticipantIsSpeaking(req *SetGroupCallParticipantIsSpeakingRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setGroupCallParticipantIsSpeaking",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"audio_source": req.AudioSource,
"is_speaking": req.IsSpeaking,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleGroupCallParticipantIsMutedRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Participant identifier
ParticipantId MessageSender `json:"participant_id"`
2023-07-24 18:35:55 +00:00
// Pass true to mute the user; pass false to unmute them
2023-03-26 09:37:06 +00:00
IsMuted bool `json:"is_muted"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether a participant of an active group call is muted, unmuted, or allowed to unmute themselves
func (client *Client) ToggleGroupCallParticipantIsMuted(req *ToggleGroupCallParticipantIsMutedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallParticipantIsMuted",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"participant_id": req.ParticipantId,
"is_muted": req.IsMuted,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetGroupCallParticipantVolumeLevelRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Participant identifier
ParticipantId MessageSender `json:"participant_id"`
// New participant's volume level; 1-20000 in hundreds of percents
VolumeLevel int32 `json:"volume_level"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Changes volume level of a participant of an active group call. If the current user can manage the group call, then the participant's volume level will be changed for all users with the default volume level
func (client *Client) SetGroupCallParticipantVolumeLevel(req *SetGroupCallParticipantVolumeLevelRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setGroupCallParticipantVolumeLevel",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"participant_id": req.ParticipantId,
"volume_level": req.VolumeLevel,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleGroupCallParticipantIsHandRaisedRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Participant identifier
ParticipantId MessageSender `json:"participant_id"`
// Pass true if the user's hand needs to be raised. Only self hand can be raised. Requires groupCall.can_be_managed group call flag to lower other's hand
IsHandRaised bool `json:"is_hand_raised"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether a group call participant hand is rased
func (client *Client) ToggleGroupCallParticipantIsHandRaised(req *ToggleGroupCallParticipantIsHandRaisedRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleGroupCallParticipantIsHandRaised",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"participant_id": req.ParticipantId,
"is_hand_raised": req.IsHandRaised,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type LoadGroupCallParticipantsRequest struct {
// Group call identifier. The group call must be previously received through getGroupCall and must be joined or being joined
GroupCallId int32 `json:"group_call_id"`
// The maximum number of participants to load; up to 100
Limit int32 `json:"limit"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Loads more participants of a group call. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants have already been loaded
func (client *Client) LoadGroupCallParticipants(req *LoadGroupCallParticipantsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "loadGroupCallParticipants",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type LeaveGroupCallRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Leaves a group call
func (client *Client) LeaveGroupCall(req *LeaveGroupCallRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "leaveGroupCall",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type EndGroupCallRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Ends a group call. Requires groupCall.can_be_managed
func (client *Client) EndGroupCall(req *EndGroupCallRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "endGroupCall",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type GetGroupCallStreamsRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
2022-03-13 04:04:12 +00:00
}
// Returns information about available group call streams
func (client *Client) GetGroupCallStreams(req *GetGroupCallStreamsRequest) (*GroupCallStreams, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getGroupCallStreams",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalGroupCallStreams(result.Data)
}
type GetGroupCallStreamSegmentRequest struct {
// Group call identifier
GroupCallId int32 `json:"group_call_id"`
// Point in time when the stream segment begins; Unix timestamp in milliseconds
TimeOffset int64 `json:"time_offset"`
// Segment duration scale; 0-1. Segment's duration is 1000/(2**scale) milliseconds
Scale int32 `json:"scale"`
// Identifier of an audio/video channel to get as received from tgcalls
ChannelId int32 `json:"channel_id"`
// Video quality as received from tgcalls; pass null to get the worst available quality
VideoQuality GroupCallVideoQuality `json:"video_quality"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns a file with a segment of a group call stream in a modified OGG format for audio or MPEG-4 format for video
func (client *Client) GetGroupCallStreamSegment(req *GetGroupCallStreamSegmentRequest) (*FilePart, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getGroupCallStreamSegment",
},
Data: map[string]interface{}{
"group_call_id": req.GroupCallId,
"time_offset": req.TimeOffset,
"scale": req.Scale,
"channel_id": req.ChannelId,
"video_quality": req.VideoQuality,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFilePart(result.Data)
}
2023-08-15 18:28:13 +00:00
type SetMessageSenderBlockListRequest struct {
2023-03-26 09:37:06 +00:00
// Identifier of a message sender to block/unblock
SenderId MessageSender `json:"sender_id"`
2023-08-15 18:28:13 +00:00
// New block list for the message sender; pass null to unblock the message sender
BlockList BlockList `json:"block_list"`
2018-10-16 20:32:57 +00:00
}
2023-08-15 18:28:13 +00:00
// Changes the block list of a message sender. Currently, only users and supergroup chats can be blocked
func (client *Client) SetMessageSenderBlockList(req *SetMessageSenderBlockListRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
2023-08-15 18:28:13 +00:00
Type: "setMessageSenderBlockList",
2023-03-26 09:37:06 +00:00
},
Data: map[string]interface{}{
"sender_id": req.SenderId,
2023-08-15 18:28:13 +00:00
"block_list": req.BlockList,
2023-03-26 09:37:06 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type BlockMessageSenderFromRepliesRequest struct {
// The identifier of an incoming message in the Replies chat
MessageId int64 `json:"message_id"`
// Pass true to delete the message
DeleteMessage bool `json:"delete_message"`
// Pass true to delete all messages from the same sender
DeleteAllMessages bool `json:"delete_all_messages"`
// Pass true to report the sender to the Telegram moderators
ReportSpam bool `json:"report_spam"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Blocks an original sender of a message in the Replies chat
func (client *Client) BlockMessageSenderFromReplies(req *BlockMessageSenderFromRepliesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "blockMessageSenderFromReplies",
},
Data: map[string]interface{}{
"message_id": req.MessageId,
"delete_message": req.DeleteMessage,
"delete_all_messages": req.DeleteAllMessages,
"report_spam": req.ReportSpam,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetBlockedMessageSendersRequest struct {
2023-08-15 18:28:13 +00:00
// Block list from which to return users
BlockList BlockList `json:"block_list"`
2023-03-26 09:37:06 +00:00
// Number of users and chats to skip in the result; must be non-negative
Offset int32 `json:"offset"`
// The maximum number of users and chats to return; up to 100
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns users and chats that were blocked by the current user
func (client *Client) GetBlockedMessageSenders(req *GetBlockedMessageSendersRequest) (*MessageSenders, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBlockedMessageSenders",
},
Data: map[string]interface{}{
2023-08-15 18:28:13 +00:00
"block_list": req.BlockList,
2023-03-26 09:37:06 +00:00
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageSenders(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type AddContactRequest struct {
// The contact to add or edit; phone number may be empty and needs to be specified only if known, vCard is ignored
Contact *Contact `json:"contact"`
// Pass true to share the current user's phone number with the new contact. A corresponding rule to userPrivacySettingShowPhoneNumber will be added if needed. Use the field userFullInfo.need_phone_number_privacy_exception to check whether the current user needs to be asked to share their phone number
SharePhoneNumber bool `json:"share_phone_number"`
2020-02-03 12:56:20 +00:00
}
// Adds a user to the contact list or edits an existing contact by their user identifier
func (client *Client) AddContact(req *AddContactRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addContact",
},
Data: map[string]interface{}{
"contact": req.Contact,
"share_phone_number": req.SharePhoneNumber,
},
})
if err != nil {
return nil, err
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-02-03 12:56:20 +00:00
}
2023-03-26 09:37:06 +00:00
type ImportContactsRequest struct {
// The list of contacts to import or edit; contacts' vCard are ignored and are not imported
Contacts []*Contact `json:"contacts"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Adds new contacts or edits existing contacts by their phone numbers; contacts' user identifiers are ignored
2018-10-16 20:32:57 +00:00
func (client *Client) ImportContacts(req *ImportContactsRequest) (*ImportedContacts, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "importContacts",
},
Data: map[string]interface{}{
"contacts": req.Contacts,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalImportedContacts(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns all contacts of the user
2018-09-05 21:45:29 +00:00
func (client *Client) GetContacts() (*Users, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getContacts",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUsers(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchContactsRequest struct {
// Query to search for; may be empty to return all contacts
Query string `json:"query"`
// The maximum number of users to be returned
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for the specified query in the first names, last names and usernames of the known user contacts
2018-10-16 20:32:57 +00:00
func (client *Client) SearchContacts(req *SearchContactsRequest) (*Users, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchContacts",
},
Data: map[string]interface{}{
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUsers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveContactsRequest struct {
// Identifiers of users to be deleted
UserIds []int64 `json:"user_ids"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Removes users from the contact list
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveContacts(req *RemoveContactsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeContacts",
},
Data: map[string]interface{}{
"user_ids": req.UserIds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns the total number of imported contacts
func (client *Client) GetImportedContactCount() (*Count, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getImportedContactCount",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalCount(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ChangeImportedContactsRequest struct {
// The new list of contacts, contact's vCard are ignored and are not imported
Contacts []*Contact `json:"contacts"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Changes imported contacts using the list of 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
2018-10-16 20:32:57 +00:00
func (client *Client) ChangeImportedContacts(req *ChangeImportedContactsRequest) (*ImportedContacts, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "changeImportedContacts",
},
Data: map[string]interface{}{
"contacts": req.Contacts,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalImportedContacts(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
// Clears all imported contacts, contact list remains unchanged
2018-08-30 14:55:42 +00:00
func (client *Client) ClearImportedContacts() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearImportedContacts",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
type SetCloseFriendsRequest struct {
// User identifiers of close friends; the users must be contacts of the current user
UserIds []int64 `json:"user_ids"`
}
// Changes the list of close friends of the current user
func (client *Client) SetCloseFriends(req *SetCloseFriendsRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setCloseFriends",
},
Data: map[string]interface{}{
"user_ids": req.UserIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns all close friends of the current user
func (client *Client) GetCloseFriends() (*Users, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getCloseFriends",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUsers(result.Data)
}
2023-03-26 09:37:06 +00:00
type SetUserPersonalProfilePhotoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// Profile photo to set; pass null to delete the photo; inputChatPhotoPrevious isn't supported in this function
Photo InputChatPhoto `json:"photo"`
2022-12-30 18:28:59 +00:00
}
// Changes a personal profile photo of a contact user
func (client *Client) SetUserPersonalProfilePhoto(req *SetUserPersonalProfilePhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setUserPersonalProfilePhoto",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"photo": req.Photo,
},
})
if err != nil {
return nil, err
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-30 18:28:59 +00:00
}
2023-03-26 09:37:06 +00:00
type SuggestUserProfilePhotoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// Profile photo to suggest; inputChatPhotoPrevious isn't supported in this function
Photo InputChatPhoto `json:"photo"`
2022-12-30 18:28:59 +00:00
}
// Suggests a profile photo to another regular user with common messages
func (client *Client) SuggestUserProfilePhoto(req *SuggestUserProfilePhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "suggestUserProfilePhoto",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"photo": req.Photo,
},
})
if err != nil {
return nil, err
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-30 18:28:59 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchUserByPhoneNumberRequest struct {
// Phone number to search for
PhoneNumber string `json:"phone_number"`
2018-08-30 14:55:42 +00:00
}
2022-05-09 11:35:19 +00:00
// Searches a user by their phone number. Returns a 404 error if the user can't be found
2022-03-13 04:04:12 +00:00
func (client *Client) SearchUserByPhoneNumber(req *SearchUserByPhoneNumberRequest) (*User, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchUserByPhoneNumber",
},
Data: map[string]interface{}{
"phone_number": req.PhoneNumber,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUser(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type SharePhoneNumberRequest struct {
// Identifier of the user with whom to share the phone number. The user must be a mutual contact
UserId int64 `json:"user_id"`
2020-02-03 12:56:20 +00:00
}
// Shares the phone number of the current user with a mutual contact. Supposed to be called when the user clicks on chatActionBarSharePhoneNumber
func (client *Client) SharePhoneNumber(req *SharePhoneNumberRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sharePhoneNumber",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetUserProfilePhotosRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// The number of photos to skip; must be non-negative
Offset int32 `json:"offset"`
// The maximum number of photos to be returned; up to 100
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2022-12-30 18:28:59 +00:00
// Returns the profile photos of a user. Personal and public photo aren't returned
2020-11-30 09:33:47 +00:00
func (client *Client) GetUserProfilePhotos(req *GetUserProfilePhotosRequest) (*ChatPhotos, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUserProfilePhotos",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatPhotos(result.Data)
}
type GetStickersRequest struct {
// Type of the stickers to return
StickerType StickerType `json:"sticker_type"`
// Search query; a space-separated list of emoji or a keyword prefix. If empty, returns all known installed stickers
Query string `json:"query"`
// The maximum number of stickers to be returned
Limit int32 `json:"limit"`
// Chat identifier for which to return stickers. Available custom emoji stickers may be different for different chats
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2023-02-04 22:54:46 +00:00
// Returns stickers from the installed sticker sets that correspond to any of the given emoji or can be found by sticker-specific keywords. If the query is non-empty, then favorite, recently used or trending stickers may also be returned
2018-10-16 20:32:57 +00:00
func (client *Client) GetStickers(req *GetStickersRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStickers",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"query": req.Query,
"limit": req.Limit,
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickers(result.Data)
}
2023-09-16 07:09:40 +00:00
type GetAllStickerEmojisRequest struct {
// Type of the stickers to search for
StickerType StickerType `json:"sticker_type"`
// Search query
Query string `json:"query"`
// Chat identifier for which to find stickers
ChatId int64 `json:"chat_id"`
// Pass true if only main emoji for each found sticker must be included in the result
ReturnOnlyMainEmoji bool `json:"return_only_main_emoji"`
}
// Returns unique emoji that correspond to stickers to be found by the getStickers(sticker_type, query, 1000000, chat_id)
func (client *Client) GetAllStickerEmojis(req *GetAllStickerEmojisRequest) (*Emojis, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getAllStickerEmojis",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"query": req.Query,
"chat_id": req.ChatId,
"return_only_main_emoji": req.ReturnOnlyMainEmoji,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmojis(result.Data)
}
2023-03-26 09:37:06 +00:00
type SearchStickersRequest struct {
// Type of the stickers to return
StickerType StickerType `json:"sticker_type"`
// Space-separated list of emoji to search for; must be non-empty
Emojis string `json:"emojis"`
// The maximum number of stickers to be returned; 0-100
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2023-02-04 22:54:46 +00:00
// Searches for stickers from public sticker sets that correspond to any of the given emoji
2018-10-16 20:32:57 +00:00
func (client *Client) SearchStickers(req *SearchStickersRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchStickers",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"emojis": req.Emojis,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPremiumStickersRequest struct {
// The maximum number of stickers to be returned; 0-100
Limit int32 `json:"limit"`
2022-08-13 15:24:07 +00:00
}
// Returns premium stickers from regular sticker sets
func (client *Client) GetPremiumStickers(req *GetPremiumStickersRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPremiumStickers",
},
Data: map[string]interface{}{
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2022-08-13 15:24:07 +00:00
}
2023-03-26 09:37:06 +00:00
type GetInstalledStickerSetsRequest struct {
// Type of the sticker sets to return
StickerType StickerType `json:"sticker_type"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a list of installed sticker sets
2018-10-16 20:32:57 +00:00
func (client *Client) GetInstalledStickerSets(req *GetInstalledStickerSetsRequest) (*StickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInstalledStickerSets",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickerSets(result.Data)
}
type GetArchivedStickerSetsRequest struct {
// Type of the sticker sets to return
StickerType StickerType `json:"sticker_type"`
// Identifier of the sticker set from which to return the result
OffsetStickerSetId JsonInt64 `json:"offset_sticker_set_id"`
// The maximum number of sticker sets to return; up to 100
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a list of archived sticker sets
2018-10-16 20:32:57 +00:00
func (client *Client) GetArchivedStickerSets(req *GetArchivedStickerSetsRequest) (*StickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getArchivedStickerSets",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"offset_sticker_set_id": req.OffsetStickerSetId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickerSets(result.Data)
}
type GetTrendingStickerSetsRequest struct {
// Type of the sticker sets to return
StickerType StickerType `json:"sticker_type"`
// The offset from which to return the sticker sets; must be non-negative
Offset int32 `json:"offset"`
// The maximum number of sticker sets to be returned; up to 100. For optimal performance, the number of returned sticker sets is chosen by TDLib and can be smaller than the specified limit, even if the end of the list has not been reached
Limit int32 `json:"limit"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns a list of trending sticker sets. For optimal performance, the number of returned sticker sets is chosen by TDLib
2022-06-21 18:10:07 +00:00
func (client *Client) GetTrendingStickerSets(req *GetTrendingStickerSetsRequest) (*TrendingStickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getTrendingStickerSets",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTrendingStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetAttachedStickerSetsRequest struct {
// File identifier
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2022-12-30 18:28:59 +00:00
// Returns a list of sticker sets attached to a file, including regular, mask, and emoji sticker sets. Currently, only animations, photos, and videos can have attached sticker sets
2018-10-16 20:32:57 +00:00
func (client *Client) GetAttachedStickerSets(req *GetAttachedStickerSetsRequest) (*StickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAttachedStickerSets",
},
Data: map[string]interface{}{
"file_id": req.FileId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetStickerSetRequest struct {
// Identifier of the sticker set
SetId JsonInt64 `json:"set_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a sticker set by its identifier
2018-10-16 20:32:57 +00:00
func (client *Client) GetStickerSet(req *GetStickerSetRequest) (*StickerSet, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStickerSet",
},
Data: map[string]interface{}{
"set_id": req.SetId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickerSet(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchStickerSetRequest struct {
// Name of the sticker set
Name string `json:"name"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for a sticker set by its name
2018-10-16 20:32:57 +00:00
func (client *Client) SearchStickerSet(req *SearchStickerSetRequest) (*StickerSet, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchStickerSet",
},
Data: map[string]interface{}{
"name": req.Name,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickerSet(result.Data)
}
type SearchInstalledStickerSetsRequest struct {
// Type of the sticker sets to search for
StickerType StickerType `json:"sticker_type"`
// Query to search for
Query string `json:"query"`
// The maximum number of sticker sets to return
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for installed sticker sets by looking for specified query in their title and name
2018-10-16 20:32:57 +00:00
func (client *Client) SearchInstalledStickerSets(req *SearchInstalledStickerSetsRequest) (*StickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchInstalledStickerSets",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchStickerSetsRequest struct {
// Query to search for
Query string `json:"query"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for ordinary sticker sets by looking for specified query in their title and name. Excludes installed sticker sets from the results
2018-10-16 20:32:57 +00:00
func (client *Client) SearchStickerSets(req *SearchStickerSetsRequest) (*StickerSets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchStickerSets",
},
Data: map[string]interface{}{
"query": req.Query,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Installs/uninstalls or activates/archives a sticker set
2018-10-16 20:32:57 +00:00
func (client *Client) ChangeStickerSet(req *ChangeStickerSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "changeStickerSet",
},
Data: map[string]interface{}{
"set_id": req.SetId,
"is_installed": req.IsInstalled,
"is_archived": req.IsArchived,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ViewTrendingStickerSetsRequest struct {
// Identifiers of viewed trending sticker sets
StickerSetIds []JsonInt64 `json:"sticker_set_ids"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Informs the server that some trending sticker sets have been viewed by the user
2018-10-16 20:32:57 +00:00
func (client *Client) ViewTrendingStickerSets(req *ViewTrendingStickerSetsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "viewTrendingStickerSets",
},
Data: map[string]interface{}{
"sticker_set_ids": req.StickerSetIds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ReorderInstalledStickerSetsRequest struct {
// Type of the sticker sets to reorder
StickerType StickerType `json:"sticker_type"`
// Identifiers of installed sticker sets in the new correct order
StickerSetIds []JsonInt64 `json:"sticker_set_ids"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the order of installed sticker sets
2018-10-16 20:32:57 +00:00
func (client *Client) ReorderInstalledStickerSets(req *ReorderInstalledStickerSetsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reorderInstalledStickerSets",
},
Data: map[string]interface{}{
"sticker_type": req.StickerType,
"sticker_set_ids": req.StickerSetIds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a list of recently used stickers
2018-10-16 20:32:57 +00:00
func (client *Client) GetRecentStickers(req *GetRecentStickersRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecentStickers",
},
Data: map[string]interface{}{
"is_attached": req.IsAttached,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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. Emoji stickers can't be added to recent stickers
2018-10-16 20:32:57 +00:00
func (client *Client) AddRecentSticker(req *AddRecentStickerRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addRecentSticker",
},
Data: map[string]interface{}{
"is_attached": req.IsAttached,
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a sticker from the list of recently used stickers
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveRecentSticker(req *RemoveRecentStickerRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeRecentSticker",
},
Data: map[string]interface{}{
"is_attached": req.IsAttached,
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Clears the list of recently used stickers
2018-10-16 20:32:57 +00:00
func (client *Client) ClearRecentStickers(req *ClearRecentStickersRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearRecentStickers",
},
Data: map[string]interface{}{
"is_attached": req.IsAttached,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns favorite stickers
func (client *Client) GetFavoriteStickers() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getFavoriteStickers",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type AddFavoriteStickerRequest struct {
// Sticker file to add
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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. Emoji stickers can't be added to favorite stickers
2018-10-16 20:32:57 +00:00
func (client *Client) AddFavoriteSticker(req *AddFavoriteStickerRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addFavoriteSticker",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveFavoriteStickerRequest struct {
// Sticker file to delete from the list
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a sticker from the list of favorite stickers
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveFavoriteSticker(req *RemoveFavoriteStickerRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeFavoriteSticker",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetStickerEmojisRequest struct {
// Sticker file identifier
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Returns emoji corresponding to a sticker. The list is only for informational purposes, because a sticker is always sent with a fixed emoji from the corresponding Sticker object
func (client *Client) GetStickerEmojis(req *GetStickerEmojisRequest) (*Emojis, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStickerEmojis",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmojis(result.Data)
}
type SearchEmojisRequest struct {
// Text to search for
Text string `json:"text"`
// Pass true if only emojis, which exactly match the text, needs to be returned
ExactMatch bool `json:"exact_match"`
// List of possible IETF language tags of the user's input language; may be empty if unknown
InputLanguageCodes []string `json:"input_language_codes"`
2019-09-10 12:36:54 +00:00
}
// Searches for emojis by keywords. Supported only if the file database is enabled
func (client *Client) SearchEmojis(req *SearchEmojisRequest) (*Emojis, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchEmojis",
},
Data: map[string]interface{}{
"text": req.Text,
"exact_match": req.ExactMatch,
"input_language_codes": req.InputLanguageCodes,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojis(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type GetEmojiCategoriesRequest struct {
// Type of emoji categories to return; pass null to get default emoji categories
Type EmojiCategoryType `json:"type"`
2023-02-04 22:54:46 +00:00
}
// Returns available emojis categories
func (client *Client) GetEmojiCategories(req *GetEmojiCategoriesRequest) (*EmojiCategories, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getEmojiCategories",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmojiCategories(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-03-26 09:37:06 +00:00
type GetAnimatedEmojiRequest struct {
// The emoji
Emoji string `json:"emoji"`
2021-12-30 05:55:02 +00:00
}
// Returns an animated emoji corresponding to a given emoji. Returns a 404 error if the emoji has no animated emoji
func (client *Client) GetAnimatedEmoji(req *GetAnimatedEmojiRequest) (*AnimatedEmoji, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAnimatedEmoji",
},
Data: map[string]interface{}{
"emoji": req.Emoji,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAnimatedEmoji(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetEmojiSuggestionsUrlRequest struct {
// Language code for which the emoji replacements will be suggested
LanguageCode string `json:"language_code"`
2022-08-13 15:24:07 +00:00
}
// Returns an HTTP URL which can be used to automatically log in to the translation platform and suggest new emoji replacements. The URL will be valid for 30 seconds after generation
func (client *Client) GetEmojiSuggestionsUrl(req *GetEmojiSuggestionsUrlRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getEmojiSuggestionsUrl",
},
Data: map[string]interface{}{
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type GetCustomEmojiStickersRequest struct {
// Identifiers of custom emoji stickers. At most 200 custom emoji stickers can be received simultaneously
CustomEmojiIds []JsonInt64 `json:"custom_emoji_ids"`
2019-09-10 12:36:54 +00:00
}
2022-08-13 15:24:07 +00:00
// Returns list of custom emoji stickers by their identifiers. Stickers are returned in arbitrary order. Only found stickers are returned
func (client *Client) GetCustomEmojiStickers(req *GetCustomEmojiStickersRequest) (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCustomEmojiStickers",
},
Data: map[string]interface{}{
"custom_emoji_ids": req.CustomEmojiIds,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-02-04 22:54:46 +00:00
// Returns default list of custom emoji stickers for placing on a chat photo
func (client *Client) GetDefaultChatPhotoCustomEmojiStickers() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDefaultChatPhotoCustomEmojiStickers",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2023-02-04 22:54:46 +00:00
}
// Returns default list of custom emoji stickers for placing on a profile photo
func (client *Client) GetDefaultProfilePhotoCustomEmojiStickers() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDefaultProfilePhotoCustomEmojiStickers",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2023-02-04 22:54:46 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns saved animations
func (client *Client) GetSavedAnimations() (*Animations, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSavedAnimations",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAnimations(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) AddSavedAnimation(req *AddSavedAnimationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addSavedAnimation",
},
Data: map[string]interface{}{
"animation": req.Animation,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveSavedAnimationRequest struct {
// Animation file to be removed
Animation InputFile `json:"animation"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes an animation from the list of saved animations
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveSavedAnimation(req *RemoveSavedAnimationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeSavedAnimation",
},
Data: map[string]interface{}{
"animation": req.Animation,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns up to 20 recently used inline bots in the order of their last usage
func (client *Client) GetRecentInlineBots() (*Users, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecentInlineBots",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUsers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchHashtagsRequest struct {
// Hashtag prefix to search for
Prefix string `json:"prefix"`
// The maximum number of hashtags to be returned
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for recently used hashtags by their prefix
2018-10-16 20:32:57 +00:00
func (client *Client) SearchHashtags(req *SearchHashtagsRequest) (*Hashtags, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchHashtags",
},
Data: map[string]interface{}{
"prefix": req.Prefix,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHashtags(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveRecentHashtagRequest struct {
// Hashtag to delete
Hashtag string `json:"hashtag"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a hashtag from the list of recently used hashtags
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveRecentHashtag(req *RemoveRecentHashtagRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeRecentHashtag",
},
Data: map[string]interface{}{
"hashtag": req.Hashtag,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetWebPagePreviewRequest struct {
// Message text with formatting
Text *FormattedText `json:"text"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetWebPagePreview(req *GetWebPagePreviewRequest) (*WebPage, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getWebPagePreview",
},
Data: map[string]interface{}{
"text": req.Text,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalWebPage(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetWebPageInstantViewRequest struct {
// The web page URL
Url string `json:"url"`
// Pass true to get full instant view for the web page
ForceFull bool `json:"force_full"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns an instant view version of a web page if available. Returns a 404 error if the web page has no instant view page
2018-10-16 20:32:57 +00:00
func (client *Client) GetWebPageInstantView(req *GetWebPageInstantViewRequest) (*WebPageInstantView, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getWebPageInstantView",
},
Data: map[string]interface{}{
"url": req.Url,
"force_full": req.ForceFull,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalWebPageInstantView(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetProfilePhotoRequest struct {
// Profile photo to set
Photo InputChatPhoto `json:"photo"`
// Pass true to set a public photo, which will be visible even the main photo is hidden by privacy settings
IsPublic bool `json:"is_public"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Changes a profile photo for the current user
2018-10-16 20:32:57 +00:00
func (client *Client) SetProfilePhoto(req *SetProfilePhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setProfilePhoto",
},
Data: map[string]interface{}{
"photo": req.Photo,
"is_public": req.IsPublic,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteProfilePhotoRequest struct {
// Identifier of the profile photo to delete
ProfilePhotoId JsonInt64 `json:"profile_photo_id"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Deletes a profile photo
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteProfilePhoto(req *DeleteProfilePhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteProfilePhoto",
},
Data: map[string]interface{}{
"profile_photo_id": req.ProfilePhotoId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetNameRequest struct {
// The new value of the first name for the current user; 1-64 characters
FirstName string `json:"first_name"`
// The new value of the optional last name for the current user; 0-64 characters
LastName string `json:"last_name"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Changes the first and last name of the current user
2018-10-16 20:32:57 +00:00
func (client *Client) SetName(req *SetNameRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setName",
},
Data: map[string]interface{}{
"first_name": req.FirstName,
"last_name": req.LastName,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetBioRequest struct {
// The new value of the user bio; 0-getOption("bio_length_max") characters without line feeds
Bio string `json:"bio"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the bio of the current user
2018-10-16 20:32:57 +00:00
func (client *Client) SetBio(req *SetBioRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setBio",
},
Data: map[string]interface{}{
"bio": req.Bio,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetUsernameRequest struct {
// The new value of the username. Use an empty string to remove the username. The username can't be completely removed if there is another active or disabled username
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2022-11-07 18:50:52 +00:00
// Changes the editable username of the current user
2018-10-16 20:32:57 +00:00
func (client *Client) SetUsername(req *SetUsernameRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setUsername",
},
Data: map[string]interface{}{
"username": req.Username,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleUsernameIsActiveRequest struct {
// The username to change
Username string `json:"username"`
// Pass true to activate the username; pass false to disable it
IsActive bool `json:"is_active"`
2022-11-07 18:50:52 +00:00
}
// Changes active state for a username of the current user. The editable username can't be disabled. May return an error with a message "USERNAMES_ACTIVE_TOO_MUCH" if the maximum number of active usernames has been reached
func (client *Client) ToggleUsernameIsActive(req *ToggleUsernameIsActiveRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleUsernameIsActive",
},
Data: map[string]interface{}{
"username": req.Username,
"is_active": req.IsActive,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type ReorderActiveUsernamesRequest struct {
// The new order of active usernames. All currently active usernames must be specified
Usernames []string `json:"usernames"`
2022-11-07 18:50:52 +00:00
}
// Changes order of active usernames of the current user
func (client *Client) ReorderActiveUsernames(req *ReorderActiveUsernamesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reorderActiveUsernames",
},
Data: map[string]interface{}{
"usernames": req.Usernames,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type SetEmojiStatusRequest struct {
// New emoji status; pass null to switch to the default badge
EmojiStatus *EmojiStatus `json:"emoji_status"`
2022-09-18 01:34:29 +00:00
}
// Changes the emoji status of the current user; for Telegram Premium users only
func (client *Client) SetEmojiStatus(req *SetEmojiStatusRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setEmojiStatus",
},
Data: map[string]interface{}{
"emoji_status": req.EmojiStatus,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SetLocationRequest struct {
// The new location of the user
Location *Location `json:"location"`
2020-11-30 09:33:47 +00:00
}
2022-12-07 20:04:16 +00:00
// Changes the location of the current user. Needs to be called if getOption("is_location_visible") is true and location changes for more than 1 kilometer
2020-11-30 09:33:47 +00:00
func (client *Client) SetLocation(req *SetLocationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setLocation",
},
Data: map[string]interface{}{
"location": req.Location,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type ChangePhoneNumberRequest struct {
// The new 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"`
2018-10-16 20:32:57 +00:00
}
2023-07-24 18:35:55 +00:00
// Changes the phone number of the user and sends an authentication code to the user's new phone number; for official Android and iOS applications only. On success, returns information about the sent code
2018-10-16 20:32:57 +00:00
func (client *Client) ChangePhoneNumber(req *ChangePhoneNumberRequest) (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "changePhoneNumber",
},
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 UnmarshalAuthenticationCodeInfo(result.Data)
2021-12-30 05:55:02 +00:00
}
2022-09-18 01:34:29 +00:00
// Resends the authentication code sent to confirm a new phone number for the current user. Works only if the previously received authenticationCodeInfo next_code_type was not null and the server-specified timeout has passed
2021-12-30 05:55:02 +00:00
func (client *Client) ResendChangePhoneNumberCode() (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendChangePhoneNumberCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckChangePhoneNumberCodeRequest struct {
// Authentication code to check
Code string `json:"code"`
2021-12-30 05:55:02 +00:00
}
// Checks the authentication code sent to confirm a new phone number of the user
func (client *Client) CheckChangePhoneNumberCode(req *CheckChangePhoneNumberCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkChangePhoneNumberCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2022-12-07 20:04:16 +00:00
// Returns an HTTPS link, which can be used to get information about the current user
func (client *Client) GetUserLink() (*UserLink, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUserLink",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUserLink(result.Data)
2022-12-07 20:04:16 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchUserByTokenRequest struct {
// Token to search for
Token string `json:"token"`
2022-12-07 20:04:16 +00:00
}
// Searches a user by a token from the user's link
func (client *Client) SearchUserByToken(req *SearchUserByTokenRequest) (*User, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchUserByToken",
},
Data: map[string]interface{}{
"token": req.Token,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUser(result.Data)
}
type SetCommandsRequest struct {
// The scope to which the commands are relevant; pass null to change commands in the default bot command scope
Scope BotCommandScope `json:"scope"`
// A two-letter ISO 639-1 language code. If empty, the commands will be applied to all users from the given scope, for which language there are no dedicated commands
LanguageCode string `json:"language_code"`
// List of the bot's commands
Commands []*BotCommand `json:"commands"`
2021-12-30 05:55:02 +00:00
}
// Sets the list of commands supported by the bot for the given user scope and language; for bots only
func (client *Client) SetCommands(req *SetCommandsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setCommands",
},
Data: map[string]interface{}{
"scope": req.Scope,
"language_code": req.LanguageCode,
"commands": req.Commands,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DeleteCommandsRequest struct {
// The scope to which the commands are relevant; pass null to delete commands in the default bot command scope
Scope BotCommandScope `json:"scope"`
// A two-letter ISO 639-1 language code or an empty string
LanguageCode string `json:"language_code"`
2021-12-30 05:55:02 +00:00
}
// Deletes commands supported by the bot for the given user scope and language; for bots only
func (client *Client) DeleteCommands(req *DeleteCommandsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteCommands",
},
Data: map[string]interface{}{
"scope": req.Scope,
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type GetCommandsRequest struct {
// The scope to which the commands are relevant; pass null to get commands in the default bot command scope
Scope BotCommandScope `json:"scope"`
// A two-letter ISO 639-1 language code or an empty string
LanguageCode string `json:"language_code"`
2021-12-30 05:55:02 +00:00
}
2023-02-04 22:54:46 +00:00
// Returns list of commands supported by the bot for the given user scope and language; for bots only
2021-12-30 05:55:02 +00:00
func (client *Client) GetCommands(req *GetCommandsRequest) (*BotCommands, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCommands",
},
Data: map[string]interface{}{
"scope": req.Scope,
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBotCommands(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetMenuButtonRequest struct {
// Identifier of the user or 0 to set menu button for all users
UserId int64 `json:"user_id"`
// New menu button
MenuButton *BotMenuButton `json:"menu_button"`
2022-04-24 20:33:39 +00:00
}
// Sets menu button for the given user or for all users; for bots only
func (client *Client) SetMenuButton(req *SetMenuButtonRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setMenuButton",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"menu_button": req.MenuButton,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-03-26 09:37:06 +00:00
type GetMenuButtonRequest struct {
// Identifier of the user or 0 to get the default menu button
UserId int64 `json:"user_id"`
2022-04-24 20:33:39 +00:00
}
// Returns menu button set by the bot for the given user; for bots only
func (client *Client) GetMenuButton(req *GetMenuButtonRequest) (*BotMenuButton, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMenuButton",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBotMenuButton(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-03-26 09:37:06 +00:00
type SetDefaultGroupAdministratorRightsRequest struct {
2023-08-15 18:28:13 +00:00
// Default administrator rights for adding the bot to basic group and supergroup chats; pass null to remove default rights
2023-03-26 09:37:06 +00:00
DefaultGroupAdministratorRights *ChatAdministratorRights `json:"default_group_administrator_rights"`
2022-04-24 20:33:39 +00:00
}
// Sets default administrator rights for adding the bot to basic group and supergroup chats; for bots only
func (client *Client) SetDefaultGroupAdministratorRights(req *SetDefaultGroupAdministratorRightsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setDefaultGroupAdministratorRights",
},
Data: map[string]interface{}{
"default_group_administrator_rights": req.DefaultGroupAdministratorRights,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-03-26 09:37:06 +00:00
type SetDefaultChannelAdministratorRightsRequest struct {
2023-08-15 18:28:13 +00:00
// Default administrator rights for adding the bot to channels; pass null to remove default rights
2023-03-26 09:37:06 +00:00
DefaultChannelAdministratorRights *ChatAdministratorRights `json:"default_channel_administrator_rights"`
2022-04-24 20:33:39 +00:00
}
// Sets default administrator rights for adding the bot to channel chats; for bots only
func (client *Client) SetDefaultChannelAdministratorRights(req *SetDefaultChannelAdministratorRightsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setDefaultChannelAdministratorRights",
},
Data: map[string]interface{}{
"default_channel_administrator_rights": req.DefaultChannelAdministratorRights,
},
})
if err != nil {
return nil, err
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-04-24 20:33:39 +00:00
}
2023-09-16 07:09:40 +00:00
type CanBotSendMessagesRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
}
// Checks whether the specified bot can send messages to the user. Returns a 404 error if can't and the access can be granted by call to allowBotToSendMessages
func (client *Client) CanBotSendMessages(req *CanBotSendMessagesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "canBotSendMessages",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AllowBotToSendMessagesRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
}
// Allows the specified bot to send messages to the user
func (client *Client) AllowBotToSendMessages(req *AllowBotToSendMessagesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "allowBotToSendMessages",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SendWebAppCustomRequestRequest struct {
// Identifier of the bot
BotUserId int64 `json:"bot_user_id"`
// The method name
Method string `json:"method"`
// JSON-serialized method parameters
Parameters string `json:"parameters"`
}
// Sends a custom request from a Web App
func (client *Client) SendWebAppCustomRequest(req *SendWebAppCustomRequestRequest) (*CustomRequestResult, error) {
result, err := client.Send(Request{
meta: meta{
Type: "sendWebAppCustomRequest",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"method": req.Method,
"parameters": req.Parameters,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalCustomRequestResult(result.Data)
}
2023-07-24 18:35:55 +00:00
type SetBotNameRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose languages there is no dedicated name
LanguageCode string `json:"language_code"`
// New bot's name on the specified language; 0-64 characters; must be non-empty if language code is empty
Name string `json:"name"`
}
// Sets the name of a bot. Can be called only if userTypeBot.can_be_edited == true
func (client *Client) SetBotName(req *SetBotNameRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setBotName",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"language_code": req.LanguageCode,
"name": req.Name,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetBotNameRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// A two-letter ISO 639-1 language code or an empty string
LanguageCode string `json:"language_code"`
}
// Returns the name of a bot in the given language. Can be called only if userTypeBot.can_be_edited == true
func (client *Client) GetBotName(req *GetBotNameRequest) (*Text, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getBotName",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type SetBotProfilePhotoRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// Profile photo to set; pass null to delete the chat photo
Photo InputChatPhoto `json:"photo"`
}
// Changes a profile photo for a bot
func (client *Client) SetBotProfilePhoto(req *SetBotProfilePhotoRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setBotProfilePhoto",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"photo": req.Photo,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleBotUsernameIsActiveRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// The username to change
Username string `json:"username"`
// Pass true to activate the username; pass false to disable it
IsActive bool `json:"is_active"`
}
// Changes active state for a username of a bot. The editable username can't be disabled. May return an error with a message "USERNAMES_ACTIVE_TOO_MUCH" if the maximum number of active usernames has been reached. Can be called only if userTypeBot.can_be_edited == true
func (client *Client) ToggleBotUsernameIsActive(req *ToggleBotUsernameIsActiveRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "toggleBotUsernameIsActive",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"username": req.Username,
"is_active": req.IsActive,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ReorderBotActiveUsernamesRequest struct {
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// The new order of active usernames. All currently active usernames must be specified
Usernames []string `json:"usernames"`
}
// Changes order of active usernames of a bot. Can be called only if userTypeBot.can_be_edited == true
func (client *Client) ReorderBotActiveUsernames(req *ReorderBotActiveUsernamesRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "reorderBotActiveUsernames",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"usernames": req.Usernames,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-03-26 09:37:06 +00:00
type SetBotInfoDescriptionRequest struct {
2023-07-24 18:35:55 +00:00
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// A two-letter ISO 639-1 language code. If empty, the description will be shown to all users for whose languages there is no dedicated description
2023-03-26 09:37:06 +00:00
LanguageCode string `json:"language_code"`
// New bot's description on the specified language
Description string `json:"description"`
2023-03-11 11:13:56 +00:00
}
2023-07-24 18:35:55 +00:00
// Sets the text shown in the chat with a bot if the chat is empty. Can be called only if userTypeBot.can_be_edited == true
2023-03-11 11:13:56 +00:00
func (client *Client) SetBotInfoDescription(req *SetBotInfoDescriptionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setBotInfoDescription",
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"bot_user_id": req.BotUserId,
2023-03-26 09:37:06 +00:00
"language_code": req.LanguageCode,
"description": req.Description,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBotInfoDescriptionRequest struct {
2023-07-24 18:35:55 +00:00
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
2023-03-26 09:37:06 +00:00
// A two-letter ISO 639-1 language code or an empty string
LanguageCode string `json:"language_code"`
2023-03-11 11:13:56 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns the text shown in the chat with a bot if the chat is empty in the given language. Can be called only if userTypeBot.can_be_edited == true
2023-03-11 11:13:56 +00:00
func (client *Client) GetBotInfoDescription(req *GetBotInfoDescriptionRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBotInfoDescription",
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"bot_user_id": req.BotUserId,
2023-03-26 09:37:06 +00:00
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type SetBotInfoShortDescriptionRequest struct {
2023-07-24 18:35:55 +00:00
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
// A two-letter ISO 639-1 language code. If empty, the short description will be shown to all users for whose languages there is no dedicated description
2023-03-26 09:37:06 +00:00
LanguageCode string `json:"language_code"`
// New bot's short description on the specified language
ShortDescription string `json:"short_description"`
2023-03-11 11:13:56 +00:00
}
2023-07-24 18:35:55 +00:00
// Sets the text shown on a bot's profile page and sent together with the link when users share the bot. Can be called only if userTypeBot.can_be_edited == true
2023-03-11 11:13:56 +00:00
func (client *Client) SetBotInfoShortDescription(req *SetBotInfoShortDescriptionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setBotInfoShortDescription",
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"bot_user_id": req.BotUserId,
2023-03-26 09:37:06 +00:00
"language_code": req.LanguageCode,
"short_description": req.ShortDescription,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBotInfoShortDescriptionRequest struct {
2023-07-24 18:35:55 +00:00
// Identifier of the target bot
BotUserId int64 `json:"bot_user_id"`
2023-03-26 09:37:06 +00:00
// A two-letter ISO 639-1 language code or an empty string
LanguageCode string `json:"language_code"`
2023-03-11 11:13:56 +00:00
}
2023-07-24 18:35:55 +00:00
// Returns the text shown on a bot's profile page and sent together with the link when users share the bot in the given language. Can be called only if userTypeBot.can_be_edited == true
2023-03-11 11:13:56 +00:00
func (client *Client) GetBotInfoShortDescription(req *GetBotInfoShortDescriptionRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBotInfoShortDescription",
},
Data: map[string]interface{}{
2023-07-24 18:35:55 +00:00
"bot_user_id": req.BotUserId,
2023-03-26 09:37:06 +00:00
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2023-03-11 11:13:56 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns all active sessions of the current user
func (client *Client) GetActiveSessions() (*Sessions, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getActiveSessions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSessions(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TerminateSessionRequest struct {
// Session identifier
SessionId JsonInt64 `json:"session_id"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Terminates a session of the current user
func (client *Client) TerminateSession(req *TerminateSessionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "terminateSession",
},
Data: map[string]interface{}{
"session_id": req.SessionId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2021-12-30 05:55:02 +00:00
// Terminates all other sessions of the current user
func (client *Client) TerminateAllOtherSessions() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "terminateAllOtherSessions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-09-16 07:09:40 +00:00
type ConfirmSessionRequest struct {
// Session identifier
SessionId JsonInt64 `json:"session_id"`
}
// Confirms an unconfirmed session of the current user from another device
func (client *Client) ConfirmSession(req *ConfirmSessionRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "confirmSession",
},
Data: map[string]interface{}{
"session_id": req.SessionId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2023-03-26 09:37:06 +00:00
type ToggleSessionCanAcceptCallsRequest struct {
// Session identifier
SessionId JsonInt64 `json:"session_id"`
// Pass true to allow accepting incoming calls by the session; pass false otherwise
CanAcceptCalls bool `json:"can_accept_calls"`
2021-12-30 05:55:02 +00:00
}
// Toggles whether a session can accept incoming calls
func (client *Client) ToggleSessionCanAcceptCalls(req *ToggleSessionCanAcceptCallsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSessionCanAcceptCalls",
},
Data: map[string]interface{}{
"session_id": req.SessionId,
"can_accept_calls": req.CanAcceptCalls,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSessionCanAcceptSecretChatsRequest struct {
// Session identifier
SessionId JsonInt64 `json:"session_id"`
2023-07-24 18:35:55 +00:00
// Pass true to allow accepting secret chats by the session; pass false otherwise
2023-03-26 09:37:06 +00:00
CanAcceptSecretChats bool `json:"can_accept_secret_chats"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether a session can accept incoming secret chats
func (client *Client) ToggleSessionCanAcceptSecretChats(req *ToggleSessionCanAcceptSecretChatsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSessionCanAcceptSecretChats",
},
Data: map[string]interface{}{
"session_id": req.SessionId,
"can_accept_secret_chats": req.CanAcceptSecretChats,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetInactiveSessionTtlRequest struct {
// New number of days of inactivity before sessions will be automatically terminated; 1-366 days
InactiveSessionTtlDays int32 `json:"inactive_session_ttl_days"`
2021-12-30 05:55:02 +00:00
}
// Changes the period of inactivity after which sessions will automatically be terminated
func (client *Client) SetInactiveSessionTtl(req *SetInactiveSessionTtlRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setInactiveSessionTtl",
},
Data: map[string]interface{}{
"inactive_session_ttl_days": req.InactiveSessionTtlDays,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns all website where the current user used Telegram to log in
func (client *Client) GetConnectedWebsites() (*ConnectedWebsites, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getConnectedWebsites",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalConnectedWebsites(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type DisconnectWebsiteRequest struct {
// Website identifier
WebsiteId JsonInt64 `json:"website_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Disconnects website from the current user's Telegram account
2018-10-16 20:32:57 +00:00
func (client *Client) DisconnectWebsite(req *DisconnectWebsiteRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "disconnectWebsite",
},
Data: map[string]interface{}{
"website_id": req.WebsiteId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Disconnects all websites from the current user's Telegram account
func (client *Client) DisconnectAllWebsites() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "disconnectAllWebsites",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetSupergroupUsernameRequest struct {
// Identifier of the supergroup or channel
SupergroupId int64 `json:"supergroup_id"`
// New value of the username. Use an empty string to remove the username. The username can't be completely removed if there is another active or disabled username
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2022-11-07 18:50:52 +00:00
// Changes the editable username of a supergroup or channel, requires owner privileges in the supergroup or channel
2018-10-16 20:32:57 +00:00
func (client *Client) SetSupergroupUsername(req *SetSupergroupUsernameRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setSupergroupUsername",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"username": req.Username,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ToggleSupergroupUsernameIsActiveRequest struct {
// Identifier of the supergroup or channel
SupergroupId int64 `json:"supergroup_id"`
// The username to change
Username string `json:"username"`
// Pass true to activate the username; pass false to disable it
IsActive bool `json:"is_active"`
2022-11-07 18:50:52 +00:00
}
// Changes active state for a username of a supergroup or channel, requires owner privileges in the supergroup or channel. The editable username can't be disabled. May return an error with a message "USERNAMES_ACTIVE_TOO_MUCH" if the maximum number of active usernames has been reached
func (client *Client) ToggleSupergroupUsernameIsActive(req *ToggleSupergroupUsernameIsActiveRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupUsernameIsActive",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"username": req.Username,
"is_active": req.IsActive,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type DisableAllSupergroupUsernamesRequest struct {
// Identifier of the supergroup or channel
SupergroupId int64 `json:"supergroup_id"`
2022-11-07 18:50:52 +00:00
}
// Disables all active non-editable usernames of a supergroup or channel, requires owner privileges in the supergroup or channel
func (client *Client) DisableAllSupergroupUsernames(req *DisableAllSupergroupUsernamesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "disableAllSupergroupUsernames",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type ReorderSupergroupActiveUsernamesRequest struct {
// Identifier of the supergroup or channel
SupergroupId int64 `json:"supergroup_id"`
// The new order of active usernames. All currently active usernames must be specified
Usernames []string `json:"usernames"`
2022-11-07 18:50:52 +00:00
}
// Changes order of active usernames of a supergroup or channel, requires owner privileges in the supergroup or channel
func (client *Client) ReorderSupergroupActiveUsernames(req *ReorderSupergroupActiveUsernamesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reorderSupergroupActiveUsernames",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"usernames": req.Usernames,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type SetSupergroupStickerSetRequest struct {
// Identifier of the supergroup
SupergroupId int64 `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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Changes the sticker set of a supergroup; requires can_change_info administrator right
2018-10-16 20:32:57 +00:00
func (client *Client) SetSupergroupStickerSet(req *SetSupergroupStickerSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setSupergroupStickerSet",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"sticker_set_id": req.StickerSetId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupSignMessagesRequest struct {
// Identifier of the channel
SupergroupId int64 `json:"supergroup_id"`
// New value of sign_messages
SignMessages bool `json:"sign_messages"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether sender signature is added to sent messages in a channel; requires can_change_info administrator right
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleSupergroupSignMessages(req *ToggleSupergroupSignMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupSignMessages",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"sign_messages": req.SignMessages,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupJoinToSendMessagesRequest struct {
// Identifier of the supergroup
SupergroupId int64 `json:"supergroup_id"`
// New value of join_to_send_messages
JoinToSendMessages bool `json:"join_to_send_messages"`
2022-06-21 18:10:07 +00:00
}
// Toggles whether joining is mandatory to send messages to a discussion supergroup; requires can_restrict_members administrator right
func (client *Client) ToggleSupergroupJoinToSendMessages(req *ToggleSupergroupJoinToSendMessagesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupJoinToSendMessages",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"join_to_send_messages": req.JoinToSendMessages,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupJoinByRequestRequest struct {
// Identifier of the channel
SupergroupId int64 `json:"supergroup_id"`
// New value of join_by_request
JoinByRequest bool `json:"join_by_request"`
2022-06-21 18:10:07 +00:00
}
// Toggles whether all users directly joining the supergroup need to be approved by supergroup administrators; requires can_restrict_members administrator right
func (client *Client) ToggleSupergroupJoinByRequest(req *ToggleSupergroupJoinByRequestRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupJoinByRequest",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"join_by_request": req.JoinByRequest,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupIsAllHistoryAvailableRequest struct {
// The identifier of the supergroup
SupergroupId int64 `json:"supergroup_id"`
// The new value of is_all_history_available
IsAllHistoryAvailable bool `json:"is_all_history_available"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Toggles whether the message history of a supergroup is available to new members; requires can_change_info administrator right
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleSupergroupIsAllHistoryAvailable(req *ToggleSupergroupIsAllHistoryAvailableRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupIsAllHistoryAvailable",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"is_all_history_available": req.IsAllHistoryAvailable,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupHasHiddenMembersRequest struct {
// Identifier of the supergroup
SupergroupId int64 `json:"supergroup_id"`
// New value of has_hidden_members
HasHiddenMembers bool `json:"has_hidden_members"`
2022-12-30 18:28:59 +00:00
}
// Toggles whether non-administrators can receive only administrators and bots using getSupergroupMembers or searchChatMembers. Can be called only if supergroupFullInfo.can_hide_members == true
func (client *Client) ToggleSupergroupHasHiddenMembers(req *ToggleSupergroupHasHiddenMembersRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupHasHiddenMembers",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"has_hidden_members": req.HasHiddenMembers,
},
})
if err != nil {
return nil, err
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-30 18:28:59 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-30 18:28:59 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupHasAggressiveAntiSpamEnabledRequest struct {
// The identifier of the supergroup, which isn't a broadcast group
SupergroupId int64 `json:"supergroup_id"`
// The new value of has_aggressive_anti_spam_enabled
HasAggressiveAntiSpamEnabled bool `json:"has_aggressive_anti_spam_enabled"`
2022-12-07 20:04:16 +00:00
}
2022-12-30 18:28:59 +00:00
// Toggles whether aggressive anti-spam checks are enabled in the supergroup. Can be called only if supergroupFullInfo.can_toggle_aggressive_anti_spam == true
func (client *Client) ToggleSupergroupHasAggressiveAntiSpamEnabled(req *ToggleSupergroupHasAggressiveAntiSpamEnabledRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupHasAggressiveAntiSpamEnabled",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"has_aggressive_anti_spam_enabled": req.HasAggressiveAntiSpamEnabled,
},
})
if err != nil {
return nil, err
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-07 20:04:16 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupIsForumRequest struct {
// Identifier of the supergroup
SupergroupId int64 `json:"supergroup_id"`
// New value of is_forum
IsForum bool `json:"is_forum"`
2022-11-07 18:50:52 +00:00
}
2023-02-04 22:54:46 +00:00
// Toggles whether the supergroup is a forum; requires owner privileges in the supergroup. Discussion supergroups can't be converted to forums
2022-11-07 18:50:52 +00:00
func (client *Client) ToggleSupergroupIsForum(req *ToggleSupergroupIsForumRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupIsForum",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"is_forum": req.IsForum,
},
})
if err != nil {
return nil, err
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-11-07 18:50:52 +00:00
}
2023-03-26 09:37:06 +00:00
type ToggleSupergroupIsBroadcastGroupRequest struct {
// Identifier of the supergroup
SupergroupId int64 `json:"supergroup_id"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Upgrades supergroup to a broadcast group; requires owner privileges in the supergroup
func (client *Client) ToggleSupergroupIsBroadcastGroup(req *ToggleSupergroupIsBroadcastGroupRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleSupergroupIsBroadcastGroup",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type ReportSupergroupSpamRequest struct {
// Supergroup identifier
SupergroupId int64 `json:"supergroup_id"`
// Identifiers of messages to report
MessageIds []int64 `json:"message_ids"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Reports messages in a supergroup as spam; requires administrator rights in the supergroup
func (client *Client) ReportSupergroupSpam(req *ReportSupergroupSpamRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportSupergroupSpam",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"message_ids": req.MessageIds,
},
})
if err != nil {
return nil, err
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-03-13 04:04:12 +00:00
}
2023-03-26 09:37:06 +00:00
type ReportSupergroupAntiSpamFalsePositiveRequest struct {
// Supergroup identifier
SupergroupId int64 `json:"supergroup_id"`
// Identifier of the erroneously deleted message
MessageId int64 `json:"message_id"`
2022-12-07 20:04:16 +00:00
}
// Reports a false deletion of a message by aggressive anti-spam checks; requires administrator rights in the supergroup. Can be called only for messages from chatEventMessageDeleted with can_report_anti_spam_false_positive == true
func (client *Client) ReportSupergroupAntiSpamFalsePositive(req *ReportSupergroupAntiSpamFalsePositiveRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportSupergroupAntiSpamFalsePositive",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetSupergroupMembersRequest struct {
// Identifier of the supergroup or channel
SupergroupId int64 `json:"supergroup_id"`
// The type of users to return; pass null to use supergroupMembersFilterRecent
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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
func (client *Client) GetSupergroupMembers(req *GetSupergroupMembersRequest) (*ChatMembers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSupergroupMembers",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"filter": req.Filter,
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalChatMembers(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CloseSecretChatRequest struct {
// Secret chat identifier
SecretChatId int32 `json:"secret_chat_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Closes a secret chat, effectively transferring its state to secretChatStateClosed
2018-10-16 20:32:57 +00:00
func (client *Client) CloseSecretChat(req *CloseSecretChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "closeSecretChat",
},
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 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"`
// The maximum number of events to return; up to 100
Limit int32 `json:"limit"`
// The types of events to return; pass null to get chat events of all types
Filters *ChatEventLogFilters `json:"filters"`
// User identifiers by which to filter events. By default, events relating to all users will be returned
UserIds []int64 `json:"user_ids"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// Returns a list of service actions taken by chat members and administrators in the last 48 hours. Available only for supergroups and channels. Requires administrator rights. Returns results in reverse chronological order (i.e., in order of decreasing event_id)
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatEventLog(req *GetChatEventLogRequest) (*ChatEvents, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatEventLog",
},
Data: map[string]interface{}{
"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 {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatEvents(result.Data)
}
type GetPaymentFormRequest struct {
// The invoice
InputInvoice InputInvoice `json:"input_invoice"`
// Preferred payment form theme; pass null to use the default theme
Theme *ThemeParameters `json:"theme"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns an invoice payment form. This method must be called when the user presses inlineKeyboardButtonBuy
2018-10-16 20:32:57 +00:00
func (client *Client) GetPaymentForm(req *GetPaymentFormRequest) (*PaymentForm, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPaymentForm",
},
Data: map[string]interface{}{
"input_invoice": req.InputInvoice,
"theme": req.Theme,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPaymentForm(result.Data)
}
type ValidateOrderInfoRequest struct {
// The invoice
InputInvoice InputInvoice `json:"input_invoice"`
// The order information, provided by the user; pass null if empty
OrderInfo *OrderInfo `json:"order_info"`
// Pass true to save the order information
AllowSave bool `json:"allow_save"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Validates the order information provided by a user and returns the available shipping options for a flexible invoice
2018-10-16 20:32:57 +00:00
func (client *Client) ValidateOrderInfo(req *ValidateOrderInfoRequest) (*ValidatedOrderInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "validateOrderInfo",
},
Data: map[string]interface{}{
"input_invoice": req.InputInvoice,
"order_info": req.OrderInfo,
"allow_save": req.AllowSave,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalValidatedOrderInfo(result.Data)
}
type SendPaymentFormRequest struct {
// The invoice
InputInvoice InputInvoice `json:"input_invoice"`
// Payment form identifier returned by getPaymentForm
PaymentFormId JsonInt64 `json:"payment_form_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"`
// Chosen by the user amount of tip in the smallest units of the currency
TipAmount int64 `json:"tip_amount"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a filled-out payment form to the bot for final verification
2018-10-16 20:32:57 +00:00
func (client *Client) SendPaymentForm(req *SendPaymentFormRequest) (*PaymentResult, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPaymentForm",
},
Data: map[string]interface{}{
"input_invoice": req.InputInvoice,
"payment_form_id": req.PaymentFormId,
"order_info_id": req.OrderInfoId,
"shipping_option_id": req.ShippingOptionId,
"credentials": req.Credentials,
"tip_amount": req.TipAmount,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPaymentResult(result.Data)
}
type GetPaymentReceiptRequest struct {
// Chat identifier of the messagePaymentSuccessful message
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a successful payment
2018-10-16 20:32:57 +00:00
func (client *Client) GetPaymentReceipt(req *GetPaymentReceiptRequest) (*PaymentReceipt, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPaymentReceipt",
},
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 UnmarshalPaymentReceipt(result.Data)
2022-03-13 04:04:12 +00:00
}
// Returns saved order information. Returns a 404 error if there is no saved order information
2018-08-30 14:55:42 +00:00
func (client *Client) GetSavedOrderInfo() (*OrderInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSavedOrderInfo",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOrderInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2022-03-13 04:04:12 +00:00
// Deletes saved order information
2018-08-30 14:55:42 +00:00
func (client *Client) DeleteSavedOrderInfo() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteSavedOrderInfo",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Deletes saved credentials for all payment provider bots
func (client *Client) DeleteSavedCredentials() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteSavedCredentials",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CreateInvoiceLinkRequest struct {
// Information about the invoice of the type inputMessageInvoice
Invoice InputMessageContent `json:"invoice"`
2022-06-21 18:10:07 +00:00
}
// Creates a link for the given invoice; for bots only
func (client *Client) CreateInvoiceLink(req *CreateInvoiceLinkRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createInvoiceLink",
},
Data: map[string]interface{}{
"invoice": req.Invoice,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2022-06-21 18:10:07 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a user that can be contacted to get support
func (client *Client) GetSupportUser() (*User, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSupportUser",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBackgroundsRequest struct {
// Pass true to order returned backgrounds for a dark theme
ForDarkTheme bool `json:"for_dark_theme"`
2019-09-10 12:36:54 +00:00
}
// Returns backgrounds installed by the user
func (client *Client) GetBackgrounds(req *GetBackgroundsRequest) (*Backgrounds, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBackgrounds",
},
Data: map[string]interface{}{
"for_dark_theme": req.ForDarkTheme,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBackgrounds(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBackgroundUrlRequest struct {
// Background name
Name string `json:"name"`
// Background type
Type BackgroundType `json:"type"`
2019-09-10 12:36:54 +00:00
}
// Constructs a persistent HTTP URL for a background
func (client *Client) GetBackgroundUrl(req *GetBackgroundUrlRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBackgroundUrl",
},
Data: map[string]interface{}{
"name": req.Name,
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type SearchBackgroundRequest struct {
// The name of the background
Name string `json:"name"`
2019-09-10 12:36:54 +00:00
}
// Searches for a background by its name
func (client *Client) SearchBackground(req *SearchBackgroundRequest) (*Background, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchBackground",
},
Data: map[string]interface{}{
"name": req.Name,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalBackground(result.Data)
}
type SetBackgroundRequest struct {
2023-07-24 18:35:55 +00:00
// The input background to use; pass null to create a new filled background or to remove the current background
2023-03-26 09:37:06 +00:00
Background InputBackground `json:"background"`
// Background type; pass null to use the default type of the remote background or to remove the current background
Type BackgroundType `json:"type"`
// Pass true if the background is changed for a dark theme
ForDarkTheme bool `json:"for_dark_theme"`
2019-09-10 12:36:54 +00:00
}
// Changes the background selected by the user; adds background to the list of installed backgrounds
func (client *Client) SetBackground(req *SetBackgroundRequest) (*Background, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setBackground",
},
Data: map[string]interface{}{
"background": req.Background,
"type": req.Type,
"for_dark_theme": req.ForDarkTheme,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBackground(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveBackgroundRequest struct {
// The background identifier
BackgroundId JsonInt64 `json:"background_id"`
2019-09-10 12:36:54 +00:00
}
// Removes background from the list of installed backgrounds
func (client *Client) RemoveBackground(req *RemoveBackgroundRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeBackground",
},
Data: map[string]interface{}{
"background_id": req.BackgroundId,
},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-09-10 12:36:54 +00:00
}
// Resets list of installed backgrounds to its default value
func (client *Client) ResetBackgrounds() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resetBackgrounds",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetLocalizationTargetInfoRequest struct {
// Pass true to get only locally available information without sending network requests
OnlyLocal bool `json:"only_local"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns information about the current localization target. This is an offline request if only_local is true. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) GetLocalizationTargetInfo(req *GetLocalizationTargetInfoRequest) (*LocalizationTargetInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getLocalizationTargetInfo",
},
Data: map[string]interface{}{
"only_local": req.OnlyLocal,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLocalizationTargetInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetLanguagePackInfoRequest struct {
// Language pack identifier
LanguagePackId string `json:"language_pack_id"`
2019-06-07 10:56:06 +00:00
}
// Returns information about a language pack. Returned language pack identifier may be different from a provided one. Can be called before authorization
func (client *Client) GetLanguagePackInfo(req *GetLanguagePackInfoRequest) (*LanguagePackInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getLanguagePackInfo",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLanguagePackInfo(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns strings from a language pack in the current localization target by their keys. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) GetLanguagePackStrings(req *GetLanguagePackStringsRequest) (*LanguagePackStrings, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getLanguagePackStrings",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
"keys": req.Keys,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLanguagePackStrings(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SynchronizeLanguagePackRequest struct {
// Language pack identifier
LanguagePackId string `json:"language_pack_id"`
2019-06-07 10:56:06 +00:00
}
2021-12-30 05:55:02 +00:00
// Fetches the latest versions of all strings from a language pack in the current localization target from the server. This method doesn't need to be called explicitly for the current used/base language packs. Can be called before authorization
2019-06-07 10:56:06 +00:00
func (client *Client) SynchronizeLanguagePack(req *SynchronizeLanguagePackRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "synchronizeLanguagePack",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type AddCustomServerLanguagePackRequest struct {
// Identifier of a language pack to be added
LanguagePackId string `json:"language_pack_id"`
2019-06-07 10:56:06 +00:00
}
// Adds a custom server language pack to the list of installed language packs in current localization target. Can be called before authorization
func (client *Client) AddCustomServerLanguagePack(req *AddCustomServerLanguagePackRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addCustomServerLanguagePack",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type SetCustomLanguagePackRequest struct {
2023-09-16 07:09:40 +00:00
// Information about the language pack. Language pack identifier must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters. Can be called before authorization
2023-03-26 09:37:06 +00:00
Info *LanguagePackInfo `json:"info"`
// Strings of the new language pack
Strings []*LanguagePackString `json:"strings"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Adds or changes a custom local language pack to the current localization target
2018-10-16 20:32:57 +00:00
func (client *Client) SetCustomLanguagePack(req *SetCustomLanguagePackRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setCustomLanguagePack",
},
Data: map[string]interface{}{
"info": req.Info,
"strings": req.Strings,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type EditCustomLanguagePackInfoRequest struct {
// New information about the custom local language pack
Info *LanguagePackInfo `json:"info"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Edits information about a custom local language pack in the current localization target. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) EditCustomLanguagePackInfo(req *EditCustomLanguagePackInfoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editCustomLanguagePackInfo",
},
Data: map[string]interface{}{
"info": req.Info,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetCustomLanguagePackStringRequest struct {
// Identifier of a previously added custom local language pack in the current localization target
LanguagePackId string `json:"language_pack_id"`
// New language pack string
NewString *LanguagePackString `json:"new_string"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Adds, edits or deletes a string in a custom local language pack. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) SetCustomLanguagePackString(req *SetCustomLanguagePackStringRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setCustomLanguagePackString",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
"new_string": req.NewString,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteLanguagePackRequest struct {
// Identifier of the language pack to delete
LanguagePackId string `json:"language_pack_id"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Deletes all information about a language pack in the current localization target. The language pack which is currently in use (including base language pack) or is being synchronized can't be deleted. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteLanguagePack(req *DeleteLanguagePackRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteLanguagePack",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RegisterDeviceRequest struct {
// Device token
DeviceToken DeviceToken `json:"device_token"`
// List of user identifiers of other users currently using the application
OtherUserIds []int64 `json:"other_user_ids"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Registers the currently used device for receiving push notifications. Returns a globally unique identifier of the push notification subscription
func (client *Client) RegisterDevice(req *RegisterDeviceRequest) (*PushReceiverId, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "registerDevice",
},
Data: map[string]interface{}{
"device_token": req.DeviceToken,
"other_user_ids": req.OtherUserIds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPushReceiverId(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type ProcessPushNotificationRequest struct {
// JSON-encoded push notification payload with all fields sent by the server, and "google.sent_time" and "google.notification.sound" fields added
Payload string `json:"payload"`
2019-06-07 10:56:06 +00:00
}
// Handles a push notification. Returns error with code 406 if the push notification is not supported and connection to the server is required to fetch new data. Can be called before authorization
func (client *Client) ProcessPushNotification(req *ProcessPushNotificationRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "processPushNotification",
},
Data: map[string]interface{}{
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPushReceiverIdRequest struct {
// JSON-encoded push notification payload
Payload string `json:"payload"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns a globally unique push notification subscription identifier for identification of an account, which has received a push notification. Can be called synchronously
func GetPushReceiverId(req *GetPushReceiverIdRequest) (*PushReceiverId, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getPushReceiverId",
},
Data: map[string]interface{}{
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPushReceiverId(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Returns a globally unique push notification subscription identifier for identification of an account, which has received a push notification. Can be called synchronously
func (client *Client) GetPushReceiverId(req *GetPushReceiverIdRequest) (*PushReceiverId, error) {
2023-03-26 09:37:06 +00:00
return GetPushReceiverId(req)}
2023-03-26 09:37:06 +00:00
type GetRecentlyVisitedTMeUrlsRequest struct {
// Google Play referrer to identify the user
Referrer string `json:"referrer"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns t.me URLs recently visited by a newly registered user
2018-10-16 20:32:57 +00:00
func (client *Client) GetRecentlyVisitedTMeUrls(req *GetRecentlyVisitedTMeUrlsRequest) (*TMeUrls, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getRecentlyVisitedTMeUrls",
},
Data: map[string]interface{}{
"referrer": req.Referrer,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTMeUrls(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetUserPrivacySettingRulesRequest struct {
// The privacy setting
Setting UserPrivacySetting `json:"setting"`
// The new privacy rules
Rules *UserPrivacySettingRules `json:"rules"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes user privacy settings
2018-10-16 20:32:57 +00:00
func (client *Client) SetUserPrivacySettingRules(req *SetUserPrivacySettingRulesRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setUserPrivacySettingRules",
},
Data: map[string]interface{}{
"setting": req.Setting,
"rules": req.Rules,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetUserPrivacySettingRulesRequest struct {
// The privacy setting
Setting UserPrivacySetting `json:"setting"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns the current privacy settings
2018-10-16 20:32:57 +00:00
func (client *Client) GetUserPrivacySettingRules(req *GetUserPrivacySettingRulesRequest) (*UserPrivacySettingRules, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUserPrivacySettingRules",
},
Data: map[string]interface{}{
"setting": req.Setting,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUserPrivacySettingRules(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetOptionRequest struct {
// The name of the option
Name string `json:"name"`
2018-10-16 20:32:57 +00:00
}
2022-08-13 15:24:07 +00:00
// 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. Can be called synchronously for options "version" and "commit_hash"
func GetOption(req *GetOptionRequest) (OptionValue, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getOption",
},
Data: map[string]interface{}{
"name": req.Name,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeOptionValueBoolean:
return UnmarshalOptionValueBoolean(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeOptionValueEmpty:
return UnmarshalOptionValueEmpty(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeOptionValueInteger:
return UnmarshalOptionValueInteger(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeOptionValueString:
return UnmarshalOptionValueString(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2022-08-13 15:24:07 +00:00
// deprecated
// 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. Can be called synchronously for options "version" and "commit_hash"
func (client *Client) GetOption(req *GetOptionRequest) (OptionValue, error) {
2023-03-26 09:37:06 +00:00
return GetOption(req)}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
type SetOptionRequest struct {
// The name of the option
Name string `json:"name"`
// The new value of the option; pass null to reset option value to a default value
Value OptionValue `json:"value"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetOption(req *SetOptionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setOption",
},
Data: map[string]interface{}{
"name": req.Name,
"value": req.Value,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SetAccountTtlRequest struct {
// New account TTL
Ttl *AccountTtl `json:"ttl"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes the period of inactivity after which the account of the current user will automatically be deleted
2018-10-16 20:32:57 +00:00
func (client *Client) SetAccountTtl(req *SetAccountTtlRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAccountTtl",
},
Data: map[string]interface{}{
"ttl": req.Ttl,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
// Returns the period of inactivity after which the account of the current user will automatically be deleted
func (client *Client) GetAccountTtl() (*AccountTtl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAccountTtl",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAccountTtl(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteAccountRequest struct {
// The reason why the account was deleted; optional
Reason string `json:"reason"`
// The 2-step verification password of the current user. If not specified, account deletion can be canceled within one week
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteAccount(req *DeleteAccountRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteAccount",
},
Data: map[string]interface{}{
"reason": req.Reason,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetDefaultMessageAutoDeleteTimeRequest struct {
// New default message auto-delete time; must be from 0 up to 365 * 86400 and be divisible by 86400. If 0, then messages aren't deleted automatically
MessageAutoDeleteTime *MessageAutoDeleteTime `json:"message_auto_delete_time"`
2022-12-07 20:04:16 +00:00
}
2022-12-30 18:28:59 +00:00
// Changes the default message auto-delete time for new chats
func (client *Client) SetDefaultMessageAutoDeleteTime(req *SetDefaultMessageAutoDeleteTimeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setDefaultMessageAutoDeleteTime",
},
Data: map[string]interface{}{
"message_auto_delete_time": req.MessageAutoDeleteTime,
},
})
if err != nil {
return nil, err
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-12-07 20:04:16 +00:00
}
2022-12-30 18:28:59 +00:00
// Returns default message auto-delete time setting for new chats
func (client *Client) GetDefaultMessageAutoDeleteTime() (*MessageAutoDeleteTime, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDefaultMessageAutoDeleteTime",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-12-07 20:04:16 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalMessageAutoDeleteTime(result.Data)
2022-12-07 20:04:16 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveChatActionBarRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Removes a chat action bar without any other action
func (client *Client) RemoveChatActionBar(req *RemoveChatActionBarRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeChatActionBar",
},
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 ReportChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifiers of reported messages; may be empty to report the whole chat
MessageIds []int64 `json:"message_ids"`
// The reason for reporting the chat
2023-07-24 18:35:55 +00:00
Reason ReportReason `json:"reason"`
2023-03-26 09:37:06 +00:00
// Additional report details; 0-1024 characters
Text string `json:"text"`
2019-06-07 10:56:06 +00:00
}
2021-12-30 05:55:02 +00:00
// Reports a chat to the Telegram moderators. A chat can be reported only from the chat action bar, or if chat.can_be_reported
2019-06-07 10:56:06 +00:00
func (client *Client) ReportChat(req *ReportChatRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
"reason": req.Reason,
"text": req.Text,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ReportChatPhotoRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the photo to report. Only full photos from chatPhoto can be reported
FileId int32 `json:"file_id"`
// The reason for reporting the chat photo
2023-07-24 18:35:55 +00:00
Reason ReportReason `json:"reason"`
2023-03-26 09:37:06 +00:00
// Additional report details; 0-1024 characters
Text string `json:"text"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Reports a chat photo to the Telegram moderators. A chat photo can be reported only if chat.can_be_reported
func (client *Client) ReportChatPhoto(req *ReportChatPhotoRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportChatPhoto",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"file_id": req.FileId,
"reason": req.Reason,
"text": req.Text,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ReportMessageReactionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// Identifier of the sender, which added the reaction
SenderId MessageSender `json:"sender_id"`
2022-09-18 01:34:29 +00:00
}
// Reports reactions set on a message to the Telegram moderators. Reactions on a message can be reported only if message.can_report_reactions
func (client *Client) ReportMessageReactions(req *ReportMessageReactionsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportMessageReactions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"sender_id": req.SenderId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatStatisticsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Pass true if a dark theme is used by the application
IsDark bool `json:"is_dark"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true
2020-11-30 09:33:47 +00:00
func (client *Client) GetChatStatistics(req *GetChatStatisticsRequest) (ChatStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatStatistics",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"is_dark": req.IsDark,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeChatStatisticsSupergroup:
return UnmarshalChatStatisticsSupergroup(result.Data)
case TypeChatStatisticsChannel:
return UnmarshalChatStatisticsChannel(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type GetMessageStatisticsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// Pass true if a dark theme is used by the application
IsDark bool `json:"is_dark"`
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns detailed statistics about a message. Can be used only if message.can_get_statistics == true
2020-11-30 09:33:47 +00:00
func (client *Client) GetMessageStatistics(req *GetMessageStatisticsRequest) (*MessageStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMessageStatistics",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"is_dark": req.IsDark,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageStatistics(result.Data)
}
type GetStatisticalGraphRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The token for graph loading
Token string `json:"token"`
// X-value for zoomed in graph or 0 otherwise
X int64 `json:"x"`
2020-11-30 09:33:47 +00:00
}
// Loads an asynchronous or a zoomed in statistical graph
func (client *Client) GetStatisticalGraph(req *GetStatisticalGraphRequest) (StatisticalGraph, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStatisticalGraph",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"token": req.Token,
"x": req.X,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeStatisticalGraphData:
return UnmarshalStatisticalGraphData(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeStatisticalGraphAsync:
return UnmarshalStatisticalGraphAsync(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeStatisticalGraphError:
return UnmarshalStatisticalGraphError(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type GetStorageStatisticsRequest struct {
// The maximum number of chats with the largest storage usage for which separate statistics need to 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"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns storage usage statistics. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) GetStorageStatistics(req *GetStorageStatisticsRequest) (*StorageStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStorageStatistics",
},
Data: map[string]interface{}{
"chat_limit": req.ChatLimit,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStorageStatistics(result.Data)
2018-09-05 21:45:29 +00:00
}
2019-06-07 10:56:06 +00:00
// Quickly returns approximate storage usage statistics. Can be called before authorization
2018-09-05 21:45:29 +00:00
func (client *Client) GetStorageStatisticsFast() (*StorageStatisticsFast, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStorageStatisticsFast",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStorageStatisticsFast(result.Data)
2018-10-23 12:38:10 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns database statistics
func (client *Client) GetDatabaseStatistics() (*DatabaseStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDatabaseStatistics",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalDatabaseStatistics(result.Data)
}
type OptimizeStorageRequest struct {
// Limit on the total size of files after deletion, in bytes. 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 number 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 non-empty, only files with the given types are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted
FileTypes []FileType `json:"file_types"`
// If non-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 non-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"`
// Pass true if statistics about the files that were deleted must be returned instead of the whole storage usage statistics. Affects only returned statistics
ReturnDeletedFileStatistics bool `json:"return_deleted_file_statistics"`
// Same as in getStorageStatistics. Affects only returned statistics
ChatLimit int32 `json:"chat_limit"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Optimizes storage usage, i.e. deletes some files and returns new storage usage statistics. Secret thumbnails can't be deleted
2018-10-16 20:32:57 +00:00
func (client *Client) OptimizeStorage(req *OptimizeStorageRequest) (*StorageStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "optimizeStorage",
},
Data: map[string]interface{}{
"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,
"return_deleted_file_statistics": req.ReturnDeletedFileStatistics,
"chat_limit": req.ChatLimit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStorageStatistics(result.Data)
}
type SetNetworkTypeRequest struct {
// The new network type; pass null to set network type to networkTypeOther
Type NetworkType `json:"type"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// 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 must 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetNetworkType(req *SetNetworkTypeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setNetworkType",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetNetworkStatisticsRequest struct {
// Pass true to get statistics only for the current library launch
OnlyCurrent bool `json:"only_current"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns network data usage statistics. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) GetNetworkStatistics(req *GetNetworkStatisticsRequest) (*NetworkStatistics, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getNetworkStatistics",
},
Data: map[string]interface{}{
"only_current": req.OnlyCurrent,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalNetworkStatistics(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type AddNetworkStatisticsRequest struct {
// The network statistics entry with the data to be added to statistics
Entry NetworkStatisticsEntry `json:"entry"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Adds the specified data to data usage statistics. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) AddNetworkStatistics(req *AddNetworkStatisticsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addNetworkStatistics",
},
Data: map[string]interface{}{
"entry": req.Entry,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
// Resets all network data usage statistics to zero. Can be called before authorization
func (client *Client) ResetNetworkStatistics() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resetNetworkStatistics",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns auto-download settings presets for the current user
2019-09-10 12:36:54 +00:00
func (client *Client) GetAutoDownloadSettingsPresets() (*AutoDownloadSettingsPresets, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAutoDownloadSettingsPresets",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAutoDownloadSettingsPresets(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-03-26 09:37:06 +00:00
type SetAutoDownloadSettingsRequest struct {
// New user auto-download settings
Settings *AutoDownloadSettings `json:"settings"`
// Type of the network for which the new settings are relevant
Type NetworkType `json:"type"`
2019-09-10 12:36:54 +00:00
}
// Sets auto-download settings
func (client *Client) SetAutoDownloadSettings(req *SetAutoDownloadSettingsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAutoDownloadSettings",
},
Data: map[string]interface{}{
"settings": req.Settings,
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2019-09-10 12:36:54 +00:00
}
2023-02-04 22:54:46 +00:00
// Returns autosave settings for the current user
func (client *Client) GetAutosaveSettings() (*AutosaveSettings, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAutosaveSettings",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAutosaveSettings(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-03-26 09:37:06 +00:00
type SetAutosaveSettingsRequest struct {
// Autosave settings scope
Scope AutosaveSettingsScope `json:"scope"`
// New autosave settings for the scope; pass null to set autosave settings to default
Settings *ScopeAutosaveSettings `json:"settings"`
2023-02-04 22:54:46 +00:00
}
2023-03-11 11:13:56 +00:00
// Sets autosave settings for the given scope. The method is guaranteed to work only after at least one call to getAutosaveSettings
2023-02-04 22:54:46 +00:00
func (client *Client) SetAutosaveSettings(req *SetAutosaveSettingsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAutosaveSettings",
},
Data: map[string]interface{}{
"scope": req.Scope,
"settings": req.Settings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-03-11 11:13:56 +00:00
// Clears the list of all autosave settings exceptions. The method is guaranteed to work only after at least one call to getAutosaveSettings
2023-02-04 22:54:46 +00:00
func (client *Client) ClearAutosaveSettingsExceptions() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearAutosaveSettingsExceptions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-02-04 22:54:46 +00:00
}
2023-03-26 09:37:06 +00:00
type GetBankCardInfoRequest struct {
// The bank card number
BankCardNumber string `json:"bank_card_number"`
2020-11-30 09:33:47 +00:00
}
// Returns information about a bank card
func (client *Client) GetBankCardInfo(req *GetBankCardInfoRequest) (*BankCardInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBankCardInfo",
},
Data: map[string]interface{}{
"bank_card_number": req.BankCardNumber,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalBankCardInfo(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPassportElementRequest struct {
// Telegram Passport element type
Type PassportElementType `json:"type"`
// The 2-step verification password of the current user
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns one of the available Telegram Passport elements
2018-10-16 20:32:57 +00:00
func (client *Client) GetPassportElement(req *GetPassportElementRequest) (PassportElement, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPassportElement",
},
Data: map[string]interface{}{
"type": req.Type,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypePassportElementPersonalDetails:
return UnmarshalPassportElementPersonalDetails(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPassport:
return UnmarshalPassportElementPassport(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementDriverLicense:
return UnmarshalPassportElementDriverLicense(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementIdentityCard:
return UnmarshalPassportElementIdentityCard(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementInternalPassport:
return UnmarshalPassportElementInternalPassport(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementAddress:
return UnmarshalPassportElementAddress(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementUtilityBill:
return UnmarshalPassportElementUtilityBill(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementBankStatement:
return UnmarshalPassportElementBankStatement(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementRentalAgreement:
return UnmarshalPassportElementRentalAgreement(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPassportRegistration:
return UnmarshalPassportElementPassportRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementTemporaryRegistration:
return UnmarshalPassportElementTemporaryRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPhoneNumber:
return UnmarshalPassportElementPhoneNumber(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementEmailAddress:
return UnmarshalPassportElementEmailAddress(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetAllPassportElementsRequest struct {
// The 2-step verification password of the current user
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns all available Telegram Passport elements
2018-10-16 20:32:57 +00:00
func (client *Client) GetAllPassportElements(req *GetAllPassportElementsRequest) (*PassportElements, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAllPassportElements",
},
Data: map[string]interface{}{
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPassportElements(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SetPassportElementRequest struct {
// Input Telegram Passport element
Element InputPassportElement `json:"element"`
// The 2-step verification password of the current user
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetPassportElement(req *SetPassportElementRequest) (PassportElement, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setPassportElement",
},
Data: map[string]interface{}{
"element": req.Element,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypePassportElementPersonalDetails:
return UnmarshalPassportElementPersonalDetails(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPassport:
return UnmarshalPassportElementPassport(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementDriverLicense:
return UnmarshalPassportElementDriverLicense(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementIdentityCard:
return UnmarshalPassportElementIdentityCard(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementInternalPassport:
return UnmarshalPassportElementInternalPassport(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementAddress:
return UnmarshalPassportElementAddress(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementUtilityBill:
return UnmarshalPassportElementUtilityBill(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementBankStatement:
return UnmarshalPassportElementBankStatement(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementRentalAgreement:
return UnmarshalPassportElementRentalAgreement(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPassportRegistration:
return UnmarshalPassportElementPassportRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementTemporaryRegistration:
return UnmarshalPassportElementTemporaryRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementPhoneNumber:
return UnmarshalPassportElementPhoneNumber(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypePassportElementEmailAddress:
return UnmarshalPassportElementEmailAddress(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type DeletePassportElementRequest struct {
// Element type
Type PassportElementType `json:"type"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Deletes a Telegram Passport element
2018-10-16 20:32:57 +00:00
func (client *Client) DeletePassportElement(req *DeletePassportElementRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deletePassportElement",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SetPassportElementErrorsRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// The errors
Errors []*InputPassportElementError `json:"errors"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetPassportElementErrors(req *SetPassportElementErrorsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setPassportElementErrors",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"errors": req.Errors,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPreferredCountryLanguageRequest struct {
// A two-letter ISO 3166-1 alpha-2 country code
CountryCode string `json:"country_code"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Returns an IETF language tag of the language preferred in the country, which must be used to fill native fields in Telegram Passport personal details. Returns a 404 error if unknown
2018-10-16 20:32:57 +00:00
func (client *Client) GetPreferredCountryLanguage(req *GetPreferredCountryLanguageRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPreferredCountryLanguage",
},
Data: map[string]interface{}{
"country_code": req.CountryCode,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type SendPhoneNumberVerificationCodeRequest 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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Sends a code to verify a phone number to be added to a user's Telegram Passport
2018-10-16 20:32:57 +00:00
func (client *Client) SendPhoneNumberVerificationCode(req *SendPhoneNumberVerificationCodeRequest) (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPhoneNumberVerificationCode",
},
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 UnmarshalAuthenticationCodeInfo(result.Data)
2018-09-05 21:45:29 +00:00
}
2022-09-18 01:34:29 +00:00
// Resends the code to verify a phone number to be added to a user's Telegram Passport
2018-09-05 21:45:29 +00:00
func (client *Client) ResendPhoneNumberVerificationCode() (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendPhoneNumberVerificationCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckPhoneNumberVerificationCodeRequest struct {
// Verification code to check
Code string `json:"code"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Checks the phone number verification code for Telegram Passport
2018-10-16 20:32:57 +00:00
func (client *Client) CheckPhoneNumberVerificationCode(req *CheckPhoneNumberVerificationCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkPhoneNumberVerificationCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SendEmailAddressVerificationCodeRequest struct {
// Email address
EmailAddress string `json:"email_address"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Sends a code to verify an email address to be added to a user's Telegram Passport
2018-10-16 20:32:57 +00:00
func (client *Client) SendEmailAddressVerificationCode(req *SendEmailAddressVerificationCodeRequest) (*EmailAddressAuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendEmailAddressVerificationCode",
},
Data: map[string]interface{}{
"email_address": req.EmailAddress,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2022-09-18 01:34:29 +00:00
// Resends the code to verify an email address to be added to a user's Telegram Passport
2018-09-05 21:45:29 +00:00
func (client *Client) ResendEmailAddressVerificationCode() (*EmailAddressAuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendEmailAddressVerificationCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckEmailAddressVerificationCodeRequest struct {
// Verification code to check
Code string `json:"code"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Checks the email address verification code for Telegram Passport
2018-10-16 20:32:57 +00:00
func (client *Client) CheckEmailAddressVerificationCode(req *CheckEmailAddressVerificationCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkEmailAddressVerificationCode",
},
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 GetPassportAuthorizationFormRequest struct {
// User identifier of the service's bot
BotUserId int64 `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"`
// Unique request identifier provided by the service
Nonce string `json:"nonce"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns a Telegram Passport authorization form for sharing data with a service
2018-10-16 20:32:57 +00:00
func (client *Client) GetPassportAuthorizationForm(req *GetPassportAuthorizationFormRequest) (*PassportAuthorizationForm, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPassportAuthorizationForm",
},
Data: map[string]interface{}{
"bot_user_id": req.BotUserId,
"scope": req.Scope,
"public_key": req.PublicKey,
"nonce": req.Nonce,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPassportAuthorizationForm(result.Data)
}
type GetPassportAuthorizationFormAvailableElementsRequest struct {
// Authorization form identifier
AuthorizationFormId int32 `json:"authorization_form_id"`
// The 2-step verification password of the current user
Password string `json:"password"`
2019-06-07 10:56:06 +00:00
}
// Returns already available Telegram Passport elements suitable for completing a Telegram Passport authorization form. Result can be received only once for each authorization form
func (client *Client) GetPassportAuthorizationFormAvailableElements(req *GetPassportAuthorizationFormAvailableElementsRequest) (*PassportElementsWithErrors, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPassportAuthorizationFormAvailableElements",
},
Data: map[string]interface{}{
"authorization_form_id": req.AuthorizationFormId,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPassportElementsWithErrors(result.Data)
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type SendPassportAuthorizationFormRequest struct {
// Authorization form identifier
AuthorizationFormId int32 `json:"authorization_form_id"`
// Types of Telegram Passport elements chosen by user to complete the authorization form
Types []PassportElementType `json:"types"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Sends a Telegram Passport authorization form, effectively sharing data with the service. This method must be called after getPassportAuthorizationFormAvailableElements if some previously available elements are going to be reused
2018-10-16 20:32:57 +00:00
func (client *Client) SendPassportAuthorizationForm(req *SendPassportAuthorizationFormRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPassportAuthorizationForm",
},
Data: map[string]interface{}{
"authorization_form_id": req.AuthorizationFormId,
"types": req.Types,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SendPhoneNumberConfirmationCodeRequest struct {
// Hash value from the link
Hash string `json:"hash"`
// Phone number value from the link
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"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Sends phone number confirmation code to handle links of the type internalLinkTypePhoneNumberConfirmation
2018-10-16 20:32:57 +00:00
func (client *Client) SendPhoneNumberConfirmationCode(req *SendPhoneNumberConfirmationCodeRequest) (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPhoneNumberConfirmationCode",
},
Data: map[string]interface{}{
"hash": req.Hash,
"phone_number": req.PhoneNumber,
"settings": req.Settings,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-09-05 21:45:29 +00:00
// Resends phone number confirmation code
func (client *Client) ResendPhoneNumberConfirmationCode() (*AuthenticationCodeInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendPhoneNumberConfirmationCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckPhoneNumberConfirmationCodeRequest struct {
// Confirmation code to check
Code string `json:"code"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Checks phone number confirmation code
2018-10-16 20:32:57 +00:00
func (client *Client) CheckPhoneNumberConfirmationCode(req *CheckPhoneNumberConfirmationCodeRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkPhoneNumberConfirmationCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetBotUpdatesStatusRequest struct {
// The number of pending updates
PendingUpdateCount int32 `json:"pending_update_count"`
// The last error message
ErrorMessage string `json:"error_message"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Informs the server about the number of pending bot updates if they haven't been processed for a long time; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) SetBotUpdatesStatus(req *SetBotUpdatesStatusRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setBotUpdatesStatus",
},
Data: map[string]interface{}{
"pending_update_count": req.PendingUpdateCount,
"error_message": req.ErrorMessage,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type UploadStickerFileRequest struct {
// Sticker file owner; ignored for regular users
UserId int64 `json:"user_id"`
// Sticker format
StickerFormat StickerFormat `json:"sticker_format"`
// File file to upload; must fit in a 512x512 square. For WEBP stickers the file must be in WEBP or PNG format, which will be converted to WEBP server-side. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Uploads a file with a sticker; returns the uploaded file
2018-10-16 20:32:57 +00:00
func (client *Client) UploadStickerFile(req *UploadStickerFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "uploadStickerFile",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"sticker_format": req.StickerFormat,
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalFile(result.Data)
2018-10-23 12:38:10 +00:00
}
2023-03-26 09:37:06 +00:00
type GetSuggestedStickerSetNameRequest struct {
// Sticker set title; 1-64 characters
Title string `json:"title"`
2021-12-30 05:55:02 +00:00
}
// Returns a suggested name for a new sticker set with a given title
func (client *Client) GetSuggestedStickerSetName(req *GetSuggestedStickerSetNameRequest) (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getSuggestedStickerSetName",
},
Data: map[string]interface{}{
"title": req.Title,
},
})
if err != nil {
return nil, err
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2021-12-30 05:55:02 +00:00
}
2023-03-26 09:37:06 +00:00
type CheckStickerSetNameRequest struct {
// Name to be checked
Name string `json:"name"`
2021-12-30 05:55:02 +00:00
}
// Checks whether a name can be used for a new sticker set
func (client *Client) CheckStickerSetName(req *CheckStickerSetNameRequest) (CheckStickerSetNameResult, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkStickerSetName",
},
Data: map[string]interface{}{
"name": req.Name,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeCheckStickerSetNameResultOk:
return UnmarshalCheckStickerSetNameResultOk(result.Data)
case TypeCheckStickerSetNameResultNameInvalid:
return UnmarshalCheckStickerSetNameResultNameInvalid(result.Data)
case TypeCheckStickerSetNameResultNameOccupied:
return UnmarshalCheckStickerSetNameResultNameOccupied(result.Data)
default:
return nil, errors.New("invalid type")
}
}
type CreateNewStickerSetRequest struct {
// Sticker set owner; ignored for regular users
UserId int64 `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_<bot username>"* (*<bot_username>* is case insensitive) for bots; 1-64 characters
Name string `json:"name"`
// Format of the stickers in the set
StickerFormat StickerFormat `json:"sticker_format"`
// Type of the stickers in the set
StickerType StickerType `json:"sticker_type"`
// Pass true if stickers in the sticker set must be repainted; for custom emoji sticker sets only
NeedsRepainting bool `json:"needs_repainting"`
// List of stickers to be added to the set; must be non-empty. All stickers must have the same format. For TGS stickers, uploadStickerFile must be used before the sticker is shown
Stickers []*InputSticker `json:"stickers"`
// Source of the sticker set; may be empty if unknown
Source string `json:"source"`
2018-10-16 20:32:57 +00:00
}
2021-12-30 05:55:02 +00:00
// Creates a new sticker set. Returns the newly created sticker set
2018-10-16 20:32:57 +00:00
func (client *Client) CreateNewStickerSet(req *CreateNewStickerSetRequest) (*StickerSet, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewStickerSet",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"title": req.Title,
"name": req.Name,
"sticker_format": req.StickerFormat,
"sticker_type": req.StickerType,
"needs_repainting": req.NeedsRepainting,
"stickers": req.Stickers,
"source": req.Source,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickerSet(result.Data)
}
type AddStickerToSetRequest struct {
// Sticker set owner
UserId int64 `json:"user_id"`
// Sticker set name
Name string `json:"name"`
// Sticker to add to the set
Sticker *InputSticker `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2023-03-11 11:13:56 +00:00
// Adds a new sticker to a set; for bots only
func (client *Client) AddStickerToSet(req *AddStickerToSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addStickerToSet",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"name": req.Name,
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetStickerSetThumbnailRequest struct {
// Sticker set owner
UserId int64 `json:"user_id"`
// Sticker set name
Name string `json:"name"`
// Thumbnail to set in PNG, TGS, or WEBM format; pass null to remove the sticker set thumbnail. Thumbnail format must match the format of stickers in the set
Thumbnail InputFile `json:"thumbnail"`
2020-11-30 09:33:47 +00:00
}
2023-03-11 11:13:56 +00:00
// Sets a sticker set thumbnail; for bots only
func (client *Client) SetStickerSetThumbnail(req *SetStickerSetThumbnailRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerSetThumbnail",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"name": req.Name,
"thumbnail": req.Thumbnail,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetCustomEmojiStickerSetThumbnailRequest struct {
// Sticker set name
Name string `json:"name"`
// Identifier of the custom emoji from the sticker set, which will be set as sticker set thumbnail; pass 0 to remove the sticker set thumbnail
CustomEmojiId JsonInt64 `json:"custom_emoji_id"`
2023-03-11 11:13:56 +00:00
}
// Sets a custom emoji sticker set thumbnail; for bots only
func (client *Client) SetCustomEmojiStickerSetThumbnail(req *SetCustomEmojiStickerSetThumbnailRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setCustomEmojiStickerSetThumbnail",
},
Data: map[string]interface{}{
"name": req.Name,
"custom_emoji_id": req.CustomEmojiId,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type SetStickerSetTitleRequest struct {
// Sticker set name
Name string `json:"name"`
// New sticker set title
Title string `json:"title"`
2023-03-11 11:13:56 +00:00
}
// Sets a sticker set title; for bots only
func (client *Client) SetStickerSetTitle(req *SetStickerSetTitleRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerSetTitle",
},
Data: map[string]interface{}{
"name": req.Name,
"title": req.Title,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type DeleteStickerSetRequest struct {
// Sticker set name
Name string `json:"name"`
2023-03-11 11:13:56 +00:00
}
// Deleted a sticker set; for bots only
func (client *Client) DeleteStickerSet(req *DeleteStickerSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteStickerSet",
},
Data: map[string]interface{}{
"name": req.Name,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-02-04 23:22:52 +00:00
}
2023-03-26 09:37:06 +00:00
type SetStickerPositionInSetRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
// New position of the sticker in the set, 0-based
Position int32 `json:"position"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetStickerPositionInSet(req *SetStickerPositionInSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerPositionInSet",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
"position": req.Position,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveStickerFromSetRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveStickerFromSet(req *RemoveStickerFromSetRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeStickerFromSet",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2023-02-04 23:22:52 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-02-04 23:22:52 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-02-04 23:22:52 +00:00
}
2023-03-26 09:37:06 +00:00
type SetStickerEmojisRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
// New string with 1-20 emoji corresponding to the sticker
Emojis string `json:"emojis"`
2023-03-11 11:13:56 +00:00
}
// Changes the list of emoji corresponding to a sticker; for bots only. The sticker must belong to a regular or custom emoji sticker set created by the bot
func (client *Client) SetStickerEmojis(req *SetStickerEmojisRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerEmojis",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
"emojis": req.Emojis,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type SetStickerKeywordsRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
// List of up to 20 keywords with total length up to 64 characters, which can be used to find the sticker
Keywords []string `json:"keywords"`
2023-03-11 11:13:56 +00:00
}
// Changes the list of keywords of a sticker; for bots only. The sticker must belong to a regular or custom emoji sticker set created by the bot
func (client *Client) SetStickerKeywords(req *SetStickerKeywordsRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerKeywords",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
"keywords": req.Keywords,
},
})
if err != nil {
return nil, err
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2023-03-11 11:13:56 +00:00
}
2023-03-26 09:37:06 +00:00
type SetStickerMaskPositionRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
// Position where the mask is placed; pass null to remove mask position
MaskPosition *MaskPosition `json:"mask_position"`
2023-03-11 11:13:56 +00:00
}
// Changes the mask position of a mask sticker; for bots only. The sticker must belong to a mask sticker set created by the bot
func (client *Client) SetStickerMaskPosition(req *SetStickerMaskPositionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setStickerMaskPosition",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
"mask_position": req.MaskPosition,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded
2018-10-16 20:32:57 +00:00
func (client *Client) GetMapThumbnailFile(req *GetMapThumbnailFileRequest) (*File, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getMapThumbnailFile",
},
Data: map[string]interface{}{
"location": req.Location,
"zoom": req.Zoom,
"width": req.Width,
"height": req.Height,
"scale": req.Scale,
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type GetPremiumLimitRequest struct {
// Type of the limit
LimitType PremiumLimitType `json:"limit_type"`
2022-06-21 18:10:07 +00:00
}
// Returns information about a limit, increased for Premium users. Returns a 404 error if the limit is unknown
func (client *Client) GetPremiumLimit(req *GetPremiumLimitRequest) (*PremiumLimit, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPremiumLimit",
},
Data: map[string]interface{}{
"limit_type": req.LimitType,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPremiumLimit(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPremiumFeaturesRequest struct {
// Source of the request; pass null if the method is called from some non-standard source
Source PremiumSource `json:"source"`
2022-06-21 18:10:07 +00:00
}
// Returns information about features, available to Premium users
func (client *Client) GetPremiumFeatures(req *GetPremiumFeaturesRequest) (*PremiumFeatures, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPremiumFeatures",
},
Data: map[string]interface{}{
"source": req.Source,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPremiumFeatures(result.Data)
2022-06-21 18:10:07 +00:00
}
// Returns examples of premium stickers for demonstration purposes
2022-08-13 15:24:07 +00:00
func (client *Client) GetPremiumStickerExamples() (*Stickers, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPremiumStickerExamples",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalStickers(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type ViewPremiumFeatureRequest struct {
// The viewed premium feature
Feature PremiumFeature `json:"feature"`
2022-06-21 18:10:07 +00:00
}
// Informs TDLib that the user viewed detailed information about a Premium feature on the Premium features screen
func (client *Client) ViewPremiumFeature(req *ViewPremiumFeatureRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "viewPremiumFeature",
},
Data: map[string]interface{}{
"feature": req.Feature,
},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-06-21 18:10:07 +00:00
}
// Informs TDLib that the user clicked Premium subscription button on the Premium features screen
func (client *Client) ClickPremiumSubscriptionButton() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clickPremiumSubscriptionButton",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-06-21 18:10:07 +00:00
}
// Returns state of Telegram Premium subscription and promotion videos for Premium features
func (client *Client) GetPremiumState() (*PremiumState, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPremiumState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-06-21 18:10:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPremiumState(result.Data)
2022-06-21 18:10:07 +00:00
}
2023-03-26 09:37:06 +00:00
type CanPurchasePremiumRequest struct {
// Transaction purpose
Purpose StorePaymentPurpose `json:"purpose"`
2022-08-13 15:24:07 +00:00
}
// Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase
func (client *Client) CanPurchasePremium(req *CanPurchasePremiumRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "canPurchasePremium",
},
Data: map[string]interface{}{
"purpose": req.Purpose,
},
})
if err != nil {
return nil, err
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-08-13 15:24:07 +00:00
}
2023-03-26 09:37:06 +00:00
type AssignAppStoreTransactionRequest struct {
// App Store receipt
Receipt []byte `json:"receipt"`
// Transaction purpose
Purpose StorePaymentPurpose `json:"purpose"`
2022-08-13 15:24:07 +00:00
}
// Informs server about a purchase through App Store. For official applications only
func (client *Client) AssignAppStoreTransaction(req *AssignAppStoreTransactionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "assignAppStoreTransaction",
},
Data: map[string]interface{}{
"receipt": req.Receipt,
"purpose": req.Purpose,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AssignGooglePlayTransactionRequest struct {
// Application package name
PackageName string `json:"package_name"`
// Identifier of the purchased store product
StoreProductId string `json:"store_product_id"`
// Google Play purchase token
PurchaseToken string `json:"purchase_token"`
// Transaction purpose
Purpose StorePaymentPurpose `json:"purpose"`
2022-08-13 15:24:07 +00:00
}
// Informs server about a purchase through Google Play. For official applications only
func (client *Client) AssignGooglePlayTransaction(req *AssignGooglePlayTransactionRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "assignGooglePlayTransaction",
},
Data: map[string]interface{}{
"package_name": req.PackageName,
"store_product_id": req.StoreProductId,
"purchase_token": req.PurchaseToken,
"purpose": req.Purpose,
},
})
if err != nil {
return nil, err
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-08-13 15:24:07 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2022-08-13 15:24:07 +00:00
}
2023-03-26 09:37:06 +00:00
type AcceptTermsOfServiceRequest struct {
// Terms of service identifier
TermsOfServiceId string `json:"terms_of_service_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Accepts Telegram terms of services
2018-10-16 20:32:57 +00:00
func (client *Client) AcceptTermsOfService(req *AcceptTermsOfServiceRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "acceptTermsOfService",
},
Data: map[string]interface{}{
"terms_of_service_id": req.TermsOfServiceId,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-09-16 07:09:40 +00:00
type SearchStringsByPrefixRequest struct {
// The strings to search in for the query
Strings []string `json:"strings"`
// Query to search for
Query string `json:"query"`
// The maximum number of objects to return
Limit int32 `json:"limit"`
// Pass true to receive no results for an empty query
ReturnNoneForEmptyQuery bool `json:"return_none_for_empty_query"`
}
// Searches specified query by word prefixes in the provided strings. Returns 0-based positions of strings that matched. Can be called synchronously
func SearchStringsByPrefix(req *SearchStringsByPrefixRequest) (*FoundPositions, error) {
result, err := Execute(Request{
meta: meta{
Type: "searchStringsByPrefix",
},
Data: map[string]interface{}{
"strings": req.Strings,
"query": req.Query,
"limit": req.Limit,
"return_none_for_empty_query": req.ReturnNoneForEmptyQuery,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFoundPositions(result.Data)
}
// deprecated
// Searches specified query by word prefixes in the provided strings. Returns 0-based positions of strings that matched. Can be called synchronously
func (client *Client) SearchStringsByPrefix(req *SearchStringsByPrefixRequest) (*FoundPositions, error) {
return SearchStringsByPrefix(req)}
2023-03-26 09:37:06 +00:00
type SendCustomRequestRequest struct {
// The method name
Method string `json:"method"`
// JSON-serialized method parameters
Parameters string `json:"parameters"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a custom request; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) SendCustomRequest(req *SendCustomRequestRequest) (*CustomRequestResult, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCustomRequest",
},
Data: map[string]interface{}{
"method": req.Method,
"parameters": req.Parameters,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalCustomRequestResult(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type AnswerCustomQueryRequest struct {
// Identifier of a custom query
CustomQueryId JsonInt64 `json:"custom_query_id"`
// JSON-serialized answer to the query
Data string `json:"data"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Answers a custom query; for bots only
2018-10-16 20:32:57 +00:00
func (client *Client) AnswerCustomQuery(req *AnswerCustomQueryRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "answerCustomQuery",
},
Data: map[string]interface{}{
"custom_query_id": req.CustomQueryId,
"data": req.Data,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetAlarmRequest struct {
// Number of seconds before the function returns
Seconds float64 `json:"seconds"`
2018-10-16 20:32:57 +00:00
}
2020-11-30 09:33:47 +00:00
// Succeeds after a specified amount of time has passed. Can be called before initialization
2018-10-16 20:32:57 +00:00
func (client *Client) SetAlarm(req *SetAlarmRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAlarm",
},
Data: map[string]interface{}{
"seconds": req.Seconds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns information about existing countries. Can be called before authorization
func (client *Client) GetCountries() (*Countries, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCountries",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalCountries(result.Data)
2020-11-30 09:33:47 +00:00
}
2021-12-30 05:55:02 +00:00
// Uses the current IP address to find the current country. Returns two-letter ISO 3166-1 alpha-2 country code. Can be called before authorization
2018-08-30 14:55:42 +00:00
func (client *Client) GetCountryCode() (*Text, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCountryCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPhoneNumberInfoRequest struct {
// The phone number prefix
PhoneNumberPrefix string `json:"phone_number_prefix"`
2020-11-30 09:33:47 +00:00
}
// Returns information about a phone number by its prefix. Can be called before authorization
func (client *Client) GetPhoneNumberInfo(req *GetPhoneNumberInfoRequest) (*PhoneNumberInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPhoneNumberInfo",
},
Data: map[string]interface{}{
"phone_number_prefix": req.PhoneNumberPrefix,
},
})
if err != nil {
return nil, err
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalPhoneNumberInfo(result.Data)
2020-11-30 09:33:47 +00:00
}
2023-03-26 09:37:06 +00:00
type GetPhoneNumberInfoSyncRequest struct {
// A two-letter ISO 639-1 language code for country information localization
LanguageCode string `json:"language_code"`
// The phone number prefix
PhoneNumberPrefix string `json:"phone_number_prefix"`
2021-12-30 05:55:02 +00:00
}
// Returns information about a phone number by its prefix synchronously. getCountries must be called at least once after changing localization to the specified language if properly localized country information is expected. Can be called synchronously
func GetPhoneNumberInfoSync(req *GetPhoneNumberInfoSyncRequest) (*PhoneNumberInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getPhoneNumberInfoSync",
},
Data: map[string]interface{}{
"language_code": req.LanguageCode,
"phone_number_prefix": req.PhoneNumberPrefix,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPhoneNumberInfo(result.Data)
2021-12-30 05:55:02 +00:00
}
// deprecated
// Returns information about a phone number by its prefix synchronously. getCountries must be called at least once after changing localization to the specified language if properly localized country information is expected. Can be called synchronously
func (client *Client) GetPhoneNumberInfoSync(req *GetPhoneNumberInfoSyncRequest) (*PhoneNumberInfo, error) {
2023-03-26 09:37:06 +00:00
return GetPhoneNumberInfoSync(req)}
2023-03-26 09:37:06 +00:00
type GetDeepLinkInfoRequest struct {
// The link
Link string `json:"link"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// 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
2018-10-16 20:32:57 +00:00
func (client *Client) GetDeepLinkInfo(req *GetDeepLinkInfoRequest) (*DeepLinkInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDeepLinkInfo",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalDeepLinkInfo(result.Data)
2018-10-23 12:38:10 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns application config, provided by the server. Can be called before authorization
func (client *Client) GetApplicationConfig() (JsonValue, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getApplicationConfig",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeJsonValueNull:
return UnmarshalJsonValueNull(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueBoolean:
return UnmarshalJsonValueBoolean(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueNumber:
return UnmarshalJsonValueNumber(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueString:
return UnmarshalJsonValueString(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueArray:
return UnmarshalJsonValueArray(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeJsonValueObject:
return UnmarshalJsonValueObject(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2019-06-07 10:56:06 +00:00
}
2023-03-26 09:37:06 +00:00
type AddApplicationChangelogRequest struct {
// The previous application version
PreviousApplicationVersion string `json:"previous_application_version"`
2023-03-11 11:13:56 +00:00
}
2023-07-24 18:35:55 +00:00
// Adds server-provided application changelog as messages to the chat 777000 (Telegram) or as a stories; for official applications only. Returns a 404 error if nothing changed
2023-03-11 11:13:56 +00:00
func (client *Client) AddApplicationChangelog(req *AddApplicationChangelogRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addApplicationChangelog",
},
Data: map[string]interface{}{
"previous_application_version": req.PreviousApplicationVersion,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SaveApplicationLogEventRequest struct {
// Event type
Type string `json:"type"`
// Optional chat identifier, associated with the event
ChatId int64 `json:"chat_id"`
// The log event data
Data JsonValue `json:"data"`
2019-06-07 10:56:06 +00:00
}
// Saves application log event on the server. Can be called before authorization
func (client *Client) SaveApplicationLogEvent(req *SaveApplicationLogEventRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "saveApplicationLogEvent",
},
Data: map[string]interface{}{
"type": req.Type,
"chat_id": req.ChatId,
"data": req.Data,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2023-02-04 23:22:52 +00:00
}
2023-03-11 11:13:56 +00:00
// Returns the link for downloading official Telegram application to be used when the current user invites friends to Telegram
func (client *Client) GetApplicationDownloadLink() (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getApplicationDownloadLink",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
}
type AddProxyRequest struct {
2023-09-16 07:09:40 +00:00
// Proxy server domain or IP address
2023-03-26 09:37:06 +00:00
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// Pass true to immediately enable the proxy
Enable bool `json:"enable"`
// Proxy type
Type ProxyType `json:"type"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Adds a proxy server for network requests. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) AddProxy(req *AddProxyRequest) (*Proxy, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addProxy",
},
Data: map[string]interface{}{
"server": req.Server,
"port": req.Port,
"enable": req.Enable,
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalProxy(result.Data)
}
type EditProxyRequest struct {
// Proxy identifier
ProxyId int32 `json:"proxy_id"`
2023-09-16 07:09:40 +00:00
// Proxy server domain or IP address
2023-03-26 09:37:06 +00:00
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// Pass true to immediately enable the proxy
Enable bool `json:"enable"`
// Proxy type
Type ProxyType `json:"type"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Edits an existing proxy server for network requests. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) EditProxy(req *EditProxyRequest) (*Proxy, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "editProxy",
},
Data: map[string]interface{}{
"proxy_id": req.ProxyId,
"server": req.Server,
"port": req.Port,
"enable": req.Enable,
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalProxy(result.Data)
}
type EnableProxyRequest struct {
// Proxy identifier
ProxyId int32 `json:"proxy_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) EnableProxy(req *EnableProxyRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "enableProxy",
},
Data: map[string]interface{}{
"proxy_id": req.ProxyId,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
// Disables the currently enabled proxy. Can be called before authorization
func (client *Client) DisableProxy() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "disableProxy",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type RemoveProxyRequest struct {
// Proxy identifier
ProxyId int32 `json:"proxy_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Removes a proxy server. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) RemoveProxy(req *RemoveProxyRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeProxy",
},
Data: map[string]interface{}{
"proxy_id": req.ProxyId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns list of proxies that are currently set up. Can be called before authorization
func (client *Client) GetProxies() (*Proxies, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getProxies",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalProxies(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type GetProxyLinkRequest struct {
// Proxy identifier
ProxyId int32 `json:"proxy_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns an HTTPS link, which can be used to add a proxy. Available only for SOCKS5 and MTProto proxies. Can be called before authorization
2021-12-30 05:55:02 +00:00
func (client *Client) GetProxyLink(req *GetProxyLinkRequest) (*HttpUrl, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getProxyLink",
},
Data: map[string]interface{}{
"proxy_id": req.ProxyId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalHttpUrl(result.Data)
2018-09-05 21:45:29 +00:00
}
2023-03-26 09:37:06 +00:00
type PingProxyRequest struct {
// Proxy identifier. Use 0 to ping a Telegram server without a proxy
ProxyId int32 `json:"proxy_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Computes time needed to receive a response from a Telegram server through a proxy. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) PingProxy(req *PingProxyRequest) (*Seconds, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "pingProxy",
},
Data: map[string]interface{}{
"proxy_id": req.ProxyId,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalSeconds(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type SetLogStreamRequest struct {
// New log stream
LogStream LogStream `json:"log_stream"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Sets new log stream for internal logging of TDLib. Can be called synchronously
func SetLogStream(req *SetLogStreamRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "setLogStream",
},
Data: map[string]interface{}{
"log_stream": req.LogStream,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Sets new log stream for internal logging of TDLib. Can be called synchronously
func (client *Client) SetLogStream(req *SetLogStreamRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
return SetLogStream(req)}
2020-11-30 09:33:47 +00:00
// Returns information about currently used log stream for internal logging of TDLib. Can be called synchronously
func GetLogStream() (LogStream, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getLogStream",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeLogStreamDefault:
return UnmarshalLogStreamDefault(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeLogStreamFile:
return UnmarshalLogStreamFile(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeLogStreamEmpty:
return UnmarshalLogStreamEmpty(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2019-06-07 10:56:06 +00:00
}
// deprecated
// Returns information about currently used log stream for internal logging of TDLib. Can be called synchronously
func (client *Client) GetLogStream() (LogStream, error) {
2023-03-26 09:37:06 +00:00
return GetLogStream()}
2023-03-26 09:37:06 +00:00
type SetLogVerbosityLevelRequest struct {
// New value of the verbosity level for logging. Value 0 corresponds to fatal errors, value 1 corresponds to errors, value 2 corresponds to warnings and debug warnings, value 3 corresponds to informational, value 4 corresponds to debug, value 5 corresponds to verbose debug, value greater than 5 and up to 1023 can be used to enable even more logging
NewVerbosityLevel int32 `json:"new_verbosity_level"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Sets the verbosity level of the internal logging of TDLib. Can be called synchronously
func SetLogVerbosityLevel(req *SetLogVerbosityLevelRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "setLogVerbosityLevel",
},
Data: map[string]interface{}{
"new_verbosity_level": req.NewVerbosityLevel,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Sets the verbosity level of the internal logging of TDLib. Can be called synchronously
func (client *Client) SetLogVerbosityLevel(req *SetLogVerbosityLevelRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
return SetLogVerbosityLevel(req)}
2020-11-30 09:33:47 +00:00
// Returns current verbosity level of the internal logging of TDLib. Can be called synchronously
func GetLogVerbosityLevel() (*LogVerbosityLevel, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getLogVerbosityLevel",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLogVerbosityLevel(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Returns current verbosity level of the internal logging of TDLib. Can be called synchronously
func (client *Client) GetLogVerbosityLevel() (*LogVerbosityLevel, error) {
2023-03-26 09:37:06 +00:00
return GetLogVerbosityLevel()}
2020-11-30 09:33:47 +00:00
// Returns list of available TDLib internal log tags, for example, ["actor", "binlog", "connections", "notifications", "proxy"]. Can be called synchronously
func GetLogTags() (*LogTags, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getLogTags",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLogTags(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Returns list of available TDLib internal log tags, for example, ["actor", "binlog", "connections", "notifications", "proxy"]. Can be called synchronously
func (client *Client) GetLogTags() (*LogTags, error) {
2023-03-26 09:37:06 +00:00
return GetLogTags()}
2023-03-26 09:37:06 +00:00
type SetLogTagVerbosityLevelRequest struct {
// Logging tag to change verbosity level
Tag string `json:"tag"`
// New verbosity level; 1-1024
NewVerbosityLevel int32 `json:"new_verbosity_level"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Sets the verbosity level for a specified TDLib internal log tag. Can be called synchronously
func SetLogTagVerbosityLevel(req *SetLogTagVerbosityLevelRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "setLogTagVerbosityLevel",
},
Data: map[string]interface{}{
"tag": req.Tag,
"new_verbosity_level": req.NewVerbosityLevel,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Sets the verbosity level for a specified TDLib internal log tag. Can be called synchronously
func (client *Client) SetLogTagVerbosityLevel(req *SetLogTagVerbosityLevelRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
return SetLogTagVerbosityLevel(req)}
2023-03-26 09:37:06 +00:00
type GetLogTagVerbosityLevelRequest struct {
// Logging tag to change verbosity level
Tag string `json:"tag"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns current verbosity level for a specified TDLib internal log tag. Can be called synchronously
func GetLogTagVerbosityLevel(req *GetLogTagVerbosityLevelRequest) (*LogVerbosityLevel, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "getLogTagVerbosityLevel",
},
Data: map[string]interface{}{
"tag": req.Tag,
},
})
if err != nil {
return nil, err
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalLogVerbosityLevel(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Returns current verbosity level for a specified TDLib internal log tag. Can be called synchronously
func (client *Client) GetLogTagVerbosityLevel(req *GetLogTagVerbosityLevelRequest) (*LogVerbosityLevel, error) {
2023-03-26 09:37:06 +00:00
return GetLogTagVerbosityLevel(req)}
2023-03-26 09:37:06 +00:00
type AddLogMessageRequest struct {
// The minimum verbosity level needed for the message to be logged; 0-1023
VerbosityLevel int32 `json:"verbosity_level"`
// Text of a message to log
Text string `json:"text"`
2019-06-07 10:56:06 +00:00
}
2020-11-30 09:33:47 +00:00
// Adds a message to TDLib internal log. Can be called synchronously
func AddLogMessage(req *AddLogMessageRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "addLogMessage",
},
Data: map[string]interface{}{
"verbosity_level": req.VerbosityLevel,
"text": req.Text,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2019-06-07 10:56:06 +00:00
}
// deprecated
// Adds a message to TDLib internal log. Can be called synchronously
func (client *Client) AddLogMessage(req *AddLogMessageRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
return AddLogMessage(req)}
2023-03-26 09:37:06 +00:00
type GetUserSupportInfoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
2022-09-18 01:34:29 +00:00
}
// Returns support information for the given user; for Telegram support only
func (client *Client) GetUserSupportInfo(req *GetUserSupportInfoRequest) (*UserSupportInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getUserSupportInfo",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalUserSupportInfo(result.Data)
2022-09-18 01:34:29 +00:00
}
2023-03-26 09:37:06 +00:00
type SetUserSupportInfoRequest struct {
// User identifier
UserId int64 `json:"user_id"`
// New information message
Message *FormattedText `json:"message"`
2022-09-18 01:34:29 +00:00
}
// Sets support information for the given user; for Telegram support only
func (client *Client) SetUserSupportInfo(req *SetUserSupportInfoRequest) (*UserSupportInfo, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setUserSupportInfo",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"message": req.Message,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUserSupportInfo(result.Data)
}
// Returns localized name of the Telegram support user; for Telegram support only
func (client *Client) GetSupportName() (*Text, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSupportName",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
2022-09-18 01:34:29 +00:00
}
2019-06-07 10:56:06 +00:00
// Does nothing; for testing only. This is an offline method. Can be called before authorization
2018-08-30 14:55:42 +00:00
func (client *Client) TestCallEmpty() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallEmpty",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallStringRequest struct {
// String to return
X string `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received string; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallString(req *TestCallStringRequest) (*TestString, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallString",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestString(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallBytesRequest struct {
// Bytes to return
X []byte `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received bytes; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallBytes(req *TestCallBytesRequest) (*TestBytes, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallBytes",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestBytes(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallVectorIntRequest struct {
// Vector of numbers to return
X []int32 `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received vector of numbers; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallVectorInt(req *TestCallVectorIntRequest) (*TestVectorInt, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallVectorInt",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestVectorInt(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallVectorIntObjectRequest struct {
// Vector of objects to return
X []*TestInt `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received vector of objects containing a number; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallVectorIntObject(req *TestCallVectorIntObjectRequest) (*TestVectorIntObject, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallVectorIntObject",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestVectorIntObject(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallVectorStringRequest struct {
// Vector of strings to return
X []string `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received vector of strings; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallVectorString(req *TestCallVectorStringRequest) (*TestVectorString, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallVectorString",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestVectorString(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestCallVectorStringObjectRequest struct {
// Vector of objects to return
X []*TestString `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the received vector of objects containing a string; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestCallVectorStringObject(req *TestCallVectorStringObjectRequest) (*TestVectorStringObject, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testCallVectorStringObject",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestVectorStringObject(result.Data)
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestSquareIntRequest struct {
// Number to square
X int32 `json:"x"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Returns the squared received number; for testing only. This is an offline method. Can be called before authorization
2018-10-16 20:32:57 +00:00
func (client *Client) TestSquareInt(req *TestSquareIntRequest) (*TestInt, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testSquareInt",
},
Data: map[string]interface{}{
"x": req.X,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalTestInt(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
// Sends a simple network request to the Telegram servers; for testing only. Can be called before authorization
2018-08-30 14:55:42 +00:00
func (client *Client) TestNetwork() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testNetwork",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type TestProxyRequest struct {
2023-09-16 07:09:40 +00:00
// Proxy server domain or IP address
2023-03-26 09:37:06 +00:00
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// Proxy type
Type ProxyType `json:"type"`
// Identifier of a datacenter with which to test connection
DcId int32 `json:"dc_id"`
// The maximum overall timeout for the request
Timeout float64 `json:"timeout"`
2019-09-10 12:36:54 +00:00
}
// Sends a simple network request to the Telegram servers via proxy; for testing only. Can be called before authorization
func (client *Client) TestProxy(req *TestProxyRequest) (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testProxy",
},
Data: map[string]interface{}{
"server": req.Server,
"port": req.Port,
"type": req.Type,
"dc_id": req.DcId,
"timeout": req.Timeout,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2019-09-10 12:36:54 +00:00
}
2018-08-30 14:55:42 +00:00
// Forces an updates.getDifference call to the Telegram servers; for testing only
func (client *Client) TestGetDifference() (*Ok, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testGetDifference",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
// Does nothing and ensures that the Update object is used; for testing only. This is an offline method. Can be called before authorization
2018-08-30 14:55:42 +00:00
func (client *Client) TestUseUpdate() (Update, error) {
2023-03-26 09:37:06 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testUseUpdate",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
switch result.Type {
case TypeUpdateAuthorizationState:
return UnmarshalUpdateAuthorizationState(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewMessage:
return UnmarshalUpdateNewMessage(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageSendAcknowledged:
return UnmarshalUpdateMessageSendAcknowledged(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageSendSucceeded:
return UnmarshalUpdateMessageSendSucceeded(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageSendFailed:
return UnmarshalUpdateMessageSendFailed(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageContent:
return UnmarshalUpdateMessageContent(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageEdited:
return UnmarshalUpdateMessageEdited(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageIsPinned:
return UnmarshalUpdateMessageIsPinned(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageInteractionInfo:
return UnmarshalUpdateMessageInteractionInfo(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageContentOpened:
return UnmarshalUpdateMessageContentOpened(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageMentionRead:
return UnmarshalUpdateMessageMentionRead(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageUnreadReactions:
return UnmarshalUpdateMessageUnreadReactions(result.Data)
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateMessageLiveLocationViewed:
return UnmarshalUpdateMessageLiveLocationViewed(result.Data)
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewChat:
return UnmarshalUpdateNewChat(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatTitle:
return UnmarshalUpdateChatTitle(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatPhoto:
return UnmarshalUpdateChatPhoto(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatPermissions:
return UnmarshalUpdateChatPermissions(result.Data)
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatLastMessage:
return UnmarshalUpdateChatLastMessage(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatPosition:
return UnmarshalUpdateChatPosition(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatReadInbox:
return UnmarshalUpdateChatReadInbox(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatReadOutbox:
return UnmarshalUpdateChatReadOutbox(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatActionBar:
return UnmarshalUpdateChatActionBar(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatAvailableReactions:
return UnmarshalUpdateChatAvailableReactions(result.Data)
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatDraftMessage:
return UnmarshalUpdateChatDraftMessage(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatMessageSender:
return UnmarshalUpdateChatMessageSender(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatMessageAutoDeleteTime:
return UnmarshalUpdateChatMessageAutoDeleteTime(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatNotificationSettings:
return UnmarshalUpdateChatNotificationSettings(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatPendingJoinRequests:
return UnmarshalUpdateChatPendingJoinRequests(result.Data)
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatReplyMarkup:
return UnmarshalUpdateChatReplyMarkup(result.Data)
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
case TypeUpdateChatBackground:
return UnmarshalUpdateChatBackground(result.Data)
2023-03-26 09:37:06 +00:00
case TypeUpdateChatTheme:
return UnmarshalUpdateChatTheme(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatUnreadMentionCount:
return UnmarshalUpdateChatUnreadMentionCount(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatUnreadReactionCount:
return UnmarshalUpdateChatUnreadReactionCount(result.Data)
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatVideoChat:
return UnmarshalUpdateChatVideoChat(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatDefaultDisableNotification:
return UnmarshalUpdateChatDefaultDisableNotification(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatHasProtectedContent:
return UnmarshalUpdateChatHasProtectedContent(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatIsTranslatable:
return UnmarshalUpdateChatIsTranslatable(result.Data)
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatIsMarkedAsUnread:
return UnmarshalUpdateChatIsMarkedAsUnread(result.Data)
2021-12-30 05:55:02 +00:00
2023-08-15 18:28:13 +00:00
case TypeUpdateChatBlockList:
return UnmarshalUpdateChatBlockList(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatHasScheduledMessages:
return UnmarshalUpdateChatHasScheduledMessages(result.Data)
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
case TypeUpdateChatFolders:
return UnmarshalUpdateChatFolders(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatOnlineMemberCount:
return UnmarshalUpdateChatOnlineMemberCount(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateForumTopicInfo:
return UnmarshalUpdateForumTopicInfo(result.Data)
2022-11-07 18:50:52 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateScopeNotificationSettings:
return UnmarshalUpdateScopeNotificationSettings(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNotification:
return UnmarshalUpdateNotification(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNotificationGroup:
return UnmarshalUpdateNotificationGroup(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateActiveNotifications:
return UnmarshalUpdateActiveNotifications(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateHavePendingNotifications:
return UnmarshalUpdateHavePendingNotifications(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateDeleteMessages:
return UnmarshalUpdateDeleteMessages(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatAction:
return UnmarshalUpdateChatAction(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUserStatus:
return UnmarshalUpdateUserStatus(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUser:
return UnmarshalUpdateUser(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateBasicGroup:
return UnmarshalUpdateBasicGroup(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSupergroup:
return UnmarshalUpdateSupergroup(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSecretChat:
return UnmarshalUpdateSecretChat(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUserFullInfo:
return UnmarshalUpdateUserFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateBasicGroupFullInfo:
return UnmarshalUpdateBasicGroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSupergroupFullInfo:
return UnmarshalUpdateSupergroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateServiceNotification:
return UnmarshalUpdateServiceNotification(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFile:
return UnmarshalUpdateFile(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileGenerationStart:
return UnmarshalUpdateFileGenerationStart(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileGenerationStop:
return UnmarshalUpdateFileGenerationStop(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileDownloads:
return UnmarshalUpdateFileDownloads(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileAddedToDownloads:
return UnmarshalUpdateFileAddedToDownloads(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileDownload:
return UnmarshalUpdateFileDownload(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFileRemovedFromDownloads:
return UnmarshalUpdateFileRemovedFromDownloads(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateCall:
return UnmarshalUpdateCall(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateGroupCall:
return UnmarshalUpdateGroupCall(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateGroupCallParticipant:
return UnmarshalUpdateGroupCallParticipant(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewCallSignalingData:
return UnmarshalUpdateNewCallSignalingData(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUserPrivacySettingRules:
return UnmarshalUpdateUserPrivacySettingRules(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUnreadMessageCount:
return UnmarshalUpdateUnreadMessageCount(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUnreadChatCount:
return UnmarshalUpdateUnreadChatCount(result.Data)
2018-08-30 14:55:42 +00:00
2023-07-24 18:35:55 +00:00
case TypeUpdateStory:
return UnmarshalUpdateStory(result.Data)
case TypeUpdateStoryDeleted:
return UnmarshalUpdateStoryDeleted(result.Data)
2023-08-15 18:28:13 +00:00
case TypeUpdateStorySendSucceeded:
return UnmarshalUpdateStorySendSucceeded(result.Data)
case TypeUpdateStorySendFailed:
return UnmarshalUpdateStorySendFailed(result.Data)
2023-07-24 18:35:55 +00:00
case TypeUpdateChatActiveStories:
return UnmarshalUpdateChatActiveStories(result.Data)
case TypeUpdateStoryListChatCount:
return UnmarshalUpdateStoryListChatCount(result.Data)
2023-08-15 18:28:13 +00:00
case TypeUpdateStoryStealthMode:
return UnmarshalUpdateStoryStealthMode(result.Data)
2023-03-26 09:37:06 +00:00
case TypeUpdateOption:
return UnmarshalUpdateOption(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateStickerSet:
return UnmarshalUpdateStickerSet(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateInstalledStickerSets:
return UnmarshalUpdateInstalledStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateTrendingStickerSets:
return UnmarshalUpdateTrendingStickerSets(result.Data)
2019-09-10 12:36:54 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateRecentStickers:
return UnmarshalUpdateRecentStickers(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateFavoriteStickers:
return UnmarshalUpdateFavoriteStickers(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSavedAnimations:
return UnmarshalUpdateSavedAnimations(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSavedNotificationSounds:
return UnmarshalUpdateSavedNotificationSounds(result.Data)
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSelectedBackground:
return UnmarshalUpdateSelectedBackground(result.Data)
2018-09-05 21:45:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatThemes:
return UnmarshalUpdateChatThemes(result.Data)
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateLanguagePackStrings:
return UnmarshalUpdateLanguagePackStrings(result.Data)
2022-02-06 18:36:17 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateConnectionState:
return UnmarshalUpdateConnectionState(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateTermsOfService:
return UnmarshalUpdateTermsOfService(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateUsersNearby:
return UnmarshalUpdateUsersNearby(result.Data)
2020-11-30 09:33:47 +00:00
2023-09-16 07:09:40 +00:00
case TypeUpdateUnconfirmedSession:
return UnmarshalUpdateUnconfirmedSession(result.Data)
2023-03-26 09:37:06 +00:00
case TypeUpdateAttachmentMenuBots:
return UnmarshalUpdateAttachmentMenuBots(result.Data)
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateWebAppMessageSent:
return UnmarshalUpdateWebAppMessageSent(result.Data)
2022-04-24 20:33:39 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateActiveEmojiReactions:
return UnmarshalUpdateActiveEmojiReactions(result.Data)
2022-09-18 01:34:29 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateDefaultReactionType:
return UnmarshalUpdateDefaultReactionType(result.Data)
2020-11-30 09:33:47 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateDiceEmojis:
return UnmarshalUpdateDiceEmojis(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateAnimatedEmojiMessageClicked:
return UnmarshalUpdateAnimatedEmojiMessageClicked(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateAnimationSearchParameters:
return UnmarshalUpdateAnimationSearchParameters(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateSuggestedActions:
return UnmarshalUpdateSuggestedActions(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateAddChatMembersPrivacyForbidden:
return UnmarshalUpdateAddChatMembersPrivacyForbidden(result.Data)
2023-03-11 11:13:56 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateAutosaveSettings:
return UnmarshalUpdateAutosaveSettings(result.Data)
2023-02-04 22:54:46 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewInlineQuery:
return UnmarshalUpdateNewInlineQuery(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewChosenInlineResult:
return UnmarshalUpdateNewChosenInlineResult(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewCallbackQuery:
return UnmarshalUpdateNewCallbackQuery(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewInlineCallbackQuery:
return UnmarshalUpdateNewInlineCallbackQuery(result.Data)
2018-08-30 14:55:42 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewShippingQuery:
return UnmarshalUpdateNewShippingQuery(result.Data)
2019-06-07 10:56:06 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewPreCheckoutQuery:
return UnmarshalUpdateNewPreCheckoutQuery(result.Data)
2020-02-03 12:56:20 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewCustomEvent:
return UnmarshalUpdateNewCustomEvent(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewCustomQuery:
return UnmarshalUpdateNewCustomQuery(result.Data)
2021-12-30 05:55:02 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdatePoll:
return UnmarshalUpdatePoll(result.Data)
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdatePollAnswer:
return UnmarshalUpdatePollAnswer(result.Data)
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateChatMember:
return UnmarshalUpdateChatMember(result.Data)
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
case TypeUpdateNewChatJoinRequest:
return UnmarshalUpdateNewChatJoinRequest(result.Data)
2022-03-13 04:04:12 +00:00
2023-03-26 09:37:06 +00:00
default:
return nil, errors.New("invalid type")
}
2018-08-30 14:55:42 +00:00
}
2023-03-26 09:37:06 +00:00
type TestReturnErrorRequest struct {
// The error to be returned
Error *Error `json:"error"`
2019-09-10 12:36:54 +00:00
}
2020-11-30 09:33:47 +00:00
// Returns the specified error and ensures that the Error object is used; for testing only. Can be called synchronously
func TestReturnError(req *TestReturnErrorRequest) (*Error, error) {
2023-03-26 09:37:06 +00:00
result, err := Execute(Request{
meta: meta{
Type: "testReturnError",
},
Data: map[string]interface{}{
"error": req.Error,
},
})
if err != nil {
return nil, err
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
2023-03-26 09:37:06 +00:00
return UnmarshalError(result.Data)
2018-08-30 14:55:42 +00:00
}
// deprecated
// Returns the specified error and ensures that the Error object is used; for testing only. Can be called synchronously
func (client *Client) TestReturnError(req *TestReturnErrorRequest) (*Error, error) {
2023-03-26 09:37:06 +00:00
return TestReturnError(req)}