diff --git a/.gitignore b/.gitignore index 77f9775..5313070 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +*.sqlite3 + + + # If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # diff --git a/main.go b/main.go index 5479c97..8264dd8 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,9 @@ import ( "strconv" "github.com/celestix/gotgproto" + "github.com/celestix/gotgproto/dispatcher/handlers" + "github.com/celestix/gotgproto/dispatcher/handlers/filters" + "github.com/celestix/gotgproto/ext" "github.com/celestix/gotgproto/sessionMaker" "github.com/joho/godotenv" "gorm.io/driver/sqlite" @@ -45,7 +48,7 @@ func main() { gotgproto.ClientTypePhone(phoneNumber), // Optional parameters of client &gotgproto.ClientOpts{ - Session: sessionMaker.SqlSession(sqlite.Open("echobot")), + Session: sessionMaker.SqlSession(sqlite.Open("echobot.sqlite3")), }, ) if err != nil { @@ -54,5 +57,15 @@ func main() { fmt.Printf("client (@%s) has been started...\n", client.Self.Username) + clientDispatcher := client.Dispatcher + + clientDispatcher.AddHandlerToGroup(handlers.NewMessage(filters.Message.Text, echo), 1) + client.Idle() } + +func echo(ctx *ext.Context, update *ext.Update) error { + msg := update.EffectiveMessage + _, err := ctx.Reply(update, ext.ReplyTextString(msg.Text), nil) + return err +}