diff --git a/README.md b/README.md index d9a6873..5e29f88 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ func main() { 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 @@ func main() { } ``` +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 @@ func main() { 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. diff --git a/bot_test.go b/bot_test.go index e9cfc79..60f3e65 100644 --- a/bot_test.go +++ b/bot_test.go @@ -473,13 +473,10 @@ func TestSetWebhookWithCert(t *testing.T) { 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() } diff --git a/log.go b/log.go index 7a99bbd..1872551 100644 --- a/log.go +++ b/log.go @@ -6,13 +6,22 @@ import ( "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 } diff --git a/passport.go b/passport.go index 85cb990..5f55006 100644 --- a/passport.go +++ b/passport.go @@ -8,21 +8,28 @@ type PassportRequestInfoConfig struct { 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 @@ type PassportScopeElementOne struct { NativeNames bool `json:"native_name"` } +// ScopeType is the scope type. func (eo *PassportScopeElementOne) ScopeType() string { return "one" } @@ -146,6 +154,7 @@ type ( // 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 @@ type ( 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 @@ type ( // 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 @@ type ( 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 @@ type ( 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"`