Skip to content

Commit

Permalink
Merge pull request tucnak#302 from faglo/verbose-mode
Browse files Browse the repository at this point in the history
Verbose mode
  • Loading branch information
demget authored Jun 9, 2020
2 parents 98a898f + 29af30f commit 86d8741
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, strings.Replace(url, b.Token, "<token>", -1), 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,
parseMode: pref.ParseMode,
stop: make(chan struct{}),
reporter: pref.Reporter,
Expand Down Expand Up @@ -66,6 +67,7 @@ type Bot struct {

handlers map[string]interface{}
synchronous bool
verbose bool
parseMode ParseMode
reporter func(error)
stop chan struct{}
Expand All @@ -91,6 +93,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

// ParseMode used to set default parse mode of all sent messages.
// It attaches to every send, edit or whatever method. You also
// will be able to override the default mode by passing a new one.
Expand Down Expand Up @@ -298,6 +304,7 @@ func (b *Bot) ProcessUpdate(upd Update) {

return
}

}

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

return
}

}

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

0 comments on commit 86d8741

Please sign in to comment.