Custom API server
This commit is contained in:
parent
3a06ae5f0e
commit
677f28182a
|
@ -8,7 +8,8 @@ import (
|
|||
|
||||
type Nechotron struct {
|
||||
Token string
|
||||
DefaultState *State
|
||||
DefaultState Runnable
|
||||
ApiServer string
|
||||
}
|
||||
|
||||
func NewTron(token string, defaultState *State) *Nechotron {
|
||||
|
@ -23,7 +24,8 @@ func NewTron(token string, defaultState *State) *Nechotron {
|
|||
}
|
||||
|
||||
func (n *Nechotron) newBot(chatID int64) echo.Bot {
|
||||
a := echo.NewAPI(n.Token)
|
||||
a := echo.NewCustomAPI(n.Token, n.ApiServer)
|
||||
// a := echo.NewAPI(n.Token)
|
||||
me, _ := a.GetMe()
|
||||
// log.Println("New bot active: ", chatID, me.Result)
|
||||
b := &bot{
|
||||
|
|
6
state.go
6
state.go
|
@ -13,11 +13,11 @@ type Runnable interface {
|
|||
}
|
||||
|
||||
type State struct {
|
||||
fn stateFn
|
||||
Fn stateFn
|
||||
}
|
||||
|
||||
func (s *State) Call(u *Update) (Runnable, error) {
|
||||
return s.fn(u)
|
||||
return s.Fn(u)
|
||||
}
|
||||
|
||||
type stateFn func(*Update) (Runnable, error)
|
||||
|
@ -46,7 +46,7 @@ func (d StateData) Clear() {
|
|||
}
|
||||
|
||||
var EchoState = State{
|
||||
fn: EchoFunc,
|
||||
Fn: EchoFunc,
|
||||
}
|
||||
|
||||
func EchoFunc(u *Update) (Runnable, error) {
|
||||
|
|
|
@ -188,7 +188,7 @@ func (u *Update) LogError(text string, e error, send bool) {
|
|||
} else {
|
||||
text = "Произошла внутренняя ошибка"
|
||||
}
|
||||
log.Printf("[%s] %s: %v", u.UpdateID.String(), text, e)
|
||||
log.Printf("ERROR :: [%s] :: %s: %v", u.UpdateID.String(), text, e)
|
||||
if send {
|
||||
u.AnswerMarkdown(fmt.Sprintf("%s\nКод запроса: `%s`", text, u.UpdateID.String()))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue