configs

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBotAPI = "https://api.telegram.org/bot"

DefaultBotAPI is the telegrams default bot api server.

View Source
const DefaultLogFile = "STDOUT"

DefaultLogFile is a default file for saving the bot logs in it.

Variables

This section is empty.

Functions

func Dump

func Dump(bc *BotConfigs) error

Dump saves the given BotConfigs struct in a json format in the config file (configs.json).

func LoadInto

func LoadInto(bc *BotConfigs) error

LoadInto works the same way as "Load" but it won't return the config, instead it loads the config into the given object.

Types

type BlockedUser

type BlockedUser struct {
	UserID   int    `json:"user_id"`
	UserName string `json:"username"`
}

BlockedUser is a struct used for storing a blocked user informations.

type BotConfigs

type BotConfigs struct {
	/*This is the bot api server. If you dont have a local bot api server, use "configs.DefaultBotAPI" for this field.*/
	BotAPI string `json:"bot_api"`
	/*The API key for your bot. You can get the api key (token) from botfather*/
	APIKey string `json:"api_key"`
	/*The settings related to getting updates from the api server. This field shoud only be populated when Webhook field is false, otherwise it is ignored.*/
	UpdateConfigs *UpdateConfigs `json:"update_configs,omitempty"`
	/*This field idicates if webhook should be used for receiving updates or not.
	Recommend : false*/
	Webhook bool `json:"webhook"`
	/*This field represents the configs related to web hook.*/
	WebHookConfigs *WebHookConfigs `json:"webhook_configs,omitempty"`
	/*All the logs related to bot will be written in this file. You can use configs.DefaultLogFile for default value*/
	LogFileAddress string `json:"log_file"`
	//BlockedUsers is a list of blocked users.
	BlockedUsers []BlockedUser `json:"blocked_users"`
}

BotConfigs is a struct holding the bots configs.

func Default

func Default(apiKey string) *BotConfigs

Default returns default setting for the bot.

func Load

func Load() (*BotConfigs, error)

Load loads the configs from the config file (configs.json) and returns the BotConfigs pointer.

func (*BotConfigs) Check

func (bc *BotConfigs) Check() bool

Check checks the bot configs for any problem.

func (*BotConfigs) StartCfgUpdateRoutine

func (bc *BotConfigs) StartCfgUpdateRoutine()

StartCfgUpdateRoutine starts a routine which updates the configs every second.

type UpdateConfigs

type UpdateConfigs struct {
	/*Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.*/
	Limit int `json:"limit"`
	/*Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.*/
	Timeout int `json:"timeout"`
	/*List of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
	Please note that this parameter doesnt affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.*/
	AllowedUpdates []string `json:"allowed_updates,omitempty"`
	/*This field indicates the frequency to call getUpdates method. Default is one second*/
	UpdateFrequency time.Duration `json:"update_freq"`
}

UpdateConfigs contains the necessary configs for receiving updates.

func DefaultUpdateConfigs

func DefaultUpdateConfigs() *UpdateConfigs

DefaultUpdateConfigs returns a default update configs.

type WebHookConfigs

type WebHookConfigs struct {
	/*The web hook url.*/
	URL string `json:"url"`
	/*The port that webhook server will run on. Telegram api only suppotrs 80,443,88,8443. 8443 is recommended. Pass 0 for default https port (443)*/
	Port int `json:"port"`
	/*The address of the public key certificate file.*/
	KeyFile string `json:"keyfile"`
	/*The address of the certificate file.*/
	CertFile string `json:"certfile"`
	/*The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS*/
	IP string `json:"ip,omitempty"`
	/*Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.*/
	MaxConnections int `json:"max_connections"`
	/*List of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
	Please note that this parameter doesnt affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.*/
	AllowedUpdates []string `json:"allowed_updates,omitempty"`
	/*Pass True to drop all pending updates*/
	DropPendingUpdates bool `json:"drop_pending_reqs"`
}

WebHookConfigs contains the configs necessary for webhook.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL