go-tdlib/client/function.go

10554 lines
284 KiB
Go
Raw Normal View History

2018-08-30 14:55:42 +00:00
// AUTOGENERATED
package client
import (
2018-10-23 12:38:10 +00:00
"errors"
2018-08-30 14:55:42 +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
func (client *Client) GetAuthorizationState() (AuthorizationState, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getAuthorizationState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypeAuthorizationStateWaitTdlibParameters:
return UnmarshalAuthorizationStateWaitTdlibParameters(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateWaitEncryptionKey:
return UnmarshalAuthorizationStateWaitEncryptionKey(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateWaitPhoneNumber:
return UnmarshalAuthorizationStateWaitPhoneNumber(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateWaitCode:
return UnmarshalAuthorizationStateWaitCode(result.Data)
2018-08-30 14:55:42 +00:00
2020-02-03 12:56:20 +00:00
case TypeAuthorizationStateWaitOtherDeviceConfirmation:
return UnmarshalAuthorizationStateWaitOtherDeviceConfirmation(result.Data)
2019-09-10 12:36:54 +00:00
case TypeAuthorizationStateWaitRegistration:
return UnmarshalAuthorizationStateWaitRegistration(result.Data)
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateWaitPassword:
return UnmarshalAuthorizationStateWaitPassword(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateReady:
return UnmarshalAuthorizationStateReady(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateLoggingOut:
return UnmarshalAuthorizationStateLoggingOut(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateClosing:
return UnmarshalAuthorizationStateClosing(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeAuthorizationStateClosed:
return UnmarshalAuthorizationStateClosed(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetTdlibParametersRequest struct {
// Parameters
Parameters *TdlibParameters `json:"parameters"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setTdlibParameters",
},
Data: map[string]interface{}{
"parameters": req.Parameters,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckDatabaseEncryptionKeyRequest struct {
// Encryption key to check or set up
EncryptionKey []byte `json:"encryption_key"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks the database encryption key for correctness. Works only when the current authorization state is authorizationStateWaitEncryptionKey
2018-10-16 20:32:57 +00:00
func (client *Client) CheckDatabaseEncryptionKey(req *CheckDatabaseEncryptionKeyRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkDatabaseEncryptionKey",
},
Data: map[string]interface{}{
"encryption_key": req.EncryptionKey,
},
})
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"`
2019-09-10 12:36:54 +00:00
// Settings for the authentication of the user's phone number
Settings *PhoneNumberAuthenticationSettings `json:"settings"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +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 authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword
2018-10-16 20:32:57 +00:00
func (client *Client) SetAuthenticationPhoneNumber(req *SetAuthenticationPhoneNumberRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setAuthenticationPhoneNumber",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"phone_number": req.PhoneNumber,
"settings": req.Settings,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Re-sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode and the next_code_type of the result is not null
func (client *Client) ResendAuthenticationCode() (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckAuthenticationCodeRequest struct {
// The verification code received via SMS, Telegram message, phone call, or flash call
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkAuthenticationCode",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2020-02-03 12:56:20 +00:00
type RequestQrCodeAuthenticationRequest struct {
// List of user identifiers of other users currently using the client
OtherUserIds []int32 `json:"other_user_ids"`
}
// Requests QR code authentication by scanning a QR code on another logged in device. Works only when the current authorization state is authorizationStateWaitPhoneNumber
func (client *Client) RequestQrCodeAuthentication(req *RequestQrCodeAuthenticationRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "requestQrCodeAuthentication",
},
Data: map[string]interface{}{
"other_user_ids": req.OtherUserIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2019-09-10 12:36:54 +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"`
}
// Finishes user registration. Works only when the current authorization state is authorizationStateWaitRegistration
func (client *Client) RegisterUser(req *RegisterUserRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "registerUser",
},
Data: map[string]interface{}{
2018-10-23 12:38:10 +00:00
"first_name": req.FirstName,
"last_name": req.LastName,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckAuthenticationPasswordRequest struct {
// The password to check
Password string `json:"password"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks the authentication 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Requests to send a password recovery code to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword
func (client *Client) RequestAuthenticationPasswordRecovery() (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type RecoverAuthenticationPasswordRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Recovers the password with a password recovery code sent to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword
2018-10-16 20:32:57 +00:00
func (client *Client) RecoverAuthenticationPassword(req *RecoverAuthenticationPasswordRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "recoverAuthenticationPassword",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +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
func (client *Client) Close() (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +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
func (client *Client) Destroy() (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +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"`
}
// Confirms QR code authentication on another device. Returns created session on success
func (client *Client) ConfirmQrCodeAuthentication(req *ConfirmQrCodeAuthenticationRequest) (*Session, error) {
result, err := client.Send(Request{
meta: meta{
Type: "confirmQrCodeAuthentication",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalSession(result.Data)
}
// Returns all updates needed to restore current TDLib state, i.e. all actual UpdateAuthorizationState/UpdateUser/UpdateNewChat and others. This is especially useful if TDLib is run in a separate process. This is an offline method. Can be called before authorization
2019-06-07 10:56:06 +00:00
func (client *Client) GetCurrentState() (*Updates, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getCurrentState",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalUpdates(result.Data)
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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 password of the user
OldPassword string `json:"old_password"`
// New password of the user; may be empty to remove the password
NewPassword string `json:"new_password"`
// New password hint; may be empty
NewHint string `json:"new_hint"`
// Pass true if the recovery email address should be changed
SetRecoveryEmailAddress bool `json:"set_recovery_email_address"`
// New recovery email address; may be empty
NewRecoveryEmailAddress string `json:"new_recovery_email_address"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Changes the password for 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
2018-10-16 20:32:57 +00:00
func (client *Client) SetPassword(req *SetPasswordRequest) (*PasswordState, error) {
2018-10-23 12:38:10 +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 GetRecoveryEmailAddressRequest struct {
// The 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalRecoveryEmailAddress(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetRecoveryEmailAddressRequest struct {
// 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) {
2018-10-23 12:38:10 +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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type CheckRecoveryEmailAddressCodeRequest struct {
// Verification code
Code string `json:"code"`
}
// Checks the 2-step verification recovery email address verification code
func (client *Client) CheckRecoveryEmailAddressCode(req *CheckRecoveryEmailAddressCodeRequest) (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkRecoveryEmailAddressCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
// Resends the 2-step verification recovery email address verification code
func (client *Client) ResendRecoveryEmailAddressCode() (*PasswordState, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resendRecoveryEmailAddressCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPasswordState(result.Data)
}
2018-08-30 14:55:42 +00:00
// Requests to send a 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type RecoverPasswordRequest struct {
// Recovery code to check
RecoveryCode string `json:"recovery_code"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Recovers the 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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "recoverPassword",
},
Data: map[string]interface{}{
"recovery_code": req.RecoveryCode,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalPasswordState(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateTemporaryPasswordRequest struct {
// Persistent user password
Password string `json:"password"`
// Time during which the temporary password will be valid, in seconds; should be between 60 and 86400
ValidFor int32 `json:"valid_for"`
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) {
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTemporaryPasswordState(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns the current user
func (client *Client) GetMe() (*User, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetUserRequest struct {
// User identifier
UserId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetUserFullInfoRequest struct {
// User identifier
UserId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUserFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetBasicGroupRequest struct {
// Basic group identifier
BasicGroupId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalBasicGroup(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetBasicGroupFullInfoRequest struct {
// Basic group identifier
BasicGroupId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalBasicGroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetSupergroupRequest struct {
// Supergroup or channel identifier
SupergroupId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalSupergroup(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetSupergroupFullInfoRequest struct {
// Supergroup or channel identifier
SupergroupId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalSupergroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalSecretChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessage(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56: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"`
}
// Returns information about a message, if it is available locally without sending network request. This is an offline request
func (client *Client) GetMessageLocally(req *GetMessageLocallyRequest) (*Message, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLocally",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessage(result.Data)
}
2018-10-23 12:38:10 +00:00
type GetRepliedMessageRequest struct {
// Identifier of the chat the message belongs to
ChatId int64 `json:"chat_id"`
// Identifier of the message reply to which get
MessageId int64 `json:"message_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a message that is replied by given message
2018-10-16 20:32:57 +00:00
func (client *Client) GetRepliedMessage(req *GetRepliedMessageRequest) (*Message, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessage(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
// Returns information about a pinned chat message
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatPinnedMessage(req *GetChatPinnedMessageRequest) (*Message, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessage(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessages(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalFile(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetRemoteFileRequest struct {
// Remote identifier of the file to get
RemoteFileId string `json:"remote_file_id"`
// File type, if known
FileType FileType `json:"file_type"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns information about a file by its remote ID; this is an offline request. Can be used to register a URL as a file for further uploading, or sending as a message. 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 client
2018-10-16 20:32:57 +00:00
func (client *Client) GetRemoteFile(req *GetRemoteFileRequest) (*File, error) {
2018-10-23 12:38:10 +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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type GetChatsRequest struct {
2020-02-03 12:56:20 +00:00
// The chat list in which to return chats
ChatList ChatList `json:"chat_list"`
2018-10-23 12:38:10 +00:00
// Chat order to return chats from
OffsetOrder JsonInt64 `json:"offset_order"`
// Chat identifier to return chats from
OffsetChatId int64 `json:"offset_chat_id"`
// The maximum number of chats to be returned. It is possible that fewer chats than the limit are returned even if the end of the list is not reached
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns an ordered list of chats in a chat list. Chats are sorted by the pair (order, chat_id) in decreasing order. (For example, to get a list of chats from the beginning, the offset_order should be equal to a biggest signed 64-bit number 9223372036854775807 == 2^63 - 1). For optimal performance the number of returned chats is chosen by the library
2018-10-16 20:32:57 +00:00
func (client *Client) GetChats(req *GetChatsRequest) (*Chats, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChats",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"chat_list": req.ChatList,
2018-10-23 12:38:10 +00:00
"offset_order": req.OffsetOrder,
"offset_chat_id": req.OffsetChatId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchPublicChatRequest struct {
// Username to be resolved
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchPublicChatsRequest 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 public chats by looking for specified query in their username and title. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results
2018-10-16 20:32:57 +00:00
func (client *Client) SearchPublicChats(req *SearchPublicChatsRequest) (*Chats, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchChatsRequest struct {
// Query to search for. If the query is empty, returns up to 20 recently found chats
Query string `json:"query"`
2020-02-03 12:56:20 +00:00
// The maximum number of chats to be returned
2018-10-23 12:38:10 +00:00
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 title and username of already known chats, this is an offline request. Returns chats in the order seen in the chat list
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChats(req *SearchChatsRequest) (*Chats, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchChatsOnServerRequest struct {
// Query to search for
Query string `json:"query"`
2020-02-03 12:56:20 +00:00
// The maximum number of chats to be returned
2018-10-23 12:38:10 +00:00
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 title and username of already known chats via request to the server. Returns chats in the order seen in the chat list
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChatsOnServer(req *SearchChatsOnServerRequest) (*Chats, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type SearchChatsNearbyRequest struct {
// Current user location
Location *Location `json:"location"`
}
// Returns a list of users and location-based supergroups nearby. The list of users nearby will be updated for 60 seconds after the request by the updates updateUsersNearby. The request should be sent again every 25 seconds with adjusted location to not miss new chats
func (client *Client) SearchChatsNearby(req *SearchChatsNearbyRequest) (*ChatsNearby, error) {
result, err := client.Send(Request{
meta: meta{
Type: "searchChatsNearby",
},
Data: map[string]interface{}{
"location": req.Location,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChatsNearby(result.Data)
}
2018-10-23 12:38:10 +00:00
type GetTopChatsRequest struct {
// Category of chats to be returned
Category TopChatCategory `json:"category"`
2020-02-03 12:56:20 +00:00
// The maximum number of chats to be returned; up to 30
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a 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) GetTopChats(req *GetTopChatsRequest) (*Chats, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckChatUsernameRequest struct {
// Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created
2019-06-07 10:56:06 +00:00
ChatId int64 `json:"chat_id"`
2018-10-23 12:38:10 +00:00
// 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypeCheckChatUsernameResultOk:
return UnmarshalCheckChatUsernameResultOk(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeCheckChatUsernameResultUsernameInvalid:
return UnmarshalCheckChatUsernameResultUsernameInvalid(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeCheckChatUsernameResultUsernameOccupied:
return UnmarshalCheckChatUsernameResultUsernameOccupied(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeCheckChatUsernameResultPublicChatsTooMuch:
return UnmarshalCheckChatUsernameResultPublicChatsTooMuch(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeCheckChatUsernameResultPublicGroupsUnavailable:
return UnmarshalCheckChatUsernameResultPublicGroupsUnavailable(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type GetCreatedPublicChatsRequest struct {
// Type of the public chats to return
Type PublicChatType `json:"type"`
}
// Returns a list of public chats of the specified type, owned by the user
func (client *Client) GetCreatedPublicChats(req *GetCreatedPublicChatsRequest) (*Chats, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getCreatedPublicChats",
},
2020-02-03 12:56:20 +00:00
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
type CheckCreatedPublicChatsLimitRequest struct {
// Type of the public chats, for which to check the limit
Type PublicChatType `json:"type"`
}
// Checks whether the maximum number of owned public chats has been reached. Returns corresponding error if the limit was reached
func (client *Client) CheckCreatedPublicChatsLimit(req *CheckCreatedPublicChatsLimitRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "checkCreatedPublicChatsLimit",
},
Data: map[string]interface{}{
"type": req.Type,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Basic group chats need to be first upgraded to supergroups before they can be set as a discussion group
func (client *Client) GetSuitableDiscussionChats() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getSuitableDiscussionChats",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChats(result.Data)
}
// Returns a list of recently inactive supergroups and channels. Can be used when user reaches limit on the number of joined supergroups and channels and receives CHANNELS_TOO_MUCH error
func (client *Client) GetInactiveSupergroupChats() (*Chats, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getInactiveSupergroupChats",
},
2018-10-23 12:38:10 +00:00
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChats(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetGroupsInCommonRequest struct {
// User identifier
UserId int32 `json:"user_id"`
// Chat identifier starting from which to return chats; use 0 for the first request
OffsetChatId int64 `json:"offset_chat_id"`
2020-02-03 12:56:20 +00:00
// The maximum number of chats to be returned; up to 100
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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"`
2019-06-07 10:56:06 +00:00
// Specify 0 to get results from exactly the from_message_id or a negative offset up to 99 to get additionally some newer messages
2018-10-23 12:38:10 +00:00
Offset int32 `json:"offset"`
2019-06-07 10:56:06 +00:00
// 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 or equal to -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
// If true, returns only messages that are available locally without sending network requests
OnlyLocal bool `json:"only_local"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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 the library. 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) {
2018-10-23 12:38:10 +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 DeleteChatHistoryRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2019-06-07 10:56:06 +00:00
// Pass true if the chat should be removed from the chat list
2018-10-23 12:38:10 +00:00
RemoveFromChatList bool `json:"remove_from_chat_list"`
2019-06-07 10:56:06 +00:00
// Pass true to try to delete chat history for all users
Revoke bool `json:"revoke"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +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) {
2018-10-23 12:38:10 +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,
2019-06-07 10:56:06 +00:00
"revoke": req.Revoke,
2018-10-23 12:38:10 +00:00
},
})
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"`
// If not 0, only messages sent by the specified user will be returned. Not supported in secret chats
SenderUserId int32 `json:"sender_user_id"`
// Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
FromMessageId int64 `json:"from_message_id"`
// Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages
Offset int32 `json:"offset"`
// The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
Limit int32 `json:"limit"`
// Filter for message content in the search results
Filter SearchMessagesFilter `json:"filter"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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 should be used instead), or without an enabled message database. For optimal performance the number of returned messages is chosen by the library
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChatMessages(req *SearchChatMessagesRequest) (*Messages, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchChatMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"sender_user_id": req.SenderUserId,
"from_message_id": req.FromMessageId,
"offset": req.Offset,
"limit": req.Limit,
"filter": req.Filter,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type SearchMessagesRequest struct {
2020-02-03 12:56:20 +00:00
// Chat list in which to search messages; pass null to search in all chats regardless of their chat list
ChatList ChatList `json:"chat_list"`
2018-10-23 12:38:10 +00:00
// Query to search for
Query string `json:"query"`
// The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message
OffsetDate int32 `json:"offset_date"`
// The chat identifier of the last found message, or 0 for the first request
OffsetChatId int64 `json:"offset_chat_id"`
// The message identifier of the last found message, or 0 for the first request
OffsetMessageId int64 `json:"offset_message_id"`
// The maximum number of messages to be returned, up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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 the library
2018-10-16 20:32:57 +00:00
func (client *Client) SearchMessages(req *SearchMessagesRequest) (*Messages, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchMessages",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"chat_list": req.ChatList,
2018-10-23 12:38:10 +00:00
"query": req.Query,
"offset_date": req.OffsetDate,
"offset_chat_id": req.OffsetChatId,
"offset_message_id": req.OffsetMessageId,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type SearchSecretMessagesRequest struct {
// Identifier of the chat in which to search. Specify 0 to search in all secret chats
ChatId int64 `json:"chat_id"`
// Query to search for. If empty, searchChatMessages should be used instead
Query string `json:"query"`
// The identifier from the result of a previous request, use 0 to get results from the last message
FromSearchId JsonInt64 `json:"from_search_id"`
2020-02-03 12:56:20 +00:00
// The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
// A filter for the content of messages in the search results
Filter SearchMessagesFilter `json:"filter"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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 the library
2018-10-16 20:32:57 +00:00
func (client *Client) SearchSecretMessages(req *SearchSecretMessagesRequest) (*FoundMessages, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchSecretMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"query": req.Query,
"from_search_id": req.FromSearchId,
"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 {
// Identifier of the message from which to search; use 0 to get results from the last message
FromMessageId int64 `json:"from_message_id"`
// The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
Limit int32 `json:"limit"`
// If true, returns only messages with missed calls
OnlyMissed bool `json:"only_missed"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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 the library
2018-10-16 20:32:57 +00:00
func (client *Client) SearchCallMessages(req *SearchCallMessagesRequest) (*Messages, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchCallMessages",
},
Data: map[string]interface{}{
"from_message_id": req.FromMessageId,
"limit": req.Limit,
"only_missed": req.OnlyMissed,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type SearchChatRecentLocationMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2020-02-03 12:56:20 +00:00
// The maximum number of messages to be returned
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
}
// Returns all active live locations that should be updated by the client. The list is persistent across application restarts only if the message database is used
func (client *Client) GetActiveLiveLocationMessages() (*Messages, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessages(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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 GetChatMessageCountRequest struct {
// Identifier of the chat in which to count messages
ChatId int64 `json:"chat_id"`
// Filter for message content; searchMessagesFilterEmpty is unsupported in this function
Filter SearchMessagesFilter `json:"filter"`
// If true, returns count that is available locally without sending network requests, returning -1 if the number of messages is unknown
ReturnLocal bool `json:"return_local"`
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) {
2018-10-23 12:38:10 +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)
}
2020-02-03 12:56:20 +00:00
type GetChatScheduledMessagesRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
}
// 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) {
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)
}
2019-06-07 10:56: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"`
}
// 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) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type RemoveNotificationGroupRequest struct {
// Notification group identifier
NotificationGroupId int32 `json:"notification_group_id"`
2020-02-03 12:56:20 +00:00
// The maximum identifier of removed notifications
2019-06-07 10:56:06 +00:00
MaxNotificationId int32 `json:"max_notification_id"`
}
// 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) {
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)
}
2018-10-23 12:38:10 +00:00
type GetPublicMessageLinkRequest struct {
// Identifier of the chat to which the message belongs
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// Pass true if a link for a whole media album should be returned
ForAlbum bool `json:"for_album"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns a public HTTPS link to a message. Available only for messages in supergroups and channels with a username
2018-10-16 20:32:57 +00:00
func (client *Client) GetPublicMessageLink(req *GetPublicMessageLinkRequest) (*PublicMessageLink, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPublicMessageLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"for_album": req.ForAlbum,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPublicMessageLink(result.Data)
}
2019-06-07 10:56:06 +00:00
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"`
}
// Returns a private HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels. The link will work only for members of the chat
func (client *Client) GetMessageLink(req *GetMessageLinkRequest) (*HttpUrl, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLink",
},
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 UnmarshalHttpUrl(result.Data)
}
2019-09-10 12:36:54 +00:00
type GetMessageLinkInfoRequest struct {
// The message link in the format "https://t.me/c/...", or "tg://privatepost?...", or "https://t.me/username/...", or "tg://resolve?..."
Url string `json:"url"`
}
// Returns information about a public or private message link
func (client *Client) GetMessageLinkInfo(req *GetMessageLinkInfoRequest) (*MessageLinkInfo, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getMessageLinkInfo",
},
Data: map[string]interface{}{
"url": req.Url,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessageLinkInfo(result.Data)
}
2018-10-23 12:38:10 +00:00
type SendMessageRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// Identifier of the message to reply to or 0
ReplyToMessageId int64 `json:"reply_to_message_id"`
2020-02-03 12:56:20 +00:00
// Options to be used to send the message
Options *SendMessageOptions `json:"options"`
2018-10-23 12:38:10 +00:00
// Markup for replying to the message; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// The content of the message to be sent
InputMessageContent InputMessageContent `json:"input_message_content"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"reply_to_message_id": req.ReplyToMessageId,
2020-02-03 12:56:20 +00:00
"options": req.Options,
2018-10-23 12:38:10 +00:00
"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"`
// Identifier of a message to reply to or 0
ReplyToMessageId int64 `json:"reply_to_message_id"`
2020-02-03 12:56:20 +00:00
// Options to be used to send the messages
Options *SendMessageOptions `json:"options"`
2018-10-23 12:38:10 +00:00
// Contents of messages to be sent
InputMessageContents []InputMessageContent `json:"input_message_contents"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends messages grouped together into an album. Currently only photo and video messages can be grouped into an album. Returns sent messages
2018-10-16 20:32:57 +00:00
func (client *Client) SendMessageAlbum(req *SendMessageAlbumRequest) (*Messages, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendMessageAlbum",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"reply_to_message_id": req.ReplyToMessageId,
2020-02-03 12:56:20 +00:00
"options": req.Options,
2018-10-23 12:38:10 +00:00
"input_message_contents": req.InputMessageContents,
},
})
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 int32 `json:"bot_user_id"`
// Identifier of the target chat
ChatId int64 `json:"chat_id"`
2019-09-10 12:36:54 +00:00
// A hidden parameter sent to the bot for deep linking purposes (https://core.telegram.org/bots#deep-linking)
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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"`
// Identifier of a message to reply to or 0
ReplyToMessageId int64 `json:"reply_to_message_id"`
2020-02-03 12:56:20 +00:00
// Options to be used to send the message
Options *SendMessageOptions `json:"options"`
2018-10-23 12:38:10 +00:00
// Identifier of the inline query
QueryId JsonInt64 `json:"query_id"`
// Identifier of the inline result
ResultId string `json:"result_id"`
2019-06-07 10:56:06 +00:00
// If true, there will be no mention of a 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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendInlineQueryResultMessage",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"chat_id": req.ChatId,
"reply_to_message_id": req.ReplyToMessageId,
"options": req.Options,
"query_id": req.QueryId,
"result_id": req.ResultId,
"hide_via_bot": req.HideViaBot,
2018-10-23 12:38:10 +00:00
},
})
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"`
// Identifier of the chat from which to forward messages
FromChatId int64 `json:"from_chat_id"`
// Identifiers of the messages to forward
MessageIds []int64 `json:"message_ids"`
2020-02-03 12:56:20 +00:00
// Options to be used to send the messages
Options *SendMessageOptions `json:"options"`
2018-10-23 12:38:10 +00:00
// True, if the messages should be grouped into an album after forwarding. For this to work, no more than 10 messages may be forwarded, and all of them must be photo or video messages
AsAlbum bool `json:"as_album"`
2019-09-10 12:36:54 +00:00
// True, if content of the messages needs to be copied without links to the original messages. Always true if the messages are forwarded to a secret chat
SendCopy bool `json:"send_copy"`
// True, if media captions of message copies needs to be removed. Ignored if send_copy is false
RemoveCaption bool `json:"remove_caption"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "forwardMessages",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"chat_id": req.ChatId,
"from_chat_id": req.FromChatId,
"message_ids": req.MessageIds,
"options": req.Options,
"as_album": req.AsAlbum,
"send_copy": req.SendCopy,
"remove_caption": req.RemoveCaption,
2019-09-10 12:36:54 +00:00
},
})
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"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "resendMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalMessages(result.Data)
}
type SendChatSetTtlMessageRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New TTL value, in seconds
Ttl int32 `json:"ttl"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the current TTL setting (sets a new self-destruct timer) in a secret chat and sends the corresponding message
2018-10-16 20:32:57 +00:00
func (client *Client) SendChatSetTtlMessage(req *SendChatSetTtlMessageRequest) (*Message, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendChatSetTtlMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"ttl": req.Ttl,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalMessage(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SendChatScreenshotTakenNotificationRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a notification about a screenshot taken in a chat. Supported only in private and secret chats
2018-10-16 20:32:57 +00:00
func (client *Client) SendChatScreenshotTakenNotification(req *SendChatScreenshotTakenNotificationRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
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)
}
type AddLocalMessageRequest struct {
// Target chat
ChatId int64 `json:"chat_id"`
// Identifier of the user who will be shown as the sender of the message; may be 0 for channel posts
SenderUserId int32 `json:"sender_user_id"`
// Identifier of the message to reply to or 0
ReplyToMessageId int64 `json:"reply_to_message_id"`
// Pass true to disable notification for the message
DisableNotification bool `json:"disable_notification"`
// The content of the message to be added
InputMessageContent InputMessageContent `json:"input_message_content"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addLocalMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"sender_user_id": req.SenderUserId,
"reply_to_message_id": req.ReplyToMessageId,
"disable_notification": req.DisableNotification,
"input_message_content": req.InputMessageContent,
},
})
if err != nil {
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"`
2019-06-07 10:56:06 +00:00
// Pass true to try to delete messages for all chat members. Always true for supergroups, channels and secret chats
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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 DeleteChatMessagesFromUserRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// User identifier
UserId int32 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Deletes all messages sent by the specified user to a chat. Supported only for supergroups; requires can_delete_messages administrator privileges
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteChatMessagesFromUser(req *DeleteChatMessagesFromUserRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteChatMessagesFromUser",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
},
})
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; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New text content of the message. Should be of type InputMessageText
InputMessageContent InputMessageContent `json:"input_message_content"`
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) {
2018-10-23 12:38:10 +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; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New location content of the message; may be null. Pass null to stop sharing the live location
Location *Location `json:"location"`
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) {
2018-10-23 12:38:10 +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,
},
})
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; 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. The media in the message can't be replaced if the message was set to self-destruct. Media can't be replaced by self-destructing media. Media in an album can be edited only to contain a photo or a video. Returns the edited message after the edit is completed on the server side
2018-10-16 20:32:57 +00:00
func (client *Client) EditMessageMedia(req *EditMessageMediaRequest) (*Message, error) {
2018-10-23 12:38:10 +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; for bots only
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New message content caption; 0-GetOption("message_caption_length_max") characters
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) {
2018-10-23 12:38:10 +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
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) {
2018-10-23 12:38:10 +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
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New text content of the message. Should 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) {
2018-10-23 12:38:10 +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
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New location content of the message; may be null. Pass null to stop sharing the live location
Location *Location `json:"location"`
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) {
2018-10-23 12:38:10 +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,
},
})
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; 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) {
2018-10-23 12:38:10 +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
ReplyMarkup ReplyMarkup `json:"reply_markup"`
// New message content 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) {
2018-10-23 12:38:10 +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
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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
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"`
}
// 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) {
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)
}
2018-10-23 12:38:10 +00:00
type GetTextEntitiesRequest struct {
// The text in which to look for entites
Text string `json:"text"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns all entities (mentions, hashtags, cashtags, bot commands, URLs, and email addresses) contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) GetTextEntities(req *GetTextEntitiesRequest) (*TextEntities, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTextEntities(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ParseTextEntitiesRequest struct {
// The text which should be parsed
Text string `json:"text"`
// Text parse mode
ParseMode TextParseMode `json:"parse_mode"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Parses Bold, Italic, Underline, Strikethrough, Code, Pre, PreCode, TextUrl and MentionName entities contained in the text. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) ParseTextEntities(req *ParseTextEntitiesRequest) (*FormattedText, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "parseTextEntities",
},
Data: map[string]interface{}{
"text": req.Text,
"parse_mode": req.ParseMode,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalFormattedText(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
// Returns the MIME type of a file, guessed by its extension. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) GetFileMimeType(req *GetFileMimeTypeRequest) (*Text, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetFileExtensionRequest struct {
// The MIME type of the file
MimeType string `json:"mime_type"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) GetFileExtension(req *GetFileExtensionRequest) (*Text, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-09-05 21:45:29 +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. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) CleanFileName(req *CleanFileNameRequest) (*Text, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "cleanFileName",
},
Data: map[string]interface{}{
"file_name": req.FileName,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type GetLanguagePackStringRequest struct {
// Path to the language pack database in which strings are stored
LanguagePackDatabasePath string `json:"language_pack_database_path"`
// Localization target to which the language pack belongs
LocalizationTarget string `json:"localization_target"`
// Language pack identifier
LanguagePackId string `json:"language_pack_id"`
// Language pack key of the string to be returned
Key string `json:"key"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +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. This is an offline method. Can be called before authorization. Can be called synchronously
2018-10-16 20:32:57 +00:00
func (client *Client) GetLanguagePackString(req *GetLanguagePackStringRequest) (LanguagePackStringValue, error) {
2018-10-23 12:38:10 +00:00
result, err := client.jsonClient.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")
}
}
2019-06-07 10:56:06 +00:00
type GetJsonValueRequest struct {
// The JSON-serialized string
Json string `json:"json"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Converts a JSON-serialized string to corresponding JsonValue object. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetJsonValue(req *GetJsonValueRequest) (JsonValue, error) {
result, err := client.jsonClient.Execute(Request{
2018-10-23 12:38:10 +00:00
meta: meta{
2019-06-07 10:56:06 +00:00
Type: "getJsonValue",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
2019-06-07 10:56:06 +00:00
"json": req.Json,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
switch result.Type {
case TypeJsonValueNull:
return UnmarshalJsonValueNull(result.Data)
case TypeJsonValueBoolean:
return UnmarshalJsonValueBoolean(result.Data)
case TypeJsonValueNumber:
return UnmarshalJsonValueNumber(result.Data)
case TypeJsonValueString:
return UnmarshalJsonValueString(result.Data)
case TypeJsonValueArray:
return UnmarshalJsonValueArray(result.Data)
case TypeJsonValueObject:
return UnmarshalJsonValueObject(result.Data)
default:
return nil, errors.New("invalid type")
}
2018-10-23 12:38:10 +00:00
}
2019-06-07 10:56:06 +00:00
type GetJsonStringRequest struct {
// The JsonValue object
JsonValue JsonValue `json:"json_value"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Converts a JsonValue object to corresponding JSON-serialized string. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetJsonString(req *GetJsonStringRequest) (*Text, error) {
result, err := client.jsonClient.Execute(Request{
2018-10-23 12:38:10 +00:00
meta: meta{
2019-06-07 10:56:06 +00:00
Type: "getJsonString",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
2019-06-07 10:56:06 +00:00
"json_value": req.JsonValue,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
return UnmarshalText(result.Data)
2018-10-23 12:38:10 +00:00
}
2019-06-07 10:56:06 +00:00
type SetPollAnswerRequest struct {
// Identifier of the chat to which the poll belongs
2018-10-23 12:38:10 +00:00
ChatId int64 `json:"chat_id"`
2019-06-07 10:56:06 +00:00
// Identifier of the message containing the poll
2018-10-23 12:38:10 +00:00
MessageId int64 `json:"message_id"`
2020-02-03 12:56:20 +00:00
// 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
2019-06-07 10:56:06 +00:00
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
2019-06-07 10:56:06 +00:00
Type: "setPollAnswer",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
2019-06-07 10:56:06 +00:00
"option_ids": req.OptionIds,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2019-06-07 10:56:06 +00:00
return UnmarshalOk(result.Data)
2018-10-23 12:38:10 +00:00
}
2020-02-03 12:56:20 +00:00
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"`
// Number of users to skip in the result; must be non-negative
Offset int32 `json:"offset"`
// The maximum number of users to be returned; must be positive and can't be greater than 50. Fewer users may be returned than specified by the limit, even if the end of the voter list has not been reached
Limit int32 `json:"limit"`
}
// Returns users voted for the specified option in a non-anonymous polls. For the optimal performance the number of returned users is chosen by the library
func (client *Client) GetPollVoters(req *GetPollVotersRequest) (*Users, error) {
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)
}
return UnmarshalUsers(result.Data)
}
2019-06-07 10:56: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; 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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
2019-06-07 10:56:06 +00:00
Type: "stopPoll",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
2019-06-07 10:56:06 +00:00
"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 UnmarshalOk(result.Data)
}
2020-02-03 12:56:20 +00:00
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 int32 `json:"button_id"`
}
// 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) {
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 int32 `json:"button_id"`
// True, if the user allowed the bot to send them messages
AllowWriteAccess bool `json:"allow_write_access"`
}
// 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) {
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)
}
2019-06-07 10:56:06 +00:00
type GetInlineQueryResultsRequest struct {
// The identifier of the target bot
BotUserId int32 `json:"bot_user_id"`
2020-02-03 12:56:20 +00:00
// Identifier of the chat where the query was sent
2019-06-07 10:56:06 +00:00
ChatId int64 `json:"chat_id"`
// Location of the user, only if needed
UserLocation *Location `json:"user_location"`
// Text of the query
Query string `json:"query"`
// Offset of the first entry to return
Offset string `json:"offset"`
}
// Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires
func (client *Client) GetInlineQueryResults(req *GetInlineQueryResultsRequest) (*InlineQueryResults, error) {
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"`
// True, if the result of the query can be cached for the specified user
IsPersonal bool `json:"is_personal"`
// The results of the query
Results []InputInlineQueryResult `json:"results"`
// Allowed time to cache the results of the query, in seconds
CacheTime int32 `json:"cache_time"`
// Offset for the next inline query; pass an empty string if there are no more results
NextOffset string `json:"next_offset"`
// If non-empty, this text should be shown on the button that opens a private chat with the bot and sends a start message to the bot with the parameter switch_pm_parameter
SwitchPmText string `json:"switch_pm_text"`
// The parameter for the bot start message
SwitchPmParameter string `json:"switch_pm_parameter"`
}
// Sets the result of an inline query; for bots only
func (client *Client) AnswerInlineQuery(req *AnswerInlineQueryRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "answerInlineQuery",
},
Data: map[string]interface{}{
"inline_query_id": req.InlineQueryId,
"is_personal": req.IsPersonal,
"results": req.Results,
"cache_time": req.CacheTime,
"next_offset": req.NextOffset,
"switch_pm_text": req.SwitchPmText,
"switch_pm_parameter": req.SwitchPmParameter,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetCallbackQueryAnswerRequest struct {
// Identifier of the chat with the message
ChatId int64 `json:"chat_id"`
// Identifier of the message from which the query originated
MessageId int64 `json:"message_id"`
// Query payload
Payload CallbackQueryPayload `json:"payload"`
}
// Sends a callback query to a bot and returns an answer. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires
func (client *Client) GetCallbackQueryAnswer(req *GetCallbackQueryAnswerRequest) (*CallbackQueryAnswer, error) {
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"`
// If true, an alert should be shown to the user instead of a toast notification
ShowAlert bool `json:"show_alert"`
// URL to be opened
Url string `json:"url"`
// Time during which the result of the query can be cached, in seconds
CacheTime int32 `json:"cache_time"`
}
// Sets the result of a callback query; for bots only
func (client *Client) AnswerCallbackQuery(req *AnswerCallbackQueryRequest) (*Ok, error) {
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,
2018-10-23 12:38:10 +00:00
"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) {
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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 {
2019-06-07 10:56:06 +00:00
// The chat to which the message with the game belongs
2018-10-23 12:38:10 +00:00
ChatId int64 `json:"chat_id"`
// Identifier of the message
MessageId int64 `json:"message_id"`
// True, if the message should be edited
EditMessage bool `json:"edit_message"`
// User identifier
UserId int32 `json:"user_id"`
// The new score
Score int32 `json:"score"`
// Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table
Force bool `json:"force"`
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) {
2018-10-23 12:38:10 +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"`
// True, if the message should be edited
EditMessage bool `json:"edit_message"`
// User identifier
UserId int32 `json:"user_id"`
// The new score
Score int32 `json:"score"`
// Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table
Force bool `json:"force"`
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) {
2018-10-23 12:38:10 +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 int32 `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) {
2018-10-23 12:38:10 +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 int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalGameHighScores(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
// Deletes the default reply markup from a chat. Must be called after a one-time keyboard or a ForceReply reply markup has been used. UpdateChatReplyMarkup will be sent if the reply markup will be changed
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteChatReplyMarkup(req *DeleteChatReplyMarkupRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SendChatActionRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The action description
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendChatAction",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"action": req.Action,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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"`
// True, if messages in closed chats should be marked as read
ForceRead bool `json:"force_read"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +00:00
// Informs TDLib that messages are being viewed by the user. Many useful activities depend on whether the messages are currently being viewed or not (e.g., marking messages as read, incrementing a view counter, updating a view counter, removing deleted messages in supergroups and channels)
2018-10-16 20:32:57 +00:00
func (client *Client) ViewMessages(req *ViewMessagesRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "viewMessages",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_ids": req.MessageIds,
"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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreatePrivateChatRequest struct {
// User identifier
UserId int32 `json:"user_id"`
// If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateBasicGroupChatRequest struct {
// Basic group identifier
BasicGroupId int32 `json:"basic_group_id"`
// If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateSupergroupChatRequest struct {
// Supergroup or channel identifier
SupergroupId int32 `json:"supergroup_id"`
// If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
Force bool `json:"force"`
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateNewBasicGroupChatRequest struct {
// Identifiers of users to be added to the basic group
UserIds []int32 `json:"user_ids"`
2019-06-07 10:56:06 +00:00
// Title of the new basic group; 1-128 characters
2018-10-23 12:38:10 +00:00
Title string `json:"title"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewBasicGroupChat",
},
Data: map[string]interface{}{
"user_ids": req.UserIds,
"title": req.Title,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalChat(result.Data)
}
type CreateNewSupergroupChatRequest struct {
2019-06-07 10:56:06 +00:00
// Title of the new chat; 1-128 characters
2018-10-23 12:38:10 +00:00
Title string `json:"title"`
// True, if a channel chat should be created
IsChannel bool `json:"is_channel"`
// Chat description; 0-255 characters
Description string `json:"description"`
2020-02-03 12:56:20 +00:00
// Chat location if a location-based supergroup is being created
Location *ChatLocation `json:"location"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createNewSupergroupChat",
},
Data: map[string]interface{}{
"title": req.Title,
"is_channel": req.IsChannel,
"description": req.Description,
2020-02-03 12:56:20 +00:00
"location": req.Location,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateNewSecretChatRequest struct {
// Identifier of the target user
UserId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type SetChatChatListRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New chat list of the chat
ChatList ChatList `json:"chat_list"`
}
// Moves a chat to a different chat list. Current chat list of the chat must ne non-null
func (client *Client) SetChatChatList(req *SetChatChatListRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatChatList",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"chat_list": req.ChatList,
},
})
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
type SetChatTitleRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2019-06-07 10:56:06 +00:00
// New title of the chat; 1-128 characters
2018-10-23 12:38:10 +00:00
Title string `json:"title"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Changes the chat title. Supported only for basic groups, supergroups and channels. Requires can_change_info rights. The title will not be changed until the request to the server has been completed
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatTitle(req *SetChatTitleRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatTitle",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"title": req.Title,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetChatPhotoRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New chat photo. You can use a zero InputFileId to delete the chat photo. Files that are accessible only by HTTP URL are not acceptable
Photo InputFile `json:"photo"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Changes the photo of a chat. Supported only for basic groups, supergroups and channels. Requires can_change_info rights. The photo will not be changed before request to the server has been completed
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatPhoto(req *SetChatPhotoRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatPhoto",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"photo": req.Photo,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
type SetChatPermissionsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New non-administrator members permissions in the chat
Permissions *ChatPermissions `json:"permissions"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatPermissions",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"permissions": req.Permissions,
},
})
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
type SetChatDraftMessageRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New draft message; may be null
DraftMessage *DraftMessage `json:"draft_message"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the draft message in a chat
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatDraftMessage(req *SetChatDraftMessageRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatDraftMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"draft_message": req.DraftMessage,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetChatNotificationSettingsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2020-02-03 12:56:20 +00:00
// New notification settings for the chat. If the chat is muted for more than 1 week, it is considered to be muted forever
2018-10-23 12:38:10 +00:00
NotificationSettings *ChatNotificationSettings `json:"notification_settings"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Changes the notification settings of a chat. Notification settings of a chat with the current user (Saved Messages) can't be changed
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatNotificationSettings(req *SetChatNotificationSettingsRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatNotificationSettings",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"notification_settings": req.NotificationSettings,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type ToggleChatIsPinnedRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New value of is_pinned
IsPinned bool `json:"is_pinned"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/archive chat list
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleChatIsPinned(req *ToggleChatIsPinnedRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleChatIsPinned",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"is_pinned": req.IsPinned,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ToggleChatIsMarkedAsUnreadRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New value of is_marked_as_unread
IsMarkedAsUnread bool `json:"is_marked_as_unread"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes the marked as unread state of a chat
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleChatIsMarkedAsUnread(req *ToggleChatIsMarkedAsUnreadRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleChatIsMarkedAsUnread",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"is_marked_as_unread": req.IsMarkedAsUnread,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type ToggleChatDefaultDisableNotificationRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New value of default_disable_notification
DefaultDisableNotification bool `json:"default_disable_notification"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes the value of the default disable_notification parameter, used when a message is sent to a chat
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleChatDefaultDisableNotification(req *ToggleChatDefaultDisableNotificationRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "toggleChatDefaultDisableNotification",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"default_disable_notification": req.DefaultDisableNotification,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SetChatClientDataRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New value of client_data
ClientData string `json:"client_data"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes client data associated with a chat
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatClientData(req *SetChatClientDataRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatClientData",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"client_data": req.ClientData,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
type SetChatDescriptionRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// New chat description; 0-255 characters
Description string `json:"description"`
}
// Changes information about a chat. Available for basic groups, supergroups, and channels. Requires can_change_info rights
func (client *Client) SetChatDescription(req *SetChatDescriptionRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatDescription",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"description": req.Description,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2020-02-03 12:56:20 +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 needs to be first upgraded to supergroup chats. If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable needs to be used first to change that
DiscussionChatId int64 `json:"discussion_chat_id"`
}
// Changes the discussion group of a channel chat; requires can_change_info rights in the channel if it is specified
func (client *Client) SetChatDiscussionGroup(req *SetChatDiscussionGroupRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatDiscussionGroup",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"discussion_chat_id": req.DiscussionChatId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
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"`
}
// 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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetChatSlowModeDelayRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// New slow mode delay for the chat; must be one of 0, 10, 30, 60, 300, 900, 3600
SlowModeDelay int32 `json:"slow_mode_delay"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "setChatSlowModeDelay",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"slow_mode_delay": req.SlowModeDelay,
},
})
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
type PinChatMessageRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
// Identifier of the new pinned message
MessageId int64 `json:"message_id"`
// True, if there should be no notification about the pinned message
DisableNotification bool `json:"disable_notification"`
}
2019-09-10 12:36:54 +00:00
// Pins a message in a chat; requires can_pin_messages rights
2019-06-07 10:56:06 +00:00
func (client *Client) PinChatMessage(req *PinChatMessageRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "pinChatMessage",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"disable_notification": req.DisableNotification,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type UnpinChatMessageRequest struct {
// Identifier of the chat
ChatId int64 `json:"chat_id"`
}
2019-09-10 12:36:54 +00:00
// Removes the pinned message from a chat; requires can_pin_messages rights in the group or channel
2019-06-07 10:56:06 +00:00
func (client *Client) UnpinChatMessage(req *UnpinChatMessageRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "unpinChatMessage",
},
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)
}
2018-10-23 12:38:10 +00:00
type JoinChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Adds current user as a new member to a chat. Private and secret chats can't be joined using this method
2018-10-16 20:32:57 +00:00
func (client *Client) JoinChat(req *JoinChatRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "joinChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type LeaveChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Removes current user from chat members. Private and secret chats can't be left using this method
2018-10-16 20:32:57 +00:00
func (client *Client) LeaveChat(req *LeaveChatRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "leaveChat",
},
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 AddChatMemberRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifier of the user
UserId int32 `json:"user_id"`
2019-06-07 10:56:06 +00:00
// The number of earlier messages from the chat to be forwarded to the new member; up to 100. Ignored for supergroups and channels
2018-10-23 12:38:10 +00:00
ForwardLimit int32 `json:"forward_limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Adds a new member to a chat. Members can't be added to private or secret chats. Members will not be added until the chat state has been synchronized with the server
2018-10-16 20:32:57 +00:00
func (client *Client) AddChatMember(req *AddChatMemberRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addChatMember",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
"forward_limit": req.ForwardLimit,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AddChatMembersRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// Identifiers of the users to be added to the chat
UserIds []int32 `json:"user_ids"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Adds multiple new members to a chat. Currently this option is only available for supergroups and channels. This option can't be used to join a chat. Members can't be added to a channel if it has more than 200 members. Members will not be added until the chat state has been synchronized with the server
2018-10-16 20:32:57 +00:00
func (client *Client) AddChatMembers(req *AddChatMembersRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "addChatMembers",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_ids": req.UserIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type SetChatMemberStatusRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// User identifier
UserId int32 `json:"user_id"`
// The new status of the member in the chat
Status ChatMemberStatus `json:"status"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for adding new members to the chat and transferring chat ownership; instead, use addChatMember or transferChatOwnership. The chat member status will not be changed until it has been synchronized with the server
2018-10-16 20:32:57 +00:00
func (client *Client) SetChatMemberStatus(req *SetChatMemberStatusRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setChatMemberStatus",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
"status": req.Status,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2020-02-03 12:56:20 +00:00
// 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 int32 `json:"user_id"`
// The 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)
}
2018-10-23 12:38:10 +00:00
type GetChatMemberRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// User identifier
UserId int32 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns information about a single member of a chat
2018-10-16 20:32:57 +00:00
func (client *Client) GetChatMember(req *GetChatMemberRequest) (*ChatMember, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatMember",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"user_id": req.UserId,
},
})
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
Limit int32 `json:"limit"`
// The type of users to return. By default, chatMembersFilterMembers
Filter ChatMembersFilter `json:"filter"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for a specified query in the first name, last name and username of the members of a specified chat. Requires administrator rights in channels
2018-10-16 20:32:57 +00:00
func (client *Client) SearchChatMembers(req *SearchChatMembersRequest) (*ChatMembers, error) {
2018-10-23 12:38:10 +00:00
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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChatMembers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetChatAdministratorsRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns a list of administrators of the chat with their custom titles
func (client *Client) GetChatAdministrators(req *GetChatAdministratorsRequest) (*ChatAdministrators, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getChatAdministrators",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2020-02-03 12:56:20 +00:00
return UnmarshalChatAdministrators(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ClearAllDraftMessagesRequest struct {
// If true, local draft messages in secret chats will not be cleared
ExcludeSecretChats bool `json:"exclude_secret_chats"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Clears draft messages in all chats
2018-10-16 20:32:57 +00:00
func (client *Client) ClearAllDraftMessages(req *ClearAllDraftMessagesRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearAllDraftMessages",
},
Data: map[string]interface{}{
"exclude_secret_chats": req.ExcludeSecretChats,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type GetChatNotificationSettingsExceptionsRequest struct {
// If specified, only chats from the specified scope will be returned
Scope NotificationSettingsScope `json:"scope"`
// If true, also chats with non-default sound will be returned
CompareSound bool `json:"compare_sound"`
}
// Returns list of chats with non-default notification settings
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)
}
2018-10-23 12:38:10 +00:00
type GetScopeNotificationSettingsRequest struct {
// Types of chats for which to return the notification settings information
Scope NotificationSettingsScope `json:"scope"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns the notification settings for chats of a given type
2018-10-16 20:32:57 +00:00
func (client *Client) GetScopeNotificationSettings(req *GetScopeNotificationSettingsRequest) (*ScopeNotificationSettings, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getScopeNotificationSettings",
},
Data: map[string]interface{}{
"scope": req.Scope,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalScopeNotificationSettings(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
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"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes notification settings for chats of a given type
2018-10-16 20:32:57 +00:00
func (client *Client) SetScopeNotificationSettings(req *SetScopeNotificationSettingsRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
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)
2018-09-05 21:45:29 +00:00
}
// Resets all notification settings to their default values. By default, all chats are unmuted, the sound is set to "default" and message previews are shown
func (client *Client) ResetAllNotificationSettings() (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resetAllNotificationSettings",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SetPinnedChatsRequest struct {
2020-02-03 12:56:20 +00:00
// Chat list in which to change the order of pinned chats
ChatList ChatList `json:"chat_list"`
2018-10-23 12:38:10 +00:00
// The new list of pinned chats
ChatIds []int64 `json:"chat_ids"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Changes the order of pinned chats
2018-10-16 20:32:57 +00:00
func (client *Client) SetPinnedChats(req *SetPinnedChatsRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setPinnedChats",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"chat_list": req.ChatList,
"chat_ids": req.ChatIds,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type DownloadFileRequest struct {
// Identifier of the file to download
FileId int32 `json:"file_id"`
// Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile was called will be downloaded first
Priority int32 `json:"priority"`
2019-06-07 10:56:06 +00:00
// The starting position from which the file should be downloaded
Offset int32 `json:"offset"`
// Number of bytes which should be downloaded starting from the "offset" position before the download will be automatically cancelled; use 0 to download without a limit
Limit int32 `json:"limit"`
// If false, this request returns file state just after the download has been started. If true, this request returns file state only after the download has succeeded, has failed, has been cancelled or a new downloadFile request with different offset/limit parameters was sent
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "downloadFile",
},
Data: map[string]interface{}{
2019-06-07 10:56:06 +00:00
"file_id": req.FileId,
"priority": req.Priority,
"offset": req.Offset,
"limit": req.Limit,
"synchronous": req.Synchronous,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalFile(result.Data)
2018-09-05 21:45:29 +00:00
}
2019-06-07 10:56:06 +00:00
type GetFileDownloadedPrefixSizeRequest struct {
// Identifier of the file
FileId int32 `json:"file_id"`
// Offset from which downloaded prefix size should be calculated
Offset int32 `json:"offset"`
}
// Returns file downloaded prefix size from a given offset
func (client *Client) GetFileDownloadedPrefixSize(req *GetFileDownloadedPrefixSizeRequest) (*Count, error) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalCount(result.Data)
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type UploadFileRequest struct {
// File to upload
File InputFile `json:"file"`
// File type
FileType FileType `json:"file_type"`
// Priority of the upload (1-32). The higher the priority, the earlier the file will be uploaded. If the priorities of two files are equal, then the first one for which uploadFile was called will be uploaded first
Priority int32 `json:"priority"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Asynchronously uploads a file to the cloud without sending it in a message. updateFile will be used to notify about upload progress and successful completion of the upload. The file will not have a persistent remote identifier until it will be sent in a message
2018-10-16 20:32:57 +00:00
func (client *Client) UploadFile(req *UploadFileRequest) (*File, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "uploadFile",
},
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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalFile(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CancelUploadFileRequest struct {
// Identifier of the file to stop uploading
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Stops the uploading of a file. Supported only for files uploaded by using uploadFile. For other files the behavior is undefined
2018-10-16 20:32:57 +00:00
func (client *Client) CancelUploadFile(req *CancelUploadFileRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "cancelUploadFile",
},
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)
}
2019-06-07 10:56:06 +00:00
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 int32 `json:"offset"`
// The data to write
Data []byte `json:"data"`
}
// Writes a part of a generated file. This method is intended to be used only if the client has no direct access to TDLib's file system, because it is usually slower than a direct write to the destination file
func (client *Client) WriteGeneratedFilePart(req *WriteGeneratedFilePartRequest) (*Ok, error) {
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)
}
2018-10-23 12:38:10 +00:00
type SetFileGenerationProgressRequest struct {
// The identifier of the generation process
GenerationId JsonInt64 `json:"generation_id"`
// Expected size of the generated file, in bytes; 0 if unknown
ExpectedSize int32 `json:"expected_size"`
// The number of bytes already generated
LocalPrefixSize int32 `json:"local_prefix_size"`
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) {
2018-10-23 12:38:10 +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 set, means that file generation has failed and should be terminated
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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
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 int32 `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 int32 `json:"count"`
}
// 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 client 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) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFilePart(result.Data)
}
2018-10-23 12:38:10 +00:00
type DeleteFileRequest struct {
// Identifier of the file to delete
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Deletes a file from the TDLib file cache
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteFile(req *DeleteFileRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GenerateChatInviteLinkRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Generates a new invite link for a chat; the previously generated link is revoked. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right
2018-10-16 20:32:57 +00:00
func (client *Client) GenerateChatInviteLink(req *GenerateChatInviteLinkRequest) (*ChatInviteLink, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "generateChatInviteLink",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChatInviteLink(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckChatInviteLinkRequest struct {
// Invite link to be checked; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
InviteLink string `json:"invite_link"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks the validity of an invite link for a chat and returns information about the corresponding chat
2018-10-16 20:32:57 +00:00
func (client *Client) CheckChatInviteLink(req *CheckChatInviteLinkRequest) (*ChatInviteLinkInfo, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChatInviteLinkInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type JoinChatByInviteLinkRequest struct {
// Invite link to import; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
InviteLink string `json:"invite_link"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Uses an invite link to add the current user to the chat if possible. The new member will not be added until the chat state has been synchronized with the server
2018-10-16 20:32:57 +00:00
func (client *Client) JoinChatByInviteLink(req *JoinChatByInviteLinkRequest) (*Chat, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChat(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CreateCallRequest struct {
// Identifier of the user to be called
UserId int32 `json:"user_id"`
// Description of the call protocols supported by the client
Protocol *CallProtocol `json:"protocol"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new call
2018-10-16 20:32:57 +00:00
func (client *Client) CreateCall(req *CreateCallRequest) (*CallId, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "createCall",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"protocol": req.Protocol,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalCallId(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type AcceptCallRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// Description of the call protocols supported by the client
Protocol *CallProtocol `json:"protocol"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Accepts an incoming call
2018-10-16 20:32:57 +00:00
func (client *Client) AcceptCall(req *AcceptCallRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type DiscardCallRequest struct {
// Call identifier
CallId int32 `json:"call_id"`
// True, if the user was disconnected
IsDisconnected bool `json:"is_disconnected"`
// The call duration, in seconds
Duration int32 `json:"duration"`
// Identifier of the connection used during the call
ConnectionId JsonInt64 `json:"connection_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Discards a call
2018-10-16 20:32:57 +00:00
func (client *Client) DiscardCall(req *DiscardCallRequest) (*Ok, error) {
2018-10-23 12:38:10 +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,
"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"`
2019-09-10 12:36:54 +00:00
// List of the exact types of problems with the call, specified by the user
Problems []CallProblem `json:"problems"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends a call rating
2018-10-16 20:32:57 +00:00
func (client *Client) SendCallRating(req *SendCallRatingRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendCallRating",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"call_id": req.CallId,
"rating": req.Rating,
"comment": req.Comment,
"problems": req.Problems,
2018-10-23 12:38:10 +00:00
},
})
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"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Sends debug information for a call
2018-10-16 20:32:57 +00:00
func (client *Client) SendCallDebugInformation(req *SendCallDebugInformationRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type BlockUserRequest struct {
// User identifier
UserId int32 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Adds a user to the blacklist
2018-10-16 20:32:57 +00:00
func (client *Client) BlockUser(req *BlockUserRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "blockUser",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type UnblockUserRequest struct {
// User identifier
UserId int32 `json:"user_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Removes a user from the blacklist
2018-10-16 20:32:57 +00:00
func (client *Client) UnblockUser(req *UnblockUserRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "unblockUser",
},
Data: map[string]interface{}{
"user_id": req.UserId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetBlockedUsersRequest struct {
// Number of users to skip in the result; must be non-negative
Offset int32 `json:"offset"`
2020-02-03 12:56:20 +00:00
// The maximum number of users to return; up to 100
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns users that were blocked by the current user
2018-10-16 20:32:57 +00:00
func (client *Client) GetBlockedUsers(req *GetBlockedUsersRequest) (*Users, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getBlockedUsers",
},
Data: map[string]interface{}{
"offset": req.Offset,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUsers(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type AddContactRequest struct {
// The contact to add or edit; phone number can be empty and needs to be specified only if known, vCard is ignored
Contact *Contact `json:"contact"`
// True, if the new contact needs to be allowed to see current user's phone number. 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"`
}
// Adds a user to the contact list or edits an existing contact by their user identifier
func (client *Client) AddContact(req *AddContactRequest) (*Ok, error) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
2018-10-23 12:38:10 +00:00
type ImportContactsRequest struct {
2020-02-03 12:56:20 +00:00
// The list of contacts to import or edit; contacts' vCard are ignored and are not imported
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalImportedContacts(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-09-05 21:45:29 +00:00
// Returns all user contacts
func (client *Client) GetContacts() (*Users, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUsers(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchContactsRequest struct {
2019-06-07 10:56:06 +00:00
// Query to search for; may be empty to return all contacts
2018-10-23 12:38:10 +00:00
Query string `json:"query"`
2020-02-03 12:56:20 +00:00
// The maximum number of users to be returned
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUsers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type RemoveContactsRequest struct {
// Identifiers of users to be deleted
UserIds []int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalCount(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
// Changes imported contacts using the list of current user contacts saved on the device. Imports newly added contacts and, if at least the file database is enabled, deletes recently deleted contacts. Query result depends on the result of the previous query, so only one query is possible at the same time
2018-10-16 20:32:57 +00:00
func (client *Client) ChangeImportedContacts(req *ChangeImportedContactsRequest) (*ImportedContacts, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "clearImportedContacts",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type SharePhoneNumberRequest struct {
// Identifier of the user with whom to share the phone number. The user must be a mutual contact
UserId int32 `json:"user_id"`
}
// 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) {
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)
}
2018-10-23 12:38:10 +00:00
type GetUserProfilePhotosRequest struct {
// User identifier
UserId int32 `json:"user_id"`
// The number of photos to skip; must be non-negative
Offset int32 `json:"offset"`
2020-02-03 12:56:20 +00:00
// The maximum number of photos to be returned; up to 100
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns the profile photos of a user. The result of this query may be outdated: some photos might have been deleted already
2018-10-16 20:32:57 +00:00
func (client *Client) GetUserProfilePhotos(req *GetUserProfilePhotosRequest) (*UserProfilePhotos, error) {
2018-10-23 12:38:10 +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 UnmarshalUserProfilePhotos(result.Data)
}
type GetStickersRequest struct {
// String representation of emoji. If empty, returns all known installed stickers
Emoji string `json:"emoji"`
2020-02-03 12:56:20 +00:00
// The maximum number of stickers to be returned
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns stickers from the installed sticker sets that correspond to a given emoji. If the emoji is not empty, favorite and recently used stickers may also be returned
2018-10-16 20:32:57 +00:00
func (client *Client) GetStickers(req *GetStickersRequest) (*Stickers, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStickers",
},
Data: map[string]interface{}{
"emoji": req.Emoji,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchStickersRequest struct {
// String representation of emoji; must be non-empty
Emoji string `json:"emoji"`
2020-02-03 12:56:20 +00:00
// The maximum number of stickers to be returned
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Searches for stickers from public sticker sets that correspond to a given emoji
2018-10-16 20:32:57 +00:00
func (client *Client) SearchStickers(req *SearchStickersRequest) (*Stickers, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchStickers",
},
Data: map[string]interface{}{
"emoji": req.Emoji,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetInstalledStickerSetsRequest struct {
// Pass true to return mask sticker sets; pass false to return ordinary sticker sets
IsMasks bool `json:"is_masks"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInstalledStickerSets",
},
Data: map[string]interface{}{
"is_masks": req.IsMasks,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStickerSets(result.Data)
}
type GetArchivedStickerSetsRequest struct {
// Pass true to return mask stickers sets; pass false to return ordinary sticker sets
IsMasks bool `json:"is_masks"`
// Identifier of the sticker set from which to return the result
OffsetStickerSetId JsonInt64 `json:"offset_sticker_set_id"`
2020-02-03 12:56:20 +00:00
// The maximum number of sticker sets to return
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getArchivedStickerSets",
},
Data: map[string]interface{}{
"is_masks": req.IsMasks,
"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)
2018-08-30 14:55:42 +00:00
}
// Returns a list of trending sticker sets
func (client *Client) GetTrendingStickerSets() (*StickerSets, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getTrendingStickerSets",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetAttachedStickerSetsRequest struct {
// File identifier
FileId int32 `json:"file_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Returns a list of sticker sets attached to a file. Currently only photos and videos can have attached sticker sets
2018-10-16 20:32:57 +00:00
func (client *Client) GetAttachedStickerSets(req *GetAttachedStickerSetsRequest) (*StickerSets, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickerSet(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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 {
// Pass true to return mask sticker sets; pass false to return ordinary sticker sets
IsMasks bool `json:"is_masks"`
// Query to search for
Query string `json:"query"`
2020-02-03 12:56:20 +00:00
// The maximum number of sticker sets to return
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "searchInstalledStickerSets",
},
Data: map[string]interface{}{
"is_masks": req.IsMasks,
"query": req.Query,
"limit": req.Limit,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ReorderInstalledStickerSetsRequest struct {
// Pass true to change the order of mask sticker sets; pass false to change the order of ordinary sticker sets
IsMasks bool `json:"is_masks"`
// Identifiers of installed sticker sets in the new correct order
StickerSetIds []JsonInt64 `json:"sticker_set_ids"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reorderInstalledStickerSets",
},
Data: map[string]interface{}{
"is_masks": req.IsMasks,
"sticker_set_ids": req.StickerSetIds,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +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
2018-10-16 20:32:57 +00:00
func (client *Client) AddRecentSticker(req *AddRecentStickerRequest) (*Stickers, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns favorite stickers
func (client *Client) GetFavoriteStickers() (*Stickers, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalStickers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type AddFavoriteStickerRequest struct {
// Sticker file to add
Sticker InputFile `json:"sticker"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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
2018-10-16 20:32:57 +00:00
func (client *Client) AddFavoriteSticker(req *AddFavoriteStickerRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStickerEmojis",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2019-09-10 12:36:54 +00:00
return UnmarshalEmojis(result.Data)
}
type SearchEmojisRequest struct {
// Text to search for
Text string `json:"text"`
// True, if only emojis, which exactly match text needs to be returned
ExactMatch bool `json:"exact_match"`
2020-02-03 12:56:20 +00:00
// IETF language tag of the user's input language; may be empty if unknown
InputLanguageCode string `json:"input_language_code"`
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) {
result, err := client.Send(Request{
meta: meta{
Type: "searchEmojis",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"text": req.Text,
"exact_match": req.ExactMatch,
"input_language_code": req.InputLanguageCode,
2019-09-10 12:36:54 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalEmojis(result.Data)
}
type GetEmojiSuggestionsUrlRequest struct {
// Language code for which the emoji replacements will be suggested
LanguageCode string `json:"language_code"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "getEmojiSuggestionsUrl",
},
Data: map[string]interface{}{
"language_code": req.LanguageCode,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns saved animations
func (client *Client) GetSavedAnimations() (*Animations, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalAnimations(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUsers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SearchHashtagsRequest struct {
// Hashtag prefix to search for
Prefix string `json:"prefix"`
2020-02-03 12:56:20 +00:00
// The maximum number of hashtags to be returned
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalHashtags(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalWebPage(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetWebPageInstantViewRequest struct {
// The web page URL
Url string `json:"url"`
// If true, the full instant view for the web page will be returned
ForceFull bool `json:"force_full"`
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalWebPageInstantView(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetProfilePhotoRequest struct {
// Profile photo to set. inputFileId and inputFileRemote may still be unsupported
Photo InputFile `json:"photo"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Uploads a new profile photo for the current user. If something changes, updateUser will be sent
2018-10-16 20:32:57 +00:00
func (client *Client) SetProfilePhoto(req *SetProfilePhotoRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setProfilePhoto",
},
Data: map[string]interface{}{
"photo": req.Photo,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
// Deletes a profile photo. If something changes, updateUser will be sent
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteProfilePhoto(req *DeleteProfilePhotoRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetNameRequest struct {
2019-06-07 10:56:06 +00:00
// The new value of the first name for the user; 1-64 characters
2018-10-23 12:38:10 +00:00
FirstName string `json:"first_name"`
2019-06-07 10:56:06 +00:00
// The new value of the optional last name for the user; 0-64 characters
2018-10-23 12:38:10 +00:00
LastName string `json:"last_name"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the first and last name of the current user. If something changes, updateUser will be sent
2018-10-16 20:32:57 +00:00
func (client *Client) SetName(req *SetNameRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetBioRequest struct {
// The new value of the user bio; 0-70 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetUsernameRequest struct {
// The new value of the username. Use an empty string to remove the username
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the username of the current user. If something changes, updateUser will be sent
2018-10-16 20:32:57 +00:00
func (client *Client) SetUsername(req *SetUsernameRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "setUsername",
},
Data: map[string]interface{}{
"username": req.Username,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type ChangePhoneNumberRequest struct {
// The new phone number of the user in international format
PhoneNumber string `json:"phone_number"`
2019-09-10 12:36:54 +00:00
// Settings for the authentication of the user's phone number
Settings *PhoneNumberAuthenticationSettings `json:"settings"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Changes the phone number of the user and sends an authentication code to the user's new phone number. On success, returns information about the sent code
2018-10-16 20:32:57 +00:00
func (client *Client) ChangePhoneNumber(req *ChangePhoneNumberRequest) (*AuthenticationCodeInfo, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "changePhoneNumber",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"phone_number": req.PhoneNumber,
"settings": req.Settings,
2018-10-23 12:38:10 +00:00
},
})
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
}
// Re-sends the authentication code sent to confirm a new phone number for the user. Works only if the previously received authenticationCodeInfo next_code_type was not null
func (client *Client) ResendChangePhoneNumberCode() (*AuthenticationCodeInfo, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "resendChangePhoneNumberCode",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckChangePhoneNumberCodeRequest struct {
// Verification code received by SMS, phone call or flash call
Code string `json:"code"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Checks the authentication code sent to confirm a new phone number of the user
2018-10-16 20:32:57 +00:00
func (client *Client) CheckChangePhoneNumberCode(req *CheckChangePhoneNumberCodeRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "checkChangePhoneNumberCode",
},
Data: map[string]interface{}{
"code": req.Code,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns all active sessions of the current user
func (client *Client) GetActiveSessions() (*Sessions, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalSessions(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type TerminateSessionRequest struct {
// Session identifier
SessionId JsonInt64 `json:"session_id"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Terminates a session of the current user
2018-10-16 20:32:57 +00:00
func (client *Client) TerminateSession(req *TerminateSessionRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Terminates all other sessions of the current user
func (client *Client) TerminateAllOtherSessions() (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "terminateAllOtherSessions",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalConnectedWebsites(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetSupergroupUsernameRequest struct {
// Identifier of the supergroup or channel
SupergroupId int32 `json:"supergroup_id"`
// New value of the username. Use an empty string to remove the username
Username string `json:"username"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Changes the 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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetSupergroupStickerSetRequest struct {
// Identifier of the supergroup
SupergroupId int32 `json:"supergroup_id"`
// New value of the supergroup sticker set identifier. Use 0 to remove the supergroup sticker set
StickerSetId JsonInt64 `json:"sticker_set_id"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Changes the sticker set of a supergroup; requires can_change_info rights
2018-10-16 20:32:57 +00:00
func (client *Client) SetSupergroupStickerSet(req *SetSupergroupStickerSetRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ToggleSupergroupSignMessagesRequest struct {
// Identifier of the channel
SupergroupId int32 `json:"supergroup_id"`
// New value of sign_messages
SignMessages bool `json:"sign_messages"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Toggles sender signatures messages sent in a channel; requires can_change_info rights
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleSupergroupSignMessages(req *ToggleSupergroupSignMessagesRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ToggleSupergroupIsAllHistoryAvailableRequest struct {
// The identifier of the supergroup
SupergroupId int32 `json:"supergroup_id"`
// The new value of is_all_history_available
IsAllHistoryAvailable bool `json:"is_all_history_available"`
2018-10-16 20:32:57 +00:00
}
2019-09-10 12:36:54 +00:00
// Toggles whether the message history of a supergroup is available to new members; requires can_change_info rights
2018-10-16 20:32:57 +00:00
func (client *Client) ToggleSupergroupIsAllHistoryAvailable(req *ToggleSupergroupIsAllHistoryAvailableRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type ReportSupergroupSpamRequest struct {
// Supergroup identifier
SupergroupId int32 `json:"supergroup_id"`
// User identifier
UserId int32 `json:"user_id"`
// Identifiers of messages sent in the supergroup by the user. This list must be non-empty
MessageIds []int64 `json:"message_ids"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup
2018-10-16 20:32:57 +00:00
func (client *Client) ReportSupergroupSpam(req *ReportSupergroupSpamRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "reportSupergroupSpam",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
"user_id": req.UserId,
"message_ids": req.MessageIds,
},
})
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 int32 `json:"supergroup_id"`
// The type of users to return. By default, supergroupMembersRecent
Filter SupergroupMembersFilter `json:"filter"`
// Number of users to skip
Offset int32 `json:"offset"`
// The maximum number of users be returned; up to 200
Limit int32 `json:"limit"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +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
2018-10-16 20:32:57 +00:00
func (client *Client) GetSupergroupMembers(req *GetSupergroupMembersRequest) (*ChatMembers, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalChatMembers(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type DeleteSupergroupRequest struct {
// Identifier of the supergroup or channel
SupergroupId int32 `json:"supergroup_id"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Deletes a supergroup or channel along with all messages in the corresponding chat. This will release the supergroup or channel username and remove all members; requires owner privileges in the supergroup or channel. Chats with more than 1000 members can't be deleted using this method
2018-10-16 20:32:57 +00:00
func (client *Client) DeleteSupergroup(req *DeleteSupergroupRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteSupergroup",
},
Data: map[string]interface{}{
"supergroup_id": req.SupergroupId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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"`
2020-02-03 12:56:20 +00:00
// The maximum number of events to return; up to 100
2018-10-23 12:38:10 +00:00
Limit int32 `json:"limit"`
// The types of events to return. By default, all types will be returned
Filters *ChatEventLogFilters `json:"filters"`
// User identifiers by which to filter events. By default, events relating to all users will be returned
UserIds []int32 `json:"user_ids"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +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) {
2018-10-23 12:38:10 +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 {
// Chat identifier of the Invoice 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 an invoice payment form. This method should be called when the user presses inlineKeyboardButtonBuy
2018-10-16 20:32:57 +00:00
func (client *Client) GetPaymentForm(req *GetPaymentFormRequest) (*PaymentForm, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getPaymentForm",
},
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 UnmarshalPaymentForm(result.Data)
}
type ValidateOrderInfoRequest struct {
// Chat identifier of the Invoice message
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// The order information, provided by the user
OrderInfo *OrderInfo `json:"order_info"`
// True, if the order information can be saved
AllowSave bool `json:"allow_save"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "validateOrderInfo",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"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 {
// Chat identifier of the Invoice message
ChatId int64 `json:"chat_id"`
// Message identifier
MessageId int64 `json:"message_id"`
// Identifier returned by ValidateOrderInfo, or an empty string
OrderInfoId string `json:"order_info_id"`
// Identifier of a chosen shipping option, if applicable
ShippingOptionId string `json:"shipping_option_id"`
// The credentials chosen by user for payment
Credentials InputCredentials `json:"credentials"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPaymentForm",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"message_id": req.MessageId,
"order_info_id": req.OrderInfoId,
"shipping_option_id": req.ShippingOptionId,
"credentials": req.Credentials,
},
})
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 PaymentSuccessful 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) {
2018-10-23 12:38:10 +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)
2018-08-30 14:55:42 +00:00
}
// Returns saved order info, if any
func (client *Client) GetSavedOrderInfo() (*OrderInfo, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOrderInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
// Deletes saved order info
func (client *Client) DeleteSavedOrderInfo() (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns a user that can be contacted to get support
func (client *Client) GetSupportUser() (*User, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUser(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
type GetBackgroundsRequest struct {
// True, if the backgrounds needs to be ordered for dark theme
ForDarkTheme bool `json:"for_dark_theme"`
}
// Returns backgrounds installed by the user
func (client *Client) GetBackgrounds(req *GetBackgroundsRequest) (*Backgrounds, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getBackgrounds",
},
Data: map[string]interface{}{
"for_dark_theme": req.ForDarkTheme,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalBackgrounds(result.Data)
}
type GetBackgroundUrlRequest struct {
// Background name
Name string `json:"name"`
// Background type
Type BackgroundType `json:"type"`
}
// Constructs a persistent HTTP URL for a background
func (client *Client) GetBackgroundUrl(req *GetBackgroundUrlRequest) (*HttpUrl, error) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalHttpUrl(result.Data)
}
type SearchBackgroundRequest struct {
// The name of the background
Name string `json:"name"`
}
// Searches for a background by its name
func (client *Client) SearchBackground(req *SearchBackgroundRequest) (*Background, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
2019-09-10 12:36:54 +00:00
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 {
2020-02-03 12:56:20 +00:00
// The input background to use, null for filled backgrounds
2019-09-10 12:36:54 +00:00
Background InputBackground `json:"background"`
// Background type; null for default background. The method will return error 404 if type is null
Type BackgroundType `json:"type"`
// True, if the background is chosen for dark theme
ForDarkTheme bool `json:"for_dark_theme"`
}
// Changes the background selected by the user; adds background to the list of installed backgrounds
func (client *Client) SetBackground(req *SetBackgroundRequest) (*Background, error) {
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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalBackground(result.Data)
}
type RemoveBackgroundRequest struct {
2020-02-03 12:56:20 +00:00
// The background identifier
2019-09-10 12:36:54 +00:00
BackgroundId JsonInt64 `json:"background_id"`
}
// Removes background from the list of installed backgrounds
func (client *Client) RemoveBackground(req *RemoveBackgroundRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "removeBackground",
},
Data: map[string]interface{}{
"background_id": req.BackgroundId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Resets list of installed backgrounds to its default value
func (client *Client) ResetBackgrounds() (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "resetBackgrounds",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2019-09-10 12:36:54 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type GetLocalizationTargetInfoRequest struct {
// If true, returns 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalLocalizationTargetInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type GetLanguagePackInfoRequest struct {
// Language pack identifier
LanguagePackId string `json:"language_pack_id"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "getLanguagePackInfo",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalLanguagePackInfo(result.Data)
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalLanguagePackStrings(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type SynchronizeLanguagePackRequest struct {
// Language pack identifier
LanguagePackId string `json:"language_pack_id"`
}
// 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
func (client *Client) SynchronizeLanguagePack(req *SynchronizeLanguagePackRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "synchronizeLanguagePack",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type AddCustomServerLanguagePackRequest struct {
// Identifier of a language pack to be added; may be different from a name that is used in an "https://t.me/setlanguage/" link
LanguagePackId string `json:"language_pack_id"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "addCustomServerLanguagePack",
},
Data: map[string]interface{}{
"language_pack_id": req.LanguagePackId,
},
})
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
type SetCustomLanguagePackRequest struct {
2019-06-07 10:56:06 +00:00
// Information about the language pack. Language pack ID must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters. Can be called before authorization
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type EditCustomLanguagePackInfoRequest struct {
2019-06-07 10:56:06 +00:00
// New information about the custom local language pack
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetCustomLanguagePackStringRequest struct {
2019-06-07 10:56:06 +00:00
// Identifier of a previously added custom local language pack in the current localization target
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type RegisterDeviceRequest struct {
// Device token
DeviceToken DeviceToken `json:"device_token"`
2019-06-07 10:56:06 +00:00
// List of user identifiers of other users currently using the client
2018-10-23 12:38:10 +00:00
OtherUserIds []int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2019-06-07 10:56:06 +00:00
return UnmarshalPushReceiverId(result.Data)
}
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"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "processPushNotification",
},
Data: map[string]interface{}{
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type GetPushReceiverIdRequest struct {
// JSON-encoded push notification payload
Payload string `json:"payload"`
}
// Returns a globally unique push notification subscription identifier for identification of an account, which has received a push notification. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetPushReceiverId(req *GetPushReceiverIdRequest) (*PushReceiverId, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "getPushReceiverId",
},
Data: map[string]interface{}{
"payload": req.Payload,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPushReceiverId(result.Data)
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTMeUrls(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalUserPrivacySettingRules(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type GetOptionRequest struct {
// The name of the option
Name string `json:"name"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +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
2018-10-16 20:32:57 +00:00
func (client *Client) GetOption(req *GetOptionRequest) (OptionValue, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypeOptionValueBoolean:
return UnmarshalOptionValueBoolean(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeOptionValueEmpty:
return UnmarshalOptionValueEmpty(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeOptionValueInteger:
return UnmarshalOptionValueInteger(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeOptionValueString:
return UnmarshalOptionValueString(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SetOptionRequest struct {
// The name of the option
Name string `json:"name"`
// The new value of the option
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalAccountTtl(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type DeleteAccountRequest struct {
// The reason why the account was deleted; optional
Reason string `json:"reason"`
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "deleteAccount",
},
Data: map[string]interface{}{
"reason": req.Reason,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2020-02-03 12:56:20 +00:00
type RemoveChatActionBarRequest struct {
2018-10-23 12:38:10 +00:00
// 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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
2020-02-03 12:56:20 +00:00
Type: "removeChatActionBar",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
}
2019-06-07 10:56:06 +00:00
type ReportChatRequest struct {
// Chat identifier
ChatId int64 `json:"chat_id"`
// The reason for reporting the chat
Reason ChatReportReason `json:"reason"`
// Identifiers of reported messages, if any
MessageIds []int64 `json:"message_ids"`
}
2020-02-03 12:56:20 +00:00
// Reports a chat to the Telegram moderators. Supported only for supergroups, channels, or private chats with bots, since other chats can't be checked by moderators, or when the report is done from the chat action bar
2019-06-07 10:56:06 +00:00
func (client *Client) ReportChat(req *ReportChatRequest) (*Ok, error) {
result, err := client.Send(Request{
meta: meta{
Type: "reportChat",
},
Data: map[string]interface{}{
"chat_id": req.ChatId,
"reason": req.Reason,
"message_ids": req.MessageIds,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
type GetChatStatisticsUrlRequest struct {
2018-10-23 12:38:10 +00:00
// Chat identifier
ChatId int64 `json:"chat_id"`
2019-06-07 10:56:06 +00:00
// Parameters from "tg://statsrefresh?params=******" link
Parameters string `json:"parameters"`
// Pass true if a URL with the dark theme must be returned
IsDark bool `json:"is_dark"`
2018-10-16 20:32:57 +00:00
}
2020-02-03 12:56:20 +00:00
// Returns an HTTP URL with the chat statistics. Currently this method can be used only for channels. Can be used only if SupergroupFullInfo.can_view_statistics == true
2019-06-07 10:56:06 +00:00
func (client *Client) GetChatStatisticsUrl(req *GetChatStatisticsUrlRequest) (*HttpUrl, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
2019-06-07 10:56:06 +00:00
Type: "getChatStatisticsUrl",
2018-10-23 12:38:10 +00:00
},
Data: map[string]interface{}{
2019-06-07 10:56:06 +00:00
"chat_id": req.ChatId,
"parameters": req.Parameters,
"is_dark": req.IsDark,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2019-06-07 10:56:06 +00:00
return UnmarshalHttpUrl(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type GetStorageStatisticsRequest struct {
2020-02-03 12:56:20 +00:00
// The maximum number of chats with the largest storage usage for which separate statistics should be returned. All other chats will be grouped in entries with chat_id == 0. If the chat info database is not used, the chat_limit is ignored and is always set to 0
2018-10-23 12:38:10 +00:00
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getStorageStatisticsFast",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalStorageStatisticsFast(result.Data)
}
2019-06-07 10:56:06 +00:00
// Returns database statistics
func (client *Client) GetDatabaseStatistics() (*DatabaseStatistics, error) {
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)
}
2018-10-23 12:38:10 +00:00
type OptimizeStorageRequest struct {
// Limit on the total size of files after deletion. Pass -1 to use the default limit
Size int64 `json:"size"`
// Limit on the time that has passed since the last time a file was accessed (or creation time for some filesystems). Pass -1 to use the default limit
Ttl int32 `json:"ttl"`
// Limit on the total count of files after deletion. Pass -1 to use the default limit
Count int32 `json:"count"`
// The amount of time after the creation of a file during which it can't be deleted, in seconds. Pass -1 to use the default value
ImmunityDelay int32 `json:"immunity_delay"`
// If not empty, only files with the given type(s) are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted
FileTypes []FileType `json:"file_types"`
// If not empty, only files from the given chats are considered. Use 0 as chat identifier to delete files not belonging to any chat (e.g., profile photos)
ChatIds []int64 `json:"chat_ids"`
// If not empty, files from the given chats are excluded. Use 0 as chat identifier to exclude all files not belonging to any chat (e.g., profile photos)
ExcludeChatIds []int64 `json:"exclude_chat_ids"`
// Same as in getStorageStatistics. Affects only returned statistics
ChatLimit int32 `json:"chat_limit"`
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) {
2018-10-23 12:38:10 +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,
"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. By default, networkTypeOther
Type NetworkType `json:"type"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +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 should be called whenever the network is changed, even if the network type remains the same. Network type is used to check whether the library can use the network at all and also for collecting detailed network data usage statistics
2018-10-16 20:32:57 +00:00
func (client *Client) SetNetworkType(req *SetNetworkTypeRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type GetNetworkStatisticsRequest struct {
// If true, returns only data 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalNetworkStatistics(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2019-09-10 12:36:54 +00:00
// Returns auto-download settings presets for the currently logged in user
func (client *Client) GetAutoDownloadSettingsPresets() (*AutoDownloadSettingsPresets, error) {
result, err := client.Send(Request{
meta: meta{
Type: "getAutoDownloadSettingsPresets",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalAutoDownloadSettingsPresets(result.Data)
}
type SetAutoDownloadSettingsRequest struct {
// New user auto-download settings
Settings *AutoDownloadSettings `json:"settings"`
// Type of the network for which the new settings are applied
Type NetworkType `json:"type"`
}
// Sets auto-download settings
func (client *Client) SetAutoDownloadSettings(req *SetAutoDownloadSettingsRequest) (*Ok, error) {
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)
}
2018-10-23 12:38:10 +00:00
type GetPassportElementRequest struct {
// Telegram Passport element type
Type PassportElementType `json:"type"`
// 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypePassportElementPersonalDetails:
return UnmarshalPassportElementPersonalDetails(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPassport:
return UnmarshalPassportElementPassport(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementDriverLicense:
return UnmarshalPassportElementDriverLicense(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementIdentityCard:
return UnmarshalPassportElementIdentityCard(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementInternalPassport:
return UnmarshalPassportElementInternalPassport(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementAddress:
return UnmarshalPassportElementAddress(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementUtilityBill:
return UnmarshalPassportElementUtilityBill(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementBankStatement:
return UnmarshalPassportElementBankStatement(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementRentalAgreement:
return UnmarshalPassportElementRentalAgreement(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPassportRegistration:
return UnmarshalPassportElementPassportRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementTemporaryRegistration:
return UnmarshalPassportElementTemporaryRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPhoneNumber:
return UnmarshalPassportElementPhoneNumber(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementEmailAddress:
return UnmarshalPassportElementEmailAddress(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type GetAllPassportElementsRequest struct {
// 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalPassportElements(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SetPassportElementRequest struct {
// Input Telegram Passport element
Element InputPassportElement `json:"element"`
// 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypePassportElementPersonalDetails:
return UnmarshalPassportElementPersonalDetails(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPassport:
return UnmarshalPassportElementPassport(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementDriverLicense:
return UnmarshalPassportElementDriverLicense(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementIdentityCard:
return UnmarshalPassportElementIdentityCard(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementInternalPassport:
return UnmarshalPassportElementInternalPassport(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementAddress:
return UnmarshalPassportElementAddress(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementUtilityBill:
return UnmarshalPassportElementUtilityBill(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementBankStatement:
return UnmarshalPassportElementBankStatement(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementRentalAgreement:
return UnmarshalPassportElementRentalAgreement(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPassportRegistration:
return UnmarshalPassportElementPassportRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementTemporaryRegistration:
return UnmarshalPassportElementTemporaryRegistration(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementPhoneNumber:
return UnmarshalPassportElementPhoneNumber(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypePassportElementEmailAddress:
return UnmarshalPassportElementEmailAddress(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +00:00
type SetPassportElementErrorsRequest struct {
// User identifier
UserId int32 `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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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
}
2018-09-05 21:45:29 +00:00
// Returns an IETF language tag of the language preferred in the country, which should be used to fill native fields in Telegram Passport personal details. Returns a 404 error if unknown
2018-10-16 20:32:57 +00:00
func (client *Client) GetPreferredCountryLanguage(req *GetPreferredCountryLanguageRequest) (*Text, error) {
2018-10-23 12:38:10 +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
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalText(result.Data)
}
type SendPhoneNumberVerificationCodeRequest struct {
// The phone number of the user, in international format
PhoneNumber string `json:"phone_number"`
2019-09-10 12:36:54 +00:00
// Settings for the authentication of the user's phone number
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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPhoneNumberVerificationCode",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"phone_number": req.PhoneNumber,
"settings": req.Settings,
2018-10-23 12:38:10 +00:00
},
})
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
}
// Re-sends the code to verify a phone number to be added to a user's Telegram Passport
func (client *Client) ResendPhoneNumberVerificationCode() (*AuthenticationCodeInfo, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckPhoneNumberVerificationCodeRequest struct {
// Verification code
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-09-05 21:45:29 +00:00
// Re-sends the code to verify an email address to be added to a user's Telegram Passport
func (client *Client) ResendEmailAddressVerificationCode() (*EmailAddressAuthenticationCodeInfo, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalEmailAddressAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckEmailAddressVerificationCodeRequest struct {
// Verification code
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) {
2018-10-23 12:38:10 +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 int32 `json:"bot_user_id"`
// Telegram Passport element types requested by the service
Scope string `json:"scope"`
// Service's public_key
PublicKey string `json:"public_key"`
// Authorization form nonce provided by the service
Nonce string `json:"nonce"`
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) {
2018-10-23 12:38:10 +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)
}
2019-06-07 10:56:06 +00:00
type GetPassportAuthorizationFormAvailableElementsRequest struct {
// Authorization form identifier
AutorizationFormId int32 `json:"autorization_form_id"`
// Password of the current user
Password string `json:"password"`
}
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "getPassportAuthorizationFormAvailableElements",
},
Data: map[string]interface{}{
"autorization_form_id": req.AutorizationFormId,
"password": req.Password,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalPassportElementsWithErrors(result.Data)
}
2018-10-23 12:38:10 +00:00
type SendPassportAuthorizationFormRequest struct {
// Authorization form identifier
AutorizationFormId int32 `json:"autorization_form_id"`
// Types of Telegram Passport elements chosen by user to complete the authorization form
Types []PassportElementType `json:"types"`
2018-10-16 20:32:57 +00:00
}
2019-06-07 10:56:06 +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 need to be used
2018-10-16 20:32:57 +00:00
func (client *Client) SendPassportAuthorizationForm(req *SendPassportAuthorizationFormRequest) (*Ok, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPassportAuthorizationForm",
},
Data: map[string]interface{}{
"autorization_form_id": req.AutorizationFormId,
"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 {
// Value of the "hash" parameter from the link
Hash string `json:"hash"`
// Value of the "phone" parameter from the link
PhoneNumber string `json:"phone_number"`
2019-09-10 12:36:54 +00:00
// Settings for the authentication of the user's phone number
Settings *PhoneNumberAuthenticationSettings `json:"settings"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Sends phone number confirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link
2018-10-16 20:32:57 +00:00
func (client *Client) SendPhoneNumberConfirmationCode(req *SendPhoneNumberConfirmationCodeRequest) (*AuthenticationCodeInfo, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "sendPhoneNumberConfirmationCode",
},
Data: map[string]interface{}{
2019-09-10 12:36:54 +00:00
"hash": req.Hash,
"phone_number": req.PhoneNumber,
"settings": req.Settings,
2018-10-23 12:38:10 +00:00
},
})
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalAuthenticationCodeInfo(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type CheckPhoneNumberConfirmationCodeRequest struct {
// The phone number confirmation code
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type UploadStickerFileRequest struct {
// Sticker file owner
UserId int32 `json:"user_id"`
// PNG image with the sticker; must be up to 512 kB in size and fit in 512x512 square
PngSticker InputFile `json:"png_sticker"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Uploads a PNG image with a sticker; for bots only; returns the uploaded file
2018-10-16 20:32:57 +00:00
func (client *Client) UploadStickerFile(req *UploadStickerFileRequest) (*File, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "uploadStickerFile",
},
Data: map[string]interface{}{
"user_id": req.UserId,
"png_sticker": req.PngSticker,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalFile(result.Data)
}
type CreateNewStickerSetRequest struct {
// Sticker set owner
UserId int32 `json:"user_id"`
// Sticker set title; 1-64 characters
Title string `json:"title"`
// Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_<bot username>"* (*<bot_username>* is case insensitive); 1-64 characters
Name string `json:"name"`
// True, if stickers are masks
IsMasks bool `json:"is_masks"`
// List of stickers to be added to the set
Stickers []*InputSticker `json:"stickers"`
2018-10-16 20:32:57 +00:00
}
2018-08-30 14:55:42 +00:00
// Creates a new sticker set; for bots only. Returns the newly created sticker set
2018-10-16 20:32:57 +00:00
func (client *Client) CreateNewStickerSet(req *CreateNewStickerSetRequest) (*StickerSet, error) {
2018-10-23 12:38:10 +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,
"is_masks": req.IsMasks,
"stickers": req.Stickers,
},
})
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 int32 `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
}
2018-08-30 14:55:42 +00:00
// Adds a new sticker to a set; for bots only. Returns the sticker set
2018-10-16 20:32:57 +00:00
func (client *Client) AddStickerToSet(req *AddStickerToSetRequest) (*StickerSet, error) {
2018-10-23 12:38:10 +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 UnmarshalStickerSet(result.Data)
}
type SetStickerPositionInSetRequest struct {
// Sticker
Sticker InputFile `json:"sticker"`
// New position of the sticker in the set, zero-based
Position int32 `json:"position"`
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "removeStickerFromSet",
},
Data: map[string]interface{}{
"sticker": req.Sticker,
},
})
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) {
2018-10-23 12:38:10 +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 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalCustomRequestResult(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +00:00
type SetAlarmRequest struct {
// Number of seconds before the function returns
Seconds float64 `json:"seconds"`
2018-10-16 20:32:57 +00:00
}
2018-09-05 21:45:29 +00:00
// Succeeds after a specified amount of time has passed. Can be called before authorization. Can be called before initialization
2018-10-16 20:32:57 +00:00
func (client *Client) SetAlarm(req *SetAlarmRequest) (*Ok, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
// Uses current user IP to found their 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
// Returns the default text for invitation messages to be used as a placeholder when the current user invites friends to Telegram
func (client *Client) GetInviteText() (*Text, error) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getInviteText",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalText(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "getDeepLinkInfo",
},
Data: map[string]interface{}{
"link": req.Link,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalDeepLinkInfo(result.Data)
}
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) {
result, err := client.Send(Request{
meta: meta{
Type: "getApplicationConfig",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeJsonValueNull:
return UnmarshalJsonValueNull(result.Data)
case TypeJsonValueBoolean:
return UnmarshalJsonValueBoolean(result.Data)
case TypeJsonValueNumber:
return UnmarshalJsonValueNumber(result.Data)
case TypeJsonValueString:
return UnmarshalJsonValueString(result.Data)
case TypeJsonValueArray:
return UnmarshalJsonValueArray(result.Data)
case TypeJsonValueObject:
return UnmarshalJsonValueObject(result.Data)
default:
return nil, errors.New("invalid type")
}
}
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"`
}
// Saves application log event on the server. Can be called before authorization
func (client *Client) SaveApplicationLogEvent(req *SaveApplicationLogEventRequest) (*Ok, error) {
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)
}
2018-10-23 12:38:10 +00:00
type AddProxyRequest struct {
// Proxy server IP address
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// True, if the proxy should be enabled
Enable bool `json:"enable"`
// Proxy type
Type ProxyType `json:"type"`
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) {
2018-10-23 12:38:10 +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"`
// Proxy server IP address
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// True, if the proxy should be enabled
Enable bool `json:"enable"`
// Proxy type
Type ProxyType `json:"type"`
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) {
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalProxies(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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
2018-10-16 20:32:57 +00:00
func (client *Client) GetProxyLink(req *GetProxyLinkRequest) (*Text, error) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalText(result.Data)
2018-09-05 21:45:29 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalSeconds(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-06-07 10:56:06 +00:00
type SetLogStreamRequest struct {
// New log stream
LogStream LogStream `json:"log_stream"`
}
// Sets new log stream for internal logging of TDLib. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) SetLogStream(req *SetLogStreamRequest) (*Ok, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "setLogStream",
},
Data: map[string]interface{}{
"log_stream": req.LogStream,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns information about currently used log stream for internal logging of TDLib. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetLogStream() (LogStream, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "getLogStream",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
switch result.Type {
case TypeLogStreamDefault:
return UnmarshalLogStreamDefault(result.Data)
case TypeLogStreamFile:
return UnmarshalLogStreamFile(result.Data)
case TypeLogStreamEmpty:
return UnmarshalLogStreamEmpty(result.Data)
default:
return nil, errors.New("invalid type")
}
}
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"`
}
// Sets the verbosity level of the internal logging of TDLib. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) SetLogVerbosityLevel(req *SetLogVerbosityLevelRequest) (*Ok, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "setLogVerbosityLevel",
},
Data: map[string]interface{}{
"new_verbosity_level": req.NewVerbosityLevel,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
// Returns current verbosity level of the internal logging of TDLib. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetLogVerbosityLevel() (*LogVerbosityLevel, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "getLogVerbosityLevel",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalLogVerbosityLevel(result.Data)
}
// Returns list of available TDLib internal log tags, for example, ["actor", "binlog", "connections", "notifications", "proxy"]. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetLogTags() (*LogTags, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "getLogTags",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalLogTags(result.Data)
}
type SetLogTagVerbosityLevelRequest struct {
// Logging tag to change verbosity level
Tag string `json:"tag"`
// New verbosity level; 1-1024
NewVerbosityLevel int32 `json:"new_verbosity_level"`
}
// Sets the verbosity level for a specified TDLib internal log tag. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) SetLogTagVerbosityLevel(req *SetLogTagVerbosityLevelRequest) (*Ok, error) {
result, err := client.jsonClient.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)
}
type GetLogTagVerbosityLevelRequest struct {
// Logging tag to change verbosity level
Tag string `json:"tag"`
}
// Returns current verbosity level for a specified TDLib internal log tag. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) GetLogTagVerbosityLevel(req *GetLogTagVerbosityLevelRequest) (*LogVerbosityLevel, error) {
result, err := client.jsonClient.Execute(Request{
meta: meta{
Type: "getLogTagVerbosityLevel",
},
Data: map[string]interface{}{
"tag": req.Tag,
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalLogVerbosityLevel(result.Data)
}
type AddLogMessageRequest struct {
2020-02-03 12:56:20 +00:00
// The minimum verbosity level needed for the message to be logged, 0-1023
2019-06-07 10:56:06 +00:00
VerbosityLevel int32 `json:"verbosity_level"`
// Text of a message to log
Text string `json:"text"`
}
// Adds a message to TDLib internal log. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) AddLogMessage(req *AddLogMessageRequest) (*Ok, error) {
result, err := client.jsonClient.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)
}
// 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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestString(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestBytes(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestVectorInt(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestVectorIntObject(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestVectorString(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalTestVectorStringObject(result.Data)
2018-08-30 14:55:42 +00:00
}
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +00:00
result, err := client.Send(Request{
meta: meta{
Type: "testNetwork",
},
Data: map[string]interface{}{},
})
if err != nil {
return nil, err
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return UnmarshalOk(result.Data)
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
type TestProxyRequest struct {
// Proxy server IP address
Server string `json:"server"`
// Proxy server port
Port int32 `json:"port"`
// Proxy type
Type ProxyType `json:"type"`
2020-02-03 12:56:20 +00:00
// 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) {
result, err := client.Send(Request{
meta: meta{
Type: "testProxy",
},
Data: map[string]interface{}{
2020-02-03 12:56:20 +00:00
"server": req.Server,
"port": req.Port,
"type": req.Type,
"dc_id": req.DcId,
"timeout": req.Timeout,
2019-09-10 12:36:54 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalOk(result.Data)
}
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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +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) {
2018-10-23 12:38:10 +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
2018-10-23 12:38:10 +00:00
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
switch result.Type {
case TypeUpdateAuthorizationState:
return UnmarshalUpdateAuthorizationState(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewMessage:
return UnmarshalUpdateNewMessage(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageSendAcknowledged:
return UnmarshalUpdateMessageSendAcknowledged(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageSendSucceeded:
return UnmarshalUpdateMessageSendSucceeded(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageSendFailed:
return UnmarshalUpdateMessageSendFailed(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageContent:
return UnmarshalUpdateMessageContent(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageEdited:
return UnmarshalUpdateMessageEdited(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageViews:
return UnmarshalUpdateMessageViews(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageContentOpened:
return UnmarshalUpdateMessageContentOpened(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateMessageMentionRead:
return UnmarshalUpdateMessageMentionRead(result.Data)
2018-08-30 14:55:42 +00:00
2020-02-03 12:56:20 +00:00
case TypeUpdateMessageLiveLocationViewed:
return UnmarshalUpdateMessageLiveLocationViewed(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateNewChat:
return UnmarshalUpdateNewChat(result.Data)
2018-08-30 14:55:42 +00:00
2020-02-03 12:56:20 +00:00
case TypeUpdateChatChatList:
return UnmarshalUpdateChatChatList(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateChatTitle:
return UnmarshalUpdateChatTitle(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatPhoto:
return UnmarshalUpdateChatPhoto(result.Data)
2018-08-30 14:55:42 +00:00
2019-09-10 12:36:54 +00:00
case TypeUpdateChatPermissions:
return UnmarshalUpdateChatPermissions(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateChatLastMessage:
return UnmarshalUpdateChatLastMessage(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatOrder:
return UnmarshalUpdateChatOrder(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatIsPinned:
return UnmarshalUpdateChatIsPinned(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatIsMarkedAsUnread:
return UnmarshalUpdateChatIsMarkedAsUnread(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatIsSponsored:
return UnmarshalUpdateChatIsSponsored(result.Data)
2018-09-05 21:45:29 +00:00
2020-02-03 12:56:20 +00:00
case TypeUpdateChatHasScheduledMessages:
return UnmarshalUpdateChatHasScheduledMessages(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateChatDefaultDisableNotification:
return UnmarshalUpdateChatDefaultDisableNotification(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatReadInbox:
return UnmarshalUpdateChatReadInbox(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatReadOutbox:
return UnmarshalUpdateChatReadOutbox(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatUnreadMentionCount:
return UnmarshalUpdateChatUnreadMentionCount(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatNotificationSettings:
return UnmarshalUpdateChatNotificationSettings(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateScopeNotificationSettings:
return UnmarshalUpdateScopeNotificationSettings(result.Data)
2018-08-30 14:55:42 +00:00
2020-02-03 12:56:20 +00:00
case TypeUpdateChatActionBar:
return UnmarshalUpdateChatActionBar(result.Data)
2019-06-07 10:56:06 +00:00
case TypeUpdateChatPinnedMessage:
return UnmarshalUpdateChatPinnedMessage(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateChatReplyMarkup:
return UnmarshalUpdateChatReplyMarkup(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateChatDraftMessage:
return UnmarshalUpdateChatDraftMessage(result.Data)
2018-08-30 14:55:42 +00:00
2019-06-07 10:56:06 +00:00
case TypeUpdateChatOnlineMemberCount:
return UnmarshalUpdateChatOnlineMemberCount(result.Data)
case TypeUpdateNotification:
return UnmarshalUpdateNotification(result.Data)
case TypeUpdateNotificationGroup:
return UnmarshalUpdateNotificationGroup(result.Data)
case TypeUpdateActiveNotifications:
return UnmarshalUpdateActiveNotifications(result.Data)
case TypeUpdateHavePendingNotifications:
return UnmarshalUpdateHavePendingNotifications(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateDeleteMessages:
return UnmarshalUpdateDeleteMessages(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUserChatAction:
return UnmarshalUpdateUserChatAction(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUserStatus:
return UnmarshalUpdateUserStatus(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUser:
return UnmarshalUpdateUser(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateBasicGroup:
return UnmarshalUpdateBasicGroup(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateSupergroup:
return UnmarshalUpdateSupergroup(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateSecretChat:
return UnmarshalUpdateSecretChat(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUserFullInfo:
return UnmarshalUpdateUserFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateBasicGroupFullInfo:
return UnmarshalUpdateBasicGroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateSupergroupFullInfo:
return UnmarshalUpdateSupergroupFullInfo(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateServiceNotification:
return UnmarshalUpdateServiceNotification(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateFile:
return UnmarshalUpdateFile(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateFileGenerationStart:
return UnmarshalUpdateFileGenerationStart(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateFileGenerationStop:
return UnmarshalUpdateFileGenerationStop(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateCall:
return UnmarshalUpdateCall(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUserPrivacySettingRules:
return UnmarshalUpdateUserPrivacySettingRules(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUnreadMessageCount:
return UnmarshalUpdateUnreadMessageCount(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateUnreadChatCount:
return UnmarshalUpdateUnreadChatCount(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateOption:
return UnmarshalUpdateOption(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateInstalledStickerSets:
return UnmarshalUpdateInstalledStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateTrendingStickerSets:
return UnmarshalUpdateTrendingStickerSets(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateRecentStickers:
return UnmarshalUpdateRecentStickers(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateFavoriteStickers:
return UnmarshalUpdateFavoriteStickers(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateSavedAnimations:
return UnmarshalUpdateSavedAnimations(result.Data)
2018-08-30 14:55:42 +00:00
2019-09-10 12:36:54 +00:00
case TypeUpdateSelectedBackground:
return UnmarshalUpdateSelectedBackground(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateLanguagePackStrings:
return UnmarshalUpdateLanguagePackStrings(result.Data)
2018-09-05 21:45:29 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateConnectionState:
return UnmarshalUpdateConnectionState(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateTermsOfService:
return UnmarshalUpdateTermsOfService(result.Data)
2018-09-05 21:45:29 +00:00
2020-02-03 12:56:20 +00:00
case TypeUpdateUsersNearby:
return UnmarshalUpdateUsersNearby(result.Data)
2018-10-23 12:38:10 +00:00
case TypeUpdateNewInlineQuery:
return UnmarshalUpdateNewInlineQuery(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewChosenInlineResult:
return UnmarshalUpdateNewChosenInlineResult(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewCallbackQuery:
return UnmarshalUpdateNewCallbackQuery(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewInlineCallbackQuery:
return UnmarshalUpdateNewInlineCallbackQuery(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewShippingQuery:
return UnmarshalUpdateNewShippingQuery(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewPreCheckoutQuery:
return UnmarshalUpdateNewPreCheckoutQuery(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewCustomEvent:
return UnmarshalUpdateNewCustomEvent(result.Data)
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
case TypeUpdateNewCustomQuery:
return UnmarshalUpdateNewCustomQuery(result.Data)
2018-08-30 14:55:42 +00:00
2019-06-07 10:56:06 +00:00
case TypeUpdatePoll:
return UnmarshalUpdatePoll(result.Data)
2020-02-03 12:56:20 +00:00
case TypeUpdatePollAnswer:
return UnmarshalUpdatePollAnswer(result.Data)
2018-10-23 12:38:10 +00:00
default:
return nil, errors.New("invalid type")
}
2018-08-30 14:55:42 +00:00
}
2019-09-10 12:36:54 +00:00
type TestReturnErrorRequest struct {
// The error to be returned
Error *Error `json:"error"`
}
// Returns the specified error and ensures that the Error object is used; for testing only. This is an offline method. Can be called before authorization. Can be called synchronously
func (client *Client) TestReturnError(req *TestReturnErrorRequest) (*Error, error) {
result, err := client.jsonClient.Execute(Request{
2018-10-23 12:38:10 +00:00
meta: meta{
2019-09-10 12:36:54 +00:00
Type: "testReturnError",
},
Data: map[string]interface{}{
"error": req.Error,
2018-10-23 12:38:10 +00:00
},
})
if err != nil {
return nil, err
}
if result.Type == "error" {
return nil, buildResponseError(result.Data)
}
return UnmarshalError(result.Data)
2018-08-30 14:55:42 +00:00
}