Documentation
¶
Index ¶
- func CORSMiddleware(next http.Handler) http.Handler
- func InitPostgres(ctx context.Context, o DbOptions) (db *sql.DB, err error)
- type Admin
- type AuthMail
- type BaseBot
- type Bot
- type BotOptions
- type BotType
- type Client
- type Connector
- type CustomJWTClaims
- type DbOptions
- type DbType
- type Hub
- type Mailer
- type Message
- type MockBot
- type Options
- type Server
- func (s *Server) Add(b Bot)
- func (s *Server) InitRoutes(router chi.Router, static string)
- func (s *Server) ListenAndServe()
- func (s *Server) RenderTemplate(next http.Handler) http.Handler
- func (s *Server) RunBots()
- func (s *Server) ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)
- func (s *Server) Shutdown()
- func (s *Server) StopBots()
- type TgBot
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
CORSMidlleware writer cors headers to requests
Types ¶
type Admin ¶
type Admin struct { Email string `json:"email" db:"email"` Name string `json:"name" db:"name"` HashedPassword string `json:"hashed_password" db:"hashed_password"` IsSuperUser bool `json:"is_superuser" db:"is_superuser"` IsActive bool `json:"is_active" db:"is_active"` EmailConfirmed bool `json:"email_confirmed" db:"email_confirmed"` AuthToken string `json:"auth_token" db:"auth_token"` PasswordResetToken string `json:"password_reset_token" db:"password_reset_token"` // contains filtered or unexported fields }
Admin represents registered dashboard Helpdesker
type BaseBot ¶
type BaseBot struct { // below is duplicating of Connector channels, but since real bots // inherit base bot and used as interfaces, whose channes needs to be wrapped // in separate struct for further usage Input chan []byte // messages from Customers Output chan Message // messages to Customers Error chan error // Errors for admins // contains filtered or unexported fields }
BaseBot is abstraction for useful business logic methods, such as authorization sequence etc. Every bot is basicly a REPL, with one difference: sometime your command result is given by helpdesker, and sometimes it's fully automatic. That single fact explains api design and provides ease of testing. Use it as embedded struct for various helpers and avoiding duplicating code. See MockBot implementation below
type BotOptions ¶
type BotOptions struct { T BotType Token string EmailAuth bool AllowedDomains []string Name string }
BotOptions is type/token pair which is needed for bot to start working
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub.
type CustomJWTClaims ¶
type CustomJWTClaims struct { CurrentBot string `json:"bot"` jwt.StandardClaims }
type Message ¶
type Message struct { FromAdmin bool `json:"from_bot"` IsBroadcast bool `json:"is_broadcast"` // I'm not sure what message id's are unique Text string `json:"text"` MessageID int `json:"message_id"` UserID int `json:"user_id"` ChatID int64 `json:"chat_id"` Date int `json:"send_date"` ForwardFrom int `json:"forward_from"` ForwardDate int `json:"forward_date"` ReplyToMessage int `json:"reply_to_message_id"` EditDate int `json:"edit_date"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` // those are just file ids for FileProxy, currently only Photo and Document // are supported DocumentID string `json:"file_id"` PhotoID string `json:"photo_id"` // contains filtered or unexported fields }
Message is atomic piece of communication between User and Admin
type MockBot ¶
type MockBot struct {
*BaseBot
}
MockBot takes reader/writer (ex. goes os.Stdin and os.Stdout) and simulates bot behavior and logic.
func NewMockBot ¶
NewMockBot initializes bot for development/testing purposes
type Options ¶
type Options struct { Root string Domain string Port string EmailServer string EmailAddress string EmailPassword string DatabaseURL string ServeStatic bool StaticFiles string DbOptions DbOptions Secret string TgBotTokens string }
Options represents server initialization options
type Server ¶
type Server struct { QuitCh chan struct{} Ctx context.Context Cancel func() Secret string DB *sql.DB // contains filtered or unexported fields }
Server contains gosupport server state
func InitServer ¶
func InitServer( l kitlog.Logger, t *templator.Templator, m Mailer, db *sql.DB, o Options, ) *Server
InitServer initialize new server instance with provided options & logger
func (*Server) InitRoutes ¶
InitRoutes initializes url schema. Separate function argument for routes is used to escape bugs there server tries to init routes without provided chi.Mux
type TgBot ¶
type TgBot struct { *BaseBot // contains filtered or unexported fields }
TgBot represents bot in telegram messanger
type User ¶
type User struct { UserID int `json:"userid"` ChatID int64 `json:"chatid"` Email string `json:"email"` Name string `json:"name"` Username string `json:"username"` HasUnreadMessages bool `json:"has_unread_messages"` // AuthToken used for email authorization AuthToken []byte `json:"authtoken"` IsAuthorized bool `json:"isauthorized"` IsTokenExpired bool `json:"is_token_expired"` LastMessageAt int64 `json:"lastMessageAt"` // FIXME LastMessage Message `json:"last_message"` UserPhotoID string `json:"user_photo_id"` IsActive bool `json:"is_active"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
User represents single chat endpoint of communication