go-tdlib/methods.go

10413 lines
336 KiB
Go
Executable File

package tdlib
import (
"encoding/json"
"fmt"
)
// GetAuthorizationState Returns the current authorization state; this is an offline request. For informational purposes only. Use updateAuthorizationState instead to maintain the current authorization state. Can be called before initialization
func (client *Client) GetAuthorizationState() (AuthorizationState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getAuthorizationState",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
switch AuthorizationStateEnum(result.Data["@type"].(string)) {
case AuthorizationStateWaitTdlibParametersType:
var authorizationState AuthorizationStateWaitTdlibParameters
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitEncryptionKeyType:
var authorizationState AuthorizationStateWaitEncryptionKey
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitPhoneNumberType:
var authorizationState AuthorizationStateWaitPhoneNumber
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitCodeType:
var authorizationState AuthorizationStateWaitCode
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitOtherDeviceConfirmationType:
var authorizationState AuthorizationStateWaitOtherDeviceConfirmation
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitRegistrationType:
var authorizationState AuthorizationStateWaitRegistration
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateWaitPasswordType:
var authorizationState AuthorizationStateWaitPassword
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateReadyType:
var authorizationState AuthorizationStateReady
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateLoggingOutType:
var authorizationState AuthorizationStateLoggingOut
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateClosingType:
var authorizationState AuthorizationStateClosing
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
case AuthorizationStateClosedType:
var authorizationState AuthorizationStateClosed
err = json.Unmarshal(result.Raw, &authorizationState)
return &authorizationState, err
default:
return nil, fmt.Errorf("Invalid type")
}
}
// SetTdlibParameters Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters
// @param parameters Parameters
func (client *Client) SetTdlibParameters(parameters *TdlibParameters) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "setTdlibParameters",
"parameters": parameters,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// CheckDatabaseEncryptionKey Checks the database encryption key for correctness. Works only when the current authorization state is authorizationStateWaitEncryptionKey
// @param encryptionKey Encryption key to check or set up
func (client *Client) CheckDatabaseEncryptionKey(encryptionKey []byte) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkDatabaseEncryptionKey",
"encryption_key": encryptionKey,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// SetAuthenticationPhoneNumber Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber,
// @param phoneNumber The phone number of the user, in international format
// @param settings Settings for the authentication of the user's phone number
func (client *Client) SetAuthenticationPhoneNumber(phoneNumber string, settings *PhoneNumberAuthenticationSettings) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "setAuthenticationPhoneNumber",
"phone_number": phoneNumber,
"settings": settings,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// ResendAuthenticationCode 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) {
result, err := client.SendAndCatch(UpdateData{
"@type": "resendAuthenticationCode",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// CheckAuthenticationCode Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode
// @param code The verification code received via SMS, Telegram message, phone call, or flash call
func (client *Client) CheckAuthenticationCode(code string) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkAuthenticationCode",
"code": code,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RequestQrCodeAuthentication Requests QR code authentication by scanning a QR code on another logged in device. Works only when the current authorization state is authorizationStateWaitPhoneNumber,
// @param otherUserIDs List of user identifiers of other users currently using the application
func (client *Client) RequestQrCodeAuthentication(otherUserIDs []int32) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "requestQrCodeAuthentication",
"other_user_ids": otherUserIDs,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RegisterUser Finishes user registration. Works only when the current authorization state is authorizationStateWaitRegistration
// @param firstName The first name of the user; 1-64 characters
// @param lastName The last name of the user; 0-64 characters
func (client *Client) RegisterUser(firstName string, lastName string) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "registerUser",
"first_name": firstName,
"last_name": lastName,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// CheckAuthenticationPassword Checks the authentication password for correctness. Works only when the current authorization state is authorizationStateWaitPassword
// @param password The password to check
func (client *Client) CheckAuthenticationPassword(password string) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkAuthenticationPassword",
"password": password,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RequestAuthenticationPasswordRecovery 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) {
result, err := client.SendAndCatch(UpdateData{
"@type": "requestAuthenticationPasswordRecovery",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RecoverAuthenticationPassword Recovers the password with a password recovery code sent to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword
// @param recoveryCode Recovery code to check
func (client *Client) RecoverAuthenticationPassword(recoveryCode string) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "recoverAuthenticationPassword",
"recovery_code": recoveryCode,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// CheckAuthenticationBotToken Checks the authentication token of a bot; to log in as a bot. Works only when the current authorization state is authorizationStateWaitPhoneNumber. Can be used instead of setAuthenticationPhoneNumber and checkAuthenticationCode to log in
// @param token The bot token
func (client *Client) CheckAuthenticationBotToken(token string) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkAuthenticationBotToken",
"token": token,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var okDummy Ok
err = json.Unmarshal(result.Raw, &okDummy)
return &okDummy, err
}
// LogOut Closes the TDLib instance after a proper logout. Requires an available network connection. All local data will be destroyed. After the logout completes, updateAuthorizationState with authorizationStateClosed will be sent
func (client *Client) LogOut() (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "logOut",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// Close Closes the TDLib instance. All databases will be flushed to disk and properly closed. After the close completes, updateAuthorizationState with authorizationStateClosed will be sent. Can be called before initialization
func (client *Client) Close() (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "close",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// Destroy Closes the TDLib instance, destroying all local data without a proper logout. The current user session will remain in the list of all active sessions. All local data will be destroyed. After the destruction completes updateAuthorizationState with authorizationStateClosed will be sent. Can be called before authorization
func (client *Client) Destroy() (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "destroy",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// ConfirmQrCodeAuthentication Confirms QR code authentication on another device. Returns created session on success
// @param link A link from a QR code. The link must be scanned by the in-app camera
func (client *Client) ConfirmQrCodeAuthentication(link string) (*Session, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "confirmQrCodeAuthentication",
"link": link,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var session Session
err = json.Unmarshal(result.Raw, &session)
return &session, err
}
// GetCurrentState Returns all updates needed to restore current TDLib state, i.e. all actual UpdateAuthorizationState/UpdateUser/UpdateNewChat and others. This is especially useful if TDLib is run in a separate process. Can be called before initialization
func (client *Client) GetCurrentState() (*Updates, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getCurrentState",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var updates Updates
err = json.Unmarshal(result.Raw, &updates)
return &updates, err
}
// SetDatabaseEncryptionKey Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain
// @param newEncryptionKey New encryption key
func (client *Client) SetDatabaseEncryptionKey(newEncryptionKey []byte) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "setDatabaseEncryptionKey",
"new_encryption_key": newEncryptionKey,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// GetPasswordState Returns the current state of 2-step verification
func (client *Client) GetPasswordState() (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getPasswordState",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// SetPassword 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
// @param oldPassword Previous password of the user
// @param newPassword New password of the user; may be empty to remove the password
// @param newHint New password hint; may be empty
// @param setRecoveryEmailAddress Pass true if the recovery email address should be changed
// @param newRecoveryEmailAddress New recovery email address; may be empty
func (client *Client) SetPassword(oldPassword string, newPassword string, newHint string, setRecoveryEmailAddress bool, newRecoveryEmailAddress string) (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "setPassword",
"old_password": oldPassword,
"new_password": newPassword,
"new_hint": newHint,
"set_recovery_email_address": setRecoveryEmailAddress,
"new_recovery_email_address": newRecoveryEmailAddress,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// GetRecoveryEmailAddress 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
// @param password The password for the current user
func (client *Client) GetRecoveryEmailAddress(password string) (*RecoveryEmailAddress, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getRecoveryEmailAddress",
"password": password,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var recoveryEmailAddress RecoveryEmailAddress
err = json.Unmarshal(result.Raw, &recoveryEmailAddress)
return &recoveryEmailAddress, err
}
// SetRecoveryEmailAddress 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.
// @param password
// @param newRecoveryEmailAddress
func (client *Client) SetRecoveryEmailAddress(password string, newRecoveryEmailAddress string) (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "setRecoveryEmailAddress",
"password": password,
"new_recovery_email_address": newRecoveryEmailAddress,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// CheckRecoveryEmailAddressCode Checks the 2-step verification recovery email address verification code
// @param code Verification code
func (client *Client) CheckRecoveryEmailAddressCode(code string) (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkRecoveryEmailAddressCode",
"code": code,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// ResendRecoveryEmailAddressCode Resends the 2-step verification recovery email address verification code
func (client *Client) ResendRecoveryEmailAddressCode() (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "resendRecoveryEmailAddressCode",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// RequestPasswordRecovery Requests to send a password recovery code to an email address that was previously set up
func (client *Client) RequestPasswordRecovery() (*EmailAddressAuthenticationCodeInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "requestPasswordRecovery",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var emailAddressAuthenticationCodeInfo EmailAddressAuthenticationCodeInfo
err = json.Unmarshal(result.Raw, &emailAddressAuthenticationCodeInfo)
return &emailAddressAuthenticationCodeInfo, err
}
// RecoverPassword Recovers the password using a recovery code sent to an email address that was previously set up
// @param recoveryCode Recovery code to check
func (client *Client) RecoverPassword(recoveryCode string) (*PasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "recoverPassword",
"recovery_code": recoveryCode,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var passwordState PasswordState
err = json.Unmarshal(result.Raw, &passwordState)
return &passwordState, err
}
// CreateTemporaryPassword Creates a new temporary password for processing payments
// @param password Persistent user password
// @param validFor Time during which the temporary password will be valid, in seconds; should be between 60 and 86400
func (client *Client) CreateTemporaryPassword(password string, validFor int32) (*TemporaryPasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "createTemporaryPassword",
"password": password,
"valid_for": validFor,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var temporaryPasswordState TemporaryPasswordState
err = json.Unmarshal(result.Raw, &temporaryPasswordState)
return &temporaryPasswordState, err
}
// GetTemporaryPasswordState Returns information about the current temporary password
func (client *Client) GetTemporaryPasswordState() (*TemporaryPasswordState, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getTemporaryPasswordState",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var temporaryPasswordState TemporaryPasswordState
err = json.Unmarshal(result.Raw, &temporaryPasswordState)
return &temporaryPasswordState, err
}
// GetMe Returns the current user
func (client *Client) GetMe() (*User, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMe",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var user User
err = json.Unmarshal(result.Raw, &user)
return &user, err
}
// GetUser Returns information about a user by their identifier. This is an offline request if the current user is not a bot
// @param userID User identifier
func (client *Client) GetUser(userID int32) (*User, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getUser",
"user_id": userID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var userDummy User
err = json.Unmarshal(result.Raw, &userDummy)
return &userDummy, err
}
// GetUserFullInfo Returns full information about a user by their identifier
// @param userID User identifier
func (client *Client) GetUserFullInfo(userID int32) (*UserFullInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getUserFullInfo",
"user_id": userID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var userFullInfo UserFullInfo
err = json.Unmarshal(result.Raw, &userFullInfo)
return &userFullInfo, err
}
// GetBasicGroup Returns information about a basic group by its identifier. This is an offline request if the current user is not a bot
// @param basicGroupID Basic group identifier
func (client *Client) GetBasicGroup(basicGroupID int32) (*BasicGroup, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getBasicGroup",
"basic_group_id": basicGroupID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var basicGroupDummy BasicGroup
err = json.Unmarshal(result.Raw, &basicGroupDummy)
return &basicGroupDummy, err
}
// GetBasicGroupFullInfo Returns full information about a basic group by its identifier
// @param basicGroupID Basic group identifier
func (client *Client) GetBasicGroupFullInfo(basicGroupID int32) (*BasicGroupFullInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getBasicGroupFullInfo",
"basic_group_id": basicGroupID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var basicGroupFullInfo BasicGroupFullInfo
err = json.Unmarshal(result.Raw, &basicGroupFullInfo)
return &basicGroupFullInfo, err
}
// GetSupergroup Returns information about a supergroup or a channel by its identifier. This is an offline request if the current user is not a bot
// @param supergroupID Supergroup or channel identifier
func (client *Client) GetSupergroup(supergroupID int32) (*Supergroup, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getSupergroup",
"supergroup_id": supergroupID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var supergroupDummy Supergroup
err = json.Unmarshal(result.Raw, &supergroupDummy)
return &supergroupDummy, err
}
// GetSupergroupFullInfo Returns full information about a supergroup or a channel by its identifier, cached for up to 1 minute
// @param supergroupID Supergroup or channel identifier
func (client *Client) GetSupergroupFullInfo(supergroupID int32) (*SupergroupFullInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getSupergroupFullInfo",
"supergroup_id": supergroupID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var supergroupFullInfo SupergroupFullInfo
err = json.Unmarshal(result.Raw, &supergroupFullInfo)
return &supergroupFullInfo, err
}
// GetSecretChat Returns information about a secret chat by its identifier. This is an offline request
// @param secretChatID Secret chat identifier
func (client *Client) GetSecretChat(secretChatID int32) (*SecretChat, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getSecretChat",
"secret_chat_id": secretChatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var secretChatDummy SecretChat
err = json.Unmarshal(result.Raw, &secretChatDummy)
return &secretChatDummy, err
}
// GetChat Returns information about a chat by its identifier, this is an offline request if the current user is not a bot
// @param chatID Chat identifier
func (client *Client) GetChat(chatID int64) (*Chat, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChat",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chatDummy Chat
err = json.Unmarshal(result.Raw, &chatDummy)
return &chatDummy, err
}
// GetMessage Returns information about a message
// @param chatID Identifier of the chat the message belongs to
// @param messageID Identifier of the message to get
func (client *Client) GetMessage(chatID int64, messageID int64) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessage",
"chat_id": chatID,
"message_id": messageID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// GetMessageLocally Returns information about a message, if it is available locally without sending network request. This is an offline request
// @param chatID Identifier of the chat the message belongs to
// @param messageID Identifier of the message to get
func (client *Client) GetMessageLocally(chatID int64, messageID int64) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageLocally",
"chat_id": chatID,
"message_id": messageID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// GetRepliedMessage Returns information about a message that is replied by a given message. Also returns the pinned message, the game message, and the invoice message for messages of the types messagePinMessage, messageGameScore, and messagePaymentSuccessful respectively
// @param chatID Identifier of the chat the message belongs to
// @param messageID Identifier of the message reply to which to get
func (client *Client) GetRepliedMessage(chatID int64, messageID int64) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getRepliedMessage",
"chat_id": chatID,
"message_id": messageID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// GetChatPinnedMessage Returns information about a newest pinned message in the chat
// @param chatID Identifier of the chat the message belongs to
func (client *Client) GetChatPinnedMessage(chatID int64) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChatPinnedMessage",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var message Message
err = json.Unmarshal(result.Raw, &message)
return &message, err
}
// GetCallbackQueryMessage Returns information about a message with the callback button that originated a callback query; for bots only
// @param chatID Identifier of the chat the message belongs to
// @param messageID Message identifier
// @param callbackQueryID Identifier of the callback query
func (client *Client) GetCallbackQueryMessage(chatID int64, messageID int64, callbackQueryID JSONInt64) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getCallbackQueryMessage",
"chat_id": chatID,
"message_id": messageID,
"callback_query_id": callbackQueryID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// GetMessages Returns information about messages. If a message is not found, returns null on the corresponding position of the result
// @param chatID Identifier of the chat the messages belong to
// @param messageIDs Identifiers of the messages to get
func (client *Client) GetMessages(chatID int64, messageIDs []int64) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessages",
"chat_id": chatID,
"message_ids": messageIDs,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetMessageThread Returns information about a message thread. Can be used only if message.can_get_message_thread == true
// @param chatID Chat identifier
// @param messageID Identifier of the message
func (client *Client) GetMessageThread(chatID int64, messageID int64) (*MessageThreadInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageThread",
"chat_id": chatID,
"message_id": messageID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageThreadInfo MessageThreadInfo
err = json.Unmarshal(result.Raw, &messageThreadInfo)
return &messageThreadInfo, err
}
// GetFile Returns information about a file; this is an offline request
// @param fileID Identifier of the file to get
func (client *Client) GetFile(fileID int32) (*File, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getFile",
"file_id": fileID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var fileDummy File
err = json.Unmarshal(result.Raw, &fileDummy)
return &fileDummy, err
}
// GetRemoteFile 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.
// @param remoteFileID Remote identifier of the file to get
// @param fileType File type, if known
func (client *Client) GetRemoteFile(remoteFileID string, fileType FileType) (*File, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getRemoteFile",
"remote_file_id": remoteFileID,
"file_type": fileType,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var fileDummy File
err = json.Unmarshal(result.Raw, &fileDummy)
return &fileDummy, err
}
// GetChats Returns an ordered list of chats in a chat list. Chats are sorted by the pair (chat.position.order, chat.id) in descending 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).
// @param chatList The chat list in which to return chats
// @param offsetOrder Chat order to return chats from
// @param offsetChatID Chat identifier to return chats from
// @param limit The maximum number of chats to be returned. It is possible that fewer chats than the limit are returned even if the end of the list is not reached
func (client *Client) GetChats(chatList ChatList, offsetOrder JSONInt64, offsetChatID int64, limit int32) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChats",
"chat_list": chatList,
"offset_order": offsetOrder,
"offset_chat_id": offsetChatID,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// SearchPublicChat Searches a public chat by its username. Currently only private chats, supergroups and channels can be public. Returns the chat if found; otherwise an error is returned
// @param username Username to be resolved
func (client *Client) SearchPublicChat(username string) (*Chat, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchPublicChat",
"username": username,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chat Chat
err = json.Unmarshal(result.Raw, &chat)
return &chat, err
}
// SearchPublicChats Searches public chats by looking for specified query in their username and title. Currently only private chats, supergroups and channels can be public. Returns a meaningful number of results. Returns nothing if the length of the searched username prefix is less than 5. Excludes private chats with contacts and chats from the chat list from the results
// @param query Query to search for
func (client *Client) SearchPublicChats(query string) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchPublicChats",
"query": query,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// SearchChats Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the main chat list
// @param query Query to search for. If the query is empty, returns up to 20 recently found chats
// @param limit The maximum number of chats to be returned
func (client *Client) SearchChats(query string, limit int32) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchChats",
"query": query,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// SearchChatsOnServer Searches for the specified query in the title and username of already known chats via request to the server. Returns chats in the order seen in the main chat list
// @param query Query to search for
// @param limit The maximum number of chats to be returned
func (client *Client) SearchChatsOnServer(query string, limit int32) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchChatsOnServer",
"query": query,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// SearchChatsNearby 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
// @param location Current user location
func (client *Client) SearchChatsNearby(location *Location) (*ChatsNearby, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchChatsNearby",
"location": location,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chatsNearby ChatsNearby
err = json.Unmarshal(result.Raw, &chatsNearby)
return &chatsNearby, err
}
// GetTopChats Returns a list of frequently used chats. Supported only if the chat info database is enabled
// @param category Category of chats to be returned
// @param limit The maximum number of chats to be returned; up to 30
func (client *Client) GetTopChats(category TopChatCategory, limit int32) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getTopChats",
"category": category,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// RemoveTopChat Removes a chat from the list of frequently used chats. Supported only if the chat info database is enabled
// @param category Category of frequently used chats
// @param chatID Chat identifier
func (client *Client) RemoveTopChat(category TopChatCategory, chatID int64) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "removeTopChat",
"category": category,
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// AddRecentlyFoundChat Adds a chat to the list of recently found chats. The chat is added to the beginning of the list. If the chat is already in the list, it will be removed from the list first
// @param chatID Identifier of the chat to add
func (client *Client) AddRecentlyFoundChat(chatID int64) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "addRecentlyFoundChat",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RemoveRecentlyFoundChat Removes a chat from the list of recently found chats
// @param chatID Identifier of the chat to be removed
func (client *Client) RemoveRecentlyFoundChat(chatID int64) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "removeRecentlyFoundChat",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// ClearRecentlyFoundChats Clears the list of recently found chats
func (client *Client) ClearRecentlyFoundChats() (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "clearRecentlyFoundChats",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// CheckChatUsername Checks whether a username can be set for a chat
// @param chatID Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created
// @param username Username to be checked
func (client *Client) CheckChatUsername(chatID int64, username string) (CheckChatUsernameResult, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkChatUsername",
"chat_id": chatID,
"username": username,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
switch CheckChatUsernameResultEnum(result.Data["@type"].(string)) {
case CheckChatUsernameResultOkType:
var checkChatUsernameResult CheckChatUsernameResultOk
err = json.Unmarshal(result.Raw, &checkChatUsernameResult)
return &checkChatUsernameResult, err
case CheckChatUsernameResultUsernameInvalidType:
var checkChatUsernameResult CheckChatUsernameResultUsernameInvalid
err = json.Unmarshal(result.Raw, &checkChatUsernameResult)
return &checkChatUsernameResult, err
case CheckChatUsernameResultUsernameOccupiedType:
var checkChatUsernameResult CheckChatUsernameResultUsernameOccupied
err = json.Unmarshal(result.Raw, &checkChatUsernameResult)
return &checkChatUsernameResult, err
case CheckChatUsernameResultPublicChatsTooMuchType:
var checkChatUsernameResult CheckChatUsernameResultPublicChatsTooMuch
err = json.Unmarshal(result.Raw, &checkChatUsernameResult)
return &checkChatUsernameResult, err
case CheckChatUsernameResultPublicGroupsUnavailableType:
var checkChatUsernameResult CheckChatUsernameResultPublicGroupsUnavailable
err = json.Unmarshal(result.Raw, &checkChatUsernameResult)
return &checkChatUsernameResult, err
default:
return nil, fmt.Errorf("Invalid type")
}
}
// GetCreatedPublicChats Returns a list of public chats of the specified type, owned by the user
// @param typeParam Type of the public chats to return
func (client *Client) GetCreatedPublicChats(typeParam PublicChatType) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getCreatedPublicChats",
"type": typeParam,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// CheckCreatedPublicChatsLimit Checks whether the maximum number of owned public chats has been reached. Returns corresponding error if the limit was reached
// @param typeParam Type of the public chats, for which to check the limit
func (client *Client) CheckCreatedPublicChatsLimit(typeParam PublicChatType) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "checkCreatedPublicChatsLimit",
"type": typeParam,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// GetSuitableDiscussionChats Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Returned basic group chats must be first upgraded to supergroups before they can be set as a discussion group. To set a returned supergroup as a discussion group, access to its old messages must be enabled using toggleSupergroupIsAllHistoryAvailable first
func (client *Client) GetSuitableDiscussionChats() (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getSuitableDiscussionChats",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// GetInactiveSupergroupChats 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.SendAndCatch(UpdateData{
"@type": "getInactiveSupergroupChats",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// GetGroupsInCommon Returns a list of common group chats with a given user. Chats are sorted by their type and creation date
// @param userID User identifier
// @param offsetChatID Chat identifier starting from which to return chats; use 0 for the first request
// @param limit The maximum number of chats to be returned; up to 100
func (client *Client) GetGroupsInCommon(userID int32, offsetChatID int64, limit int32) (*Chats, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getGroupsInCommon",
"user_id": userID,
"offset_chat_id": offsetChatID,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var chats Chats
err = json.Unmarshal(result.Raw, &chats)
return &chats, err
}
// GetChatHistory Returns messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id).
// @param chatID Chat identifier
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset up to 99 to get additionally some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than 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
// @param onlyLocal If true, returns only messages that are available locally without sending network requests
func (client *Client) GetChatHistory(chatID int64, fromMessageID int64, offset int32, limit int32, onlyLocal bool) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChatHistory",
"chat_id": chatID,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
"only_local": onlyLocal,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetMessageThreadHistory Returns messages in a message thread of a message. Can be used only if message.can_get_message_thread == true. Message thread of a channel message is in the channel's linked supergroup.
// @param chatID Chat identifier
// @param messageID Message identifier, which thread history needs to be returned
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset up to 99 to get additionally some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than or equal to -offset. Fewer messages may be returned than specified by the limit, even if the end of the message thread history has not been reached
func (client *Client) GetMessageThreadHistory(chatID int64, messageID int64, fromMessageID int64, offset int32, limit int32) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageThreadHistory",
"chat_id": chatID,
"message_id": messageID,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// DeleteChatHistory 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
// @param chatID Chat identifier
// @param removeFromChatList Pass true if the chat should be removed from the chat list
// @param revoke Pass true to try to delete chat history for all users
func (client *Client) DeleteChatHistory(chatID int64, removeFromChatList bool, revoke bool) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "deleteChatHistory",
"chat_id": chatID,
"remove_from_chat_list": removeFromChatList,
"revoke": revoke,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var okDummy Ok
err = json.Unmarshal(result.Raw, &okDummy)
return &okDummy, err
}
// DeleteChat Deletes a chat along with all messages in the corresponding chat for all chat members; requires owner privileges. For group chats this will release the username and remove all members. Chats with more than 1000 members can't be deleted using this method
// @param chatID Chat identifier
func (client *Client) DeleteChat(chatID int64) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "deleteChat",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// SearchChatMessages 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
// @param chatID Identifier of the chat in which to search messages
// @param query Query to search for
// @param sender If not null, only messages sent by the specified sender will be returned. Not supported in secret chats
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
// @param filter Filter for message content in the search results
// @param messageThreadID If not 0, only messages in the specified thread will be returned; supergroups only
func (client *Client) SearchChatMessages(chatID int64, query string, sender MessageSender, fromMessageID int64, offset int32, limit int32, filter SearchMessagesFilter, messageThreadID int64) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchChatMessages",
"chat_id": chatID,
"query": query,
"sender": sender,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
"filter": filter,
"message_thread_id": messageThreadID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchMessages 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)).
// @param chatList Chat list in which to search messages; pass null to search in all chats regardless of their chat list
// @param query Query to search for
// @param offsetDate The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message
// @param offsetChatID The chat identifier of the last found message, or 0 for the first request
// @param offsetMessageID The message identifier of the last found message, or 0 for the first request
// @param limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
// @param filter Filter for message content in the search results; searchMessagesFilterCall, searchMessagesFilterMissedCall, searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterFailedToSend and searchMessagesFilterPinned are unsupported in this function
// @param minDate If not 0, the minimum date of the messages to return
// @param maxDate If not 0, the maximum date of the messages to return
func (client *Client) SearchMessages(chatList ChatList, query string, offsetDate int32, offsetChatID int64, offsetMessageID int64, limit int32, filter SearchMessagesFilter, minDate int32, maxDate int32) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchMessages",
"chat_list": chatList,
"query": query,
"offset_date": offsetDate,
"offset_chat_id": offsetChatID,
"offset_message_id": offsetMessageID,
"limit": limit,
"filter": filter,
"min_date": minDate,
"max_date": maxDate,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchSecretMessages Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance the number of returned messages is chosen by the library
// @param chatID Identifier of the chat in which to search. Specify 0 to search in all secret chats
// @param query Query to search for. If empty, searchChatMessages should be used instead
// @param offset Offset of the first entry to return as received from the previous request; use empty string to get first chunk of results
// @param limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
// @param filter A filter for message content in the search results
func (client *Client) SearchSecretMessages(chatID int64, query string, offset string, limit int32, filter SearchMessagesFilter) (*FoundMessages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchSecretMessages",
"chat_id": chatID,
"query": query,
"offset": offset,
"limit": limit,
"filter": filter,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var foundMessages FoundMessages
err = json.Unmarshal(result.Raw, &foundMessages)
return &foundMessages, err
}
// SearchCallMessages Searches for call messages. Returns the results in reverse chronological order (i. e., in order of decreasing message_id). For optimal performance the number of returned messages is chosen by the library
// @param fromMessageID Identifier of the message from which to search; use 0 to get results from the last message
// @param limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached
// @param onlyMissed If true, returns only messages with missed calls
func (client *Client) SearchCallMessages(fromMessageID int64, limit int32, onlyMissed bool) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchCallMessages",
"from_message_id": fromMessageID,
"limit": limit,
"only_missed": onlyMissed,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// DeleteAllCallMessages Deletes all call messages
// @param revoke Pass true to delete the messages for all users
func (client *Client) DeleteAllCallMessages(revoke bool) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "deleteAllCallMessages",
"revoke": revoke,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var okDummy Ok
err = json.Unmarshal(result.Raw, &okDummy)
return &okDummy, err
}
// SearchChatRecentLocationMessages Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user
// @param chatID Chat identifier
// @param limit The maximum number of messages to be returned
func (client *Client) SearchChatRecentLocationMessages(chatID int64, limit int32) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "searchChatRecentLocationMessages",
"chat_id": chatID,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetActiveLiveLocationMessages Returns all active live locations that should be updated by the application. The list is persistent across application restarts only if the message database is used
func (client *Client) GetActiveLiveLocationMessages() (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getActiveLiveLocationMessages",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetChatMessageByDate Returns the last message sent in a chat no later than the specified date
// @param chatID Chat identifier
// @param date Point in time (Unix timestamp) relative to which to search for messages
func (client *Client) GetChatMessageByDate(chatID int64, date int32) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChatMessageByDate",
"chat_id": chatID,
"date": date,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var message Message
err = json.Unmarshal(result.Raw, &message)
return &message, err
}
// GetChatMessageCount Returns approximate number of messages of the specified type in the chat
// @param chatID Identifier of the chat in which to count messages
// @param filter Filter for message content; searchMessagesFilterEmpty is unsupported in this function
// @param returnLocal If true, returns count that is available locally without sending network requests, returning -1 if the number of messages is unknown
func (client *Client) GetChatMessageCount(chatID int64, filter SearchMessagesFilter, returnLocal bool) (*Count, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChatMessageCount",
"chat_id": chatID,
"filter": filter,
"return_local": returnLocal,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var count Count
err = json.Unmarshal(result.Raw, &count)
return &count, err
}
// GetChatScheduledMessages Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id)
// @param chatID Chat identifier
func (client *Client) GetChatScheduledMessages(chatID int64) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getChatScheduledMessages",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetMessagePublicForwards Returns forwarded copies of a channel message to different public channels. For optimal performance the number of returned messages is chosen by the library
// @param chatID Chat identifier of the message
// @param messageID Message identifier
// @param offset Offset of the first entry to return as received from the previous request; use empty string to get first chunk of results
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. Fewer messages may be returned than specified by the limit, even if the end of the list has not been reached
func (client *Client) GetMessagePublicForwards(chatID int64, messageID int64, offset string, limit int32) (*FoundMessages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessagePublicForwards",
"chat_id": chatID,
"message_id": messageID,
"offset": offset,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var foundMessages FoundMessages
err = json.Unmarshal(result.Raw, &foundMessages)
return &foundMessages, err
}
// RemoveNotification Removes an active notification from notification list. Needs to be called only if the notification is removed by the current user
// @param notificationGroupID Identifier of notification group to which the notification belongs
// @param notificationID Identifier of removed notification
func (client *Client) RemoveNotification(notificationGroupID int32, notificationID int32) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "removeNotification",
"notification_group_id": notificationGroupID,
"notification_id": notificationID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// RemoveNotificationGroup Removes a group of active notifications. Needs to be called only if the notification group is removed by the current user
// @param notificationGroupID Notification group identifier
// @param maxNotificationID The maximum identifier of removed notifications
func (client *Client) RemoveNotificationGroup(notificationGroupID int32, maxNotificationID int32) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "removeNotificationGroup",
"notification_group_id": notificationGroupID,
"max_notification_id": maxNotificationID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// GetMessageLink Returns an HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels. This is an offline request
// @param chatID Identifier of the chat to which the message belongs
// @param messageID Identifier of the message
// @param forAlbum Pass true to create a link for the whole media album
// @param forComment Pass true to create a link to the message as a channel post comment, or from a message thread
func (client *Client) GetMessageLink(chatID int64, messageID int64, forAlbum bool, forComment bool) (*MessageLink, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageLink",
"chat_id": chatID,
"message_id": messageID,
"for_album": forAlbum,
"for_comment": forComment,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageLink MessageLink
err = json.Unmarshal(result.Raw, &messageLink)
return &messageLink, err
}
// GetMessageEmbeddingCode Returns an HTML code for embedding the message. Available only for messages in supergroups and channels with a username
// @param chatID Identifier of the chat to which the message belongs
// @param messageID Identifier of the message
// @param forAlbum Pass true to return an HTML code for embedding of the whole media album
func (client *Client) GetMessageEmbeddingCode(chatID int64, messageID int64, forAlbum bool) (*Text, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageEmbeddingCode",
"chat_id": chatID,
"message_id": messageID,
"for_album": forAlbum,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var text Text
err = json.Unmarshal(result.Raw, &text)
return &text, err
}
// GetMessageLinkInfo Returns information about a public or private message link
// @param uRL The message link in the format "https://t.me/c/...", or "tg://privatepost?...", or "https://t.me/username/...", or "tg://resolve?..."
func (client *Client) GetMessageLinkInfo(uRL string) (*MessageLinkInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getMessageLinkInfo",
"url": uRL,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageLinkInfo MessageLinkInfo
err = json.Unmarshal(result.Raw, &messageLinkInfo)
return &messageLinkInfo, err
}
// SendMessage Sends a message. Returns the sent message
// @param chatID Target chat
// @param messageThreadID If not 0, a message thread identifier in which the message will be sent
// @param replyToMessageID Identifier of the message to reply to or 0
// @param options Options to be used to send the message
// @param replyMarkup Markup for replying to the message; for bots only
// @param inputMessageContent The content of the message to be sent
func (client *Client) SendMessage(chatID int64, messageThreadID int64, replyToMessageID int64, options *MessageSendOptions, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendMessage",
"chat_id": chatID,
"message_thread_id": messageThreadID,
"reply_to_message_id": replyToMessageID,
"options": options,
"reply_markup": replyMarkup,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// SendMessageAlbum Sends 2-10 messages grouped together into an album. Currently only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages
// @param chatID Target chat
// @param messageThreadID If not 0, a message thread identifier in which the messages will be sent
// @param replyToMessageID Identifier of a message to reply to or 0
// @param options Options to be used to send the messages
// @param inputMessageContents Contents of messages to be sent. At most 10 messages can be added to an album
func (client *Client) SendMessageAlbum(chatID int64, messageThreadID int64, replyToMessageID int64, options *MessageSendOptions, inputMessageContents []InputMessageContent) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendMessageAlbum",
"chat_id": chatID,
"message_thread_id": messageThreadID,
"reply_to_message_id": replyToMessageID,
"options": options,
"input_message_contents": inputMessageContents,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SendBotStartMessage Invites a bot to a chat (if it is not yet a member) and sends it the /start command. Bots can't be invited to a private chat other than the chat with the bot. Bots can't be invited to channels (although they can be added as admins) and secret chats. Returns the sent message
// @param botUserID Identifier of the bot
// @param chatID Identifier of the target chat
// @param parameter A hidden parameter sent to the bot for deep linking purposes (https://core.telegram.org/bots#deep-linking)
func (client *Client) SendBotStartMessage(botUserID int32, chatID int64, parameter string) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendBotStartMessage",
"bot_user_id": botUserID,
"chat_id": chatID,
"parameter": parameter,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var message Message
err = json.Unmarshal(result.Raw, &message)
return &message, err
}
// SendInlineQueryResultMessage Sends the result of an inline query as a message. Returns the sent message. Always clears a chat draft message
// @param chatID Target chat
// @param messageThreadID If not 0, a message thread identifier in which the message will be sent
// @param replyToMessageID Identifier of a message to reply to or 0
// @param options Options to be used to send the message
// @param queryID Identifier of the inline query
// @param resultID Identifier of the inline result
// @param hideViaBot 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")
func (client *Client) SendInlineQueryResultMessage(chatID int64, messageThreadID int64, replyToMessageID int64, options *MessageSendOptions, queryID JSONInt64, resultID string, hideViaBot bool) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendInlineQueryResultMessage",
"chat_id": chatID,
"message_thread_id": messageThreadID,
"reply_to_message_id": replyToMessageID,
"options": options,
"query_id": queryID,
"result_id": resultID,
"hide_via_bot": hideViaBot,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// ForwardMessages Forwards previously sent messages. Returns the forwarded messages in the same order as the message identifiers passed in message_ids. If a message can't be forwarded, null will be returned instead of the message
// @param chatID Identifier of the chat to which to forward messages
// @param fromChatID Identifier of the chat from which to forward messages
// @param messageIDs Identifiers of the messages to forward. Message identifiers must be in a strictly increasing order. At most 100 messages can be forwarded simultaneously
// @param options Options to be used to send the messages
// @param sendCopy 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
// @param removeCaption True, if media caption of message copies needs to be removed. Ignored if send_copy is false
func (client *Client) ForwardMessages(chatID int64, fromChatID int64, messageIDs []int64, options *MessageSendOptions, sendCopy bool, removeCaption bool) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "forwardMessages",
"chat_id": chatID,
"from_chat_id": fromChatID,
"message_ids": messageIDs,
"options": options,
"send_copy": sendCopy,
"remove_caption": removeCaption,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// ResendMessages 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.
// @param chatID Identifier of the chat to send messages
// @param messageIDs Identifiers of the messages to resend. Message identifiers must be in a strictly increasing order
func (client *Client) ResendMessages(chatID int64, messageIDs []int64) (*Messages, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "resendMessages",
"chat_id": chatID,
"message_ids": messageIDs,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messages Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SendChatSetTTLMessage Changes the current TTL setting (sets a new self-destruct timer) in a secret chat and sends the corresponding message
// @param chatID Chat identifier
// @param tTL New TTL value, in seconds
func (client *Client) SendChatSetTTLMessage(chatID int64, tTL int32) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendChatSetTtlMessage",
"chat_id": chatID,
"ttl": tTL,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var message Message
err = json.Unmarshal(result.Raw, &message)
return &message, err
}
// SendChatScreenshotTakenNotification Sends a notification about a screenshot taken in a chat. Supported only in private and secret chats
// @param chatID Chat identifier
func (client *Client) SendChatScreenshotTakenNotification(chatID int64) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendChatScreenshotTakenNotification",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// AddLocalMessage Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message
// @param chatID Target chat
// @param sender The sender sender of the message
// @param replyToMessageID Identifier of the message to reply to or 0
// @param disableNotification Pass true to disable notification for the message
// @param inputMessageContent The content of the message to be added
func (client *Client) AddLocalMessage(chatID int64, sender MessageSender, replyToMessageID int64, disableNotification bool, inputMessageContent InputMessageContent) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "addLocalMessage",
"chat_id": chatID,
"sender": sender,
"reply_to_message_id": replyToMessageID,
"disable_notification": disableNotification,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// DeleteMessages Deletes messages
// @param chatID Chat identifier
// @param messageIDs Identifiers of the messages to be deleted
// @param revoke Pass true to try to delete messages for all chat members. Always true for supergroups, channels and secret chats
func (client *Client) DeleteMessages(chatID int64, messageIDs []int64, revoke bool) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "deleteMessages",
"chat_id": chatID,
"message_ids": messageIDs,
"revoke": revoke,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var okDummy Ok
err = json.Unmarshal(result.Raw, &okDummy)
return &okDummy, err
}
// DeleteChatMessagesFromUser Deletes all messages sent by the specified user to a chat. Supported only for supergroups; requires can_delete_messages administrator privileges
// @param chatID Chat identifier
// @param userID User identifier
func (client *Client) DeleteChatMessagesFromUser(chatID int64, userID int32) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "deleteChatMessagesFromUser",
"chat_id": chatID,
"user_id": userID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditMessageText Edits the text of a message (or a text of a game message). Returns the edited message after the edit is completed on the server side
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param replyMarkup The new message reply markup; for bots only
// @param inputMessageContent New text content of the message. Should be of type InputMessageText
func (client *Client) EditMessageText(chatID int64, messageID int64, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageText",
"chat_id": chatID,
"message_id": messageID,
"reply_markup": replyMarkup,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// EditMessageLiveLocation Edits the message content of a live location. Messages can be edited for a limited period of time specified in the live location. Returns the edited message after the edit is completed on the server side
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param replyMarkup The new message reply markup; for bots only
// @param location New location content of the message; may be null. Pass null to stop sharing the live location
// @param heading The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown
// @param proximityAlertRadius The new maximum distance for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled
func (client *Client) EditMessageLiveLocation(chatID int64, messageID int64, replyMarkup ReplyMarkup, location *Location, heading int32, proximityAlertRadius int32) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageLiveLocation",
"chat_id": chatID,
"message_id": messageID,
"reply_markup": replyMarkup,
"location": location,
"heading": heading,
"proximity_alert_radius": proximityAlertRadius,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// EditMessageMedia Edits the content of a message with an animation, an audio, a document, a photo or a video. The media in the message can't be replaced if the message was set to self-destruct. Media can't be replaced by self-destructing media. Media in an album can be edited only to contain a photo or a video. Returns the edited message after the edit is completed on the server side
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param replyMarkup The new message reply markup; for bots only
// @param inputMessageContent New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo
func (client *Client) EditMessageMedia(chatID int64, messageID int64, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageMedia",
"chat_id": chatID,
"message_id": messageID,
"reply_markup": replyMarkup,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// EditMessageCaption Edits the message content caption. Returns the edited message after the edit is completed on the server side
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param replyMarkup The new message reply markup; for bots only
// @param caption New message content caption; 0-GetOption("message_caption_length_max") characters
func (client *Client) EditMessageCaption(chatID int64, messageID int64, replyMarkup ReplyMarkup, caption *FormattedText) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageCaption",
"chat_id": chatID,
"message_id": messageID,
"reply_markup": replyMarkup,
"caption": caption,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// EditMessageReplyMarkup Edits the message reply markup; for bots only. Returns the edited message after the edit is completed on the server side
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param replyMarkup The new message reply markup
func (client *Client) EditMessageReplyMarkup(chatID int64, messageID int64, replyMarkup ReplyMarkup) (*Message, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageReplyMarkup",
"chat_id": chatID,
"message_id": messageID,
"reply_markup": replyMarkup,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var messageDummy Message
err = json.Unmarshal(result.Raw, &messageDummy)
return &messageDummy, err
}
// EditInlineMessageText Edits the text of an inline text or game message sent via a bot; for bots only
// @param inlineMessageID Inline message identifier
// @param replyMarkup The new message reply markup
// @param inputMessageContent New text content of the message. Should be of type InputMessageText
func (client *Client) EditInlineMessageText(inlineMessageID string, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editInlineMessageText",
"inline_message_id": inlineMessageID,
"reply_markup": replyMarkup,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditInlineMessageLiveLocation Edits the content of a live location in an inline message sent via a bot; for bots only
// @param inlineMessageID Inline message identifier
// @param replyMarkup The new message reply markup
// @param location New location content of the message; may be null. Pass null to stop sharing the live location
// @param heading The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown
// @param proximityAlertRadius The new maximum distance for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled
func (client *Client) EditInlineMessageLiveLocation(inlineMessageID string, replyMarkup ReplyMarkup, location *Location, heading int32, proximityAlertRadius int32) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editInlineMessageLiveLocation",
"inline_message_id": inlineMessageID,
"reply_markup": replyMarkup,
"location": location,
"heading": heading,
"proximity_alert_radius": proximityAlertRadius,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditInlineMessageMedia Edits the content of a message with an animation, an audio, a document, a photo or a video in an inline message sent via a bot; for bots only
// @param inlineMessageID Inline message identifier
// @param replyMarkup The new message reply markup; for bots only
// @param inputMessageContent New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo
func (client *Client) EditInlineMessageMedia(inlineMessageID string, replyMarkup ReplyMarkup, inputMessageContent InputMessageContent) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editInlineMessageMedia",
"inline_message_id": inlineMessageID,
"reply_markup": replyMarkup,
"input_message_content": inputMessageContent,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditInlineMessageCaption Edits the caption of an inline message sent via a bot; for bots only
// @param inlineMessageID Inline message identifier
// @param replyMarkup The new message reply markup
// @param caption New message content caption; 0-GetOption("message_caption_length_max") characters
func (client *Client) EditInlineMessageCaption(inlineMessageID string, replyMarkup ReplyMarkup, caption *FormattedText) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editInlineMessageCaption",
"inline_message_id": inlineMessageID,
"reply_markup": replyMarkup,
"caption": caption,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditInlineMessageReplyMarkup Edits the reply markup of an inline message sent via a bot; for bots only
// @param inlineMessageID Inline message identifier
// @param replyMarkup The new message reply markup
func (client *Client) EditInlineMessageReplyMarkup(inlineMessageID string, replyMarkup ReplyMarkup) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editInlineMessageReplyMarkup",
"inline_message_id": inlineMessageID,
"reply_markup": replyMarkup,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// EditMessageSchedulingState 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
// @param chatID The chat the message belongs to
// @param messageID Identifier of the message
// @param schedulingState The new message scheduling state. Pass null to send the message immediately
func (client *Client) EditMessageSchedulingState(chatID int64, messageID int64, schedulingState MessageSchedulingState) (*Ok, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "editMessageSchedulingState",
"chat_id": chatID,
"message_id": messageID,
"scheduling_state": schedulingState,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var ok Ok
err = json.Unmarshal(result.Raw, &ok)
return &ok, err
}
// GetTextEntities Returns all entities (mentions, hashtags, cashtags, bot commands, bank card numbers, URLs, and email addresses) contained in the text. Can be called synchronously
// @param text The text in which to look for entites
func (client *Client) GetTextEntities(text string) (*TextEntities, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getTextEntities",
"text": text,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var textEntities TextEntities
err = json.Unmarshal(result.Raw, &textEntities)
return &textEntities, err
}
// ParseTextEntities Parses Bold, Italic, Underline, Strikethrough, Code, Pre, PreCode, TextUrl and MentionName entities contained in the text. Can be called synchronously
// @param text The text to parse
// @param parseMode Text parse mode
func (client *Client) ParseTextEntities(text string, parseMode TextParseMode) (*FormattedText, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "parseTextEntities",
"text": text,
"parse_mode": parseMode,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var formattedText FormattedText
err = json.Unmarshal(result.Raw, &formattedText)
return &formattedText, err
}
// ParseMarkdown Parses Markdown entities in a human-friendly format, ignoring markup errors. Can be called synchronously
// @param text The text to parse. For example, "__italic__ ~~strikethrough~~ **bold** `code` ```pre``` __[italic__ text_url](telegram.org) __italic**bold italic__bold**"
func (client *Client) ParseMarkdown(text *FormattedText) (*FormattedText, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "parseMarkdown",
"text": text,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %d msg: %s", result.Data["code"], result.Data["message"])
}
var formattedText FormattedText
err = json.Unmarshal(result.Raw, &formattedText)
return &formattedText, err