package telegram
import (
"context"
"os"
"github.com/go-faster/errors"
)
func RunUntilCanceled (ctx context .Context , client *Client ) error {
<-ctx .Done ()
return ctx .Err ()
}
func BotFromEnvironment (
ctx context .Context ,
opts Options ,
setup func (ctx context .Context , client *Client ) error ,
cb func (ctx context .Context , client *Client ) error ,
) error {
client , err := ClientFromEnvironment (opts )
if err != nil {
return errors .Wrap (err , "create client" )
}
if setup != nil {
if err := setup (ctx , client ); err != nil {
return errors .Wrap (err , "setup" )
}
}
return client .Run (ctx , func (ctx context .Context ) error {
status , err := client .Auth ().Status (ctx )
if err != nil {
return errors .Wrap (err , "auth status" )
}
if !status .Authorized {
if _ , err := client .Auth ().Bot (ctx , os .Getenv ("BOT_TOKEN" )); err != nil {
return errors .Wrap (err , "login" )
}
}
return cb (ctx , client )
})
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .