all repos — telegram-bot-api @ b6441c36ee8feca2d3ddd509fe2e339b0b21df1b

Golang bindings for the Telegram Bot API

A number of small improvements.
Syfaro syfaro@huefox.com
Mon, 08 Oct 2018 02:25:09 -0500
commit

b6441c36ee8feca2d3ddd509fe2e339b0b21df1b

parent

5f38203a155afa901c7deb70596a088a8424a9ee

4 files changed, 38 insertions(+), 11 deletions(-)

jump to
M README.mdREADME.md

@@ -51,7 +51,7 @@

updates, err := bot.GetUpdatesChan(u) for update := range updates { - if update.Message == nil { + if update.Message == nil { // ignore any non-Message Updates continue }

@@ -65,6 +65,11 @@ }

} ``` +There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki) +with detailed information on how to do many differen kinds of things. +It's a great place to get started on using keyboards, commands, or other +kinds of reply markup. + If you need to use webhooks (if you wish to run on Google App Engine), you may use a slightly different method.

@@ -96,7 +101,7 @@ if err != nil {

log.Fatal(err) } if info.LastErrorDate != 0 { - log.Printf("[Telegram callback failed]%s", info.LastErrorMessage) + log.Printf("Telegram callback failed: %s", info.LastErrorMessage) } updates := bot.ListenForWebhook("/" + bot.Token) go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)

@@ -114,5 +119,5 @@ properly signed.

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes -Now that [Let's Encrypt](https://letsencrypt.org) has entered public beta, +Now that [Let's Encrypt](https://letsencrypt.org) is available, you may wish to generate your free TLS certificate there.
M bot_test.gobot_test.go

@@ -473,12 +473,9 @@ if err != nil {

t.Error(err) t.Fail() } - info, err := bot.GetWebhookInfo() + _, err = bot.GetWebhookInfo() if err != nil { t.Error(err) - } - if info.LastErrorDate != 0 { - t.Errorf("[Telegram callback failed]%s", info.LastErrorMessage) } bot.RemoveWebhook() }
M log.golog.go

@@ -6,13 +6,22 @@ stdlog "log"

"os" ) -var log = stdlog.New(os.Stderr, "", stdlog.LstdFlags) +// BotLogger is an interface that represents the required methods to log data. +// +// Instead of requiring the standard logger, we can just specify the methods we +// use and allow users to pass anything that implements these. +type BotLogger interface { + Println(v ...interface{}) + Printf(format string, v ...interface{}) +} + +var log BotLogger = stdlog.New(os.Stderr, "", stdlog.LstdFlags) // SetLogger specifies the logger that the package should use. -func SetLogger(newLog *stdlog.Logger) error { - if newLog == nil { +func SetLogger(logger BotLogger) error { + if logger == nil { return errors.New("logger is nil") } - log = newLog + log = logger return nil }
M passport.gopassport.go

@@ -8,21 +8,28 @@ Nonce string `json:"nonce"`

PublicKey string `json:"public_key"` } +// PassportScopeElement supports using one or one of several elements. type PassportScopeElement interface { ScopeType() string } + +// PassportScope is the requested scopes of data. type PassportScope struct { V int `json:"v"` Data []PassportScopeElement `json:"data"` } +// PassportScopeElementOneOfSeveral allows you to request any one of the +// requested documents. type PassportScopeElementOneOfSeveral struct { } +// ScopeType is the scope type. func (eo *PassportScopeElementOneOfSeveral) ScopeType() string { return "one_of" } +// PassportScopeElementOne requires the specified element be provided. type PassportScopeElementOne struct { Type string `json:"type"` // One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email” Selfie bool `json:"selfie"`

@@ -30,6 +37,7 @@ Translation bool `json:"translation"`

NativeNames bool `json:"native_name"` } +// ScopeType is the scope type. func (eo *PassportScopeElementOne) ScopeType() string { return "one" }

@@ -146,6 +154,7 @@

// Error message Message string `json:"message"` } + // PassportElementErrorFrontSide represents an issue with the front side of // a document. The error is considered resolved when the file with the front // side of the document changes.

@@ -237,12 +246,14 @@ // Error message

Message string `json:"message"` } + // Credentials contains encrypted data. Credentials struct { Data SecureData `json:"secure_data"` // Nonce the same nonce given in the request Nonce string `json:"nonce"` } + // SecureData is a map of the fields and their encrypted values. SecureData map[string]*SecureValue // PersonalDetails *SecureValue `json:"personal_details"` // Passport *SecureValue `json:"passport"`

@@ -256,6 +267,7 @@ // RentalAgreement *SecureValue `json:"rental_agreement"`

// PassportRegistration *SecureValue `json:"passport_registration"` // TemporaryRegistration *SecureValue `json:"temporary_registration"` + // SecureValue contains encrypted values for a SecureData item. SecureValue struct { Data *DataCredentials `json:"data"` FrontSide *FileCredentials `json:"front_side"`

@@ -264,6 +276,8 @@ Selfie *FileCredentials `json:"selfie"`

Translation []*FileCredentials `json:"translation"` Files []*FileCredentials `json:"files"` } + + // DataCredentials contains information required to decrypt data. DataCredentials struct { // DataHash checksum of encrypted data DataHash string `json:"data_hash"`

@@ -271,12 +285,14 @@ // Secret of encrypted data

Secret string `json:"secret"` } + // FileCredentials contains information required to decrypt files. FileCredentials struct { // FileHash checksum of encrypted data FileHash string `json:"file_hash"` // Secret of encrypted data Secret string `json:"secret"` } + // PersonalDetails https://core.telegram.org/passport#personaldetails PersonalDetails struct { FirstName string `json:"first_name"`