A number of small improvements.
parent
5f38203a15
commit
b6441c36ee
11
README.md
11
README.md
|
@ -51,7 +51,7 @@ func main() {
|
||||||
updates, err := bot.GetUpdatesChan(u)
|
updates, err := bot.GetUpdatesChan(u)
|
||||||
|
|
||||||
for update := range updates {
|
for update := range updates {
|
||||||
if update.Message == nil {
|
if update.Message == nil { // ignore any non-Message Updates
|
||||||
continue
|
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),
|
If you need to use webhooks (if you wish to run on Google App Engine),
|
||||||
you may use a slightly different method.
|
you may use a slightly different method.
|
||||||
|
|
||||||
|
@ -96,7 +101,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if info.LastErrorDate != 0 {
|
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)
|
updates := bot.ListenForWebhook("/" + bot.Token)
|
||||||
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
|
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
|
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.
|
you may wish to generate your free TLS certificate there.
|
||||||
|
|
|
@ -473,13 +473,10 @@ func TestSetWebhookWithCert(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
info, err := bot.GetWebhookInfo()
|
_, err = bot.GetWebhookInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if info.LastErrorDate != 0 {
|
|
||||||
t.Errorf("[Telegram callback failed]%s", info.LastErrorMessage)
|
|
||||||
}
|
|
||||||
bot.RemoveWebhook()
|
bot.RemoveWebhook()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
log.go
17
log.go
|
@ -6,13 +6,22 @@ import (
|
||||||
"os"
|
"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.
|
// SetLogger specifies the logger that the package should use.
|
||||||
func SetLogger(newLog *stdlog.Logger) error {
|
func SetLogger(logger BotLogger) error {
|
||||||
if newLog == nil {
|
if logger == nil {
|
||||||
return errors.New("logger is nil")
|
return errors.New("logger is nil")
|
||||||
}
|
}
|
||||||
log = newLog
|
log = logger
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
16
passport.go
16
passport.go
|
@ -8,21 +8,28 @@ type PassportRequestInfoConfig struct {
|
||||||
PublicKey string `json:"public_key"`
|
PublicKey string `json:"public_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PassportScopeElement supports using one or one of several elements.
|
||||||
type PassportScopeElement interface {
|
type PassportScopeElement interface {
|
||||||
ScopeType() string
|
ScopeType() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PassportScope is the requested scopes of data.
|
||||||
type PassportScope struct {
|
type PassportScope struct {
|
||||||
V int `json:"v"`
|
V int `json:"v"`
|
||||||
Data []PassportScopeElement `json:"data"`
|
Data []PassportScopeElement `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PassportScopeElementOneOfSeveral allows you to request any one of the
|
||||||
|
// requested documents.
|
||||||
type PassportScopeElementOneOfSeveral struct {
|
type PassportScopeElementOneOfSeveral struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScopeType is the scope type.
|
||||||
func (eo *PassportScopeElementOneOfSeveral) ScopeType() string {
|
func (eo *PassportScopeElementOneOfSeveral) ScopeType() string {
|
||||||
return "one_of"
|
return "one_of"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PassportScopeElementOne requires the specified element be provided.
|
||||||
type PassportScopeElementOne struct {
|
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”
|
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"`
|
Selfie bool `json:"selfie"`
|
||||||
|
@ -30,6 +37,7 @@ type PassportScopeElementOne struct {
|
||||||
NativeNames bool `json:"native_name"`
|
NativeNames bool `json:"native_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScopeType is the scope type.
|
||||||
func (eo *PassportScopeElementOne) ScopeType() string {
|
func (eo *PassportScopeElementOne) ScopeType() string {
|
||||||
return "one"
|
return "one"
|
||||||
}
|
}
|
||||||
|
@ -146,6 +154,7 @@ type (
|
||||||
// Error message
|
// Error message
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PassportElementErrorFrontSide represents an issue with the front side of
|
// PassportElementErrorFrontSide represents an issue with the front side of
|
||||||
// a document. The error is considered resolved when the file with the front
|
// a document. The error is considered resolved when the file with the front
|
||||||
// side of the document changes.
|
// side of the document changes.
|
||||||
|
@ -237,12 +246,14 @@ type (
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Credentials contains encrypted data.
|
||||||
Credentials struct {
|
Credentials struct {
|
||||||
Data SecureData `json:"secure_data"`
|
Data SecureData `json:"secure_data"`
|
||||||
// Nonce the same nonce given in the request
|
// Nonce the same nonce given in the request
|
||||||
Nonce string `json:"nonce"`
|
Nonce string `json:"nonce"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SecureData is a map of the fields and their encrypted values.
|
||||||
SecureData map[string]*SecureValue
|
SecureData map[string]*SecureValue
|
||||||
// PersonalDetails *SecureValue `json:"personal_details"`
|
// PersonalDetails *SecureValue `json:"personal_details"`
|
||||||
// Passport *SecureValue `json:"passport"`
|
// Passport *SecureValue `json:"passport"`
|
||||||
|
@ -256,6 +267,7 @@ type (
|
||||||
// PassportRegistration *SecureValue `json:"passport_registration"`
|
// PassportRegistration *SecureValue `json:"passport_registration"`
|
||||||
// TemporaryRegistration *SecureValue `json:"temporary_registration"`
|
// TemporaryRegistration *SecureValue `json:"temporary_registration"`
|
||||||
|
|
||||||
|
// SecureValue contains encrypted values for a SecureData item.
|
||||||
SecureValue struct {
|
SecureValue struct {
|
||||||
Data *DataCredentials `json:"data"`
|
Data *DataCredentials `json:"data"`
|
||||||
FrontSide *FileCredentials `json:"front_side"`
|
FrontSide *FileCredentials `json:"front_side"`
|
||||||
|
@ -264,6 +276,8 @@ type (
|
||||||
Translation []*FileCredentials `json:"translation"`
|
Translation []*FileCredentials `json:"translation"`
|
||||||
Files []*FileCredentials `json:"files"`
|
Files []*FileCredentials `json:"files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DataCredentials contains information required to decrypt data.
|
||||||
DataCredentials struct {
|
DataCredentials struct {
|
||||||
// DataHash checksum of encrypted data
|
// DataHash checksum of encrypted data
|
||||||
DataHash string `json:"data_hash"`
|
DataHash string `json:"data_hash"`
|
||||||
|
@ -271,12 +285,14 @@ type (
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FileCredentials contains information required to decrypt files.
|
||||||
FileCredentials struct {
|
FileCredentials struct {
|
||||||
// FileHash checksum of encrypted data
|
// FileHash checksum of encrypted data
|
||||||
FileHash string `json:"file_hash"`
|
FileHash string `json:"file_hash"`
|
||||||
// Secret of encrypted data
|
// Secret of encrypted data
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PersonalDetails https://core.telegram.org/passport#personaldetails
|
// PersonalDetails https://core.telegram.org/passport#personaldetails
|
||||||
PersonalDetails struct {
|
PersonalDetails struct {
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
|
|
Loading…
Reference in New Issue