bot: add verbose mode

pull/302/head
danch 4 years ago
parent c8978c4f37
commit 092eb11418

@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
"os"
@ -38,6 +39,14 @@ func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
return nil, wrapError(err)
}
if b.verbose {
log.Printf(`[verbose] telebot: sent request
Method: %v
URL: %v
Params: %v
Response: %v`, method, url, payload, string(data))
}
// returning data as well
return data, extractOk(data)
}

@ -37,6 +37,7 @@ func NewBot(pref Settings) (*Bot, error) {
handlers: make(map[string]interface{}),
synchronous: pref.Synchronous,
verbose: pref.Verbose,
stop: make(chan struct{}),
reporter: pref.Reporter,
client: client,
@ -65,6 +66,7 @@ type Bot struct {
handlers map[string]interface{}
synchronous bool
verbose bool
reporter func(error)
stop chan struct{}
client *http.Client
@ -89,6 +91,10 @@ type Settings struct {
// It makes ProcessUpdate return after the handler is finished.
Synchronous bool
// Verbose mode let you to debug the bot
// Shows upcoming requests
Verbose bool
// Reporter is a callback function that will get called
// on any panics recovered from endpoint handlers.
Reporter func(error)
@ -291,6 +297,7 @@ func (b *Bot) ProcessUpdate(upd Update) {
return
}
}
if upd.EditedMessage != nil {
@ -435,6 +442,7 @@ func (b *Bot) ProcessUpdate(upd Update) {
return
}
}
func (b *Bot) handle(end string, m *Message) bool {

Loading…
Cancel
Save