Skip to content

Commit

Permalink
bot: add verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
danch committed May 31, 2020
1 parent c8978c4 commit 092eb11
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +66,7 @@ type Bot struct {

handlers map[string]interface{}
synchronous bool
verbose bool
reporter func(error)
stop chan struct{}
client *http.Client
Expand All @@ -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)
Expand Down Expand Up @@ -291,6 +297,7 @@ func (b *Bot) ProcessUpdate(upd Update) {

return
}

}

if upd.EditedMessage != nil {
Expand Down Expand Up @@ -435,6 +442,7 @@ func (b *Bot) ProcessUpdate(upd Update) {

return
}

}

func (b *Bot) handle(end string, m *Message) bool {
Expand Down

0 comments on commit 092eb11

Please sign in to comment.