Git Product home page Git Product logo

fsm-telebot's Introduction

fsm-telebot

GitHub go.mod Go version Go Reference Go golangci-lint

Finite State Machine for telebot. Based on aiogram FSM version.

It not a full implementation FSM. It just states manager for telegram bots.

Install:

Last release version (manually):

go get -u github.com/vitaliy-ukiru/[email protected]

Last commit from master (unstable)

go get -u github.com/vitaliy-ukiru/fsm-telebot@master

Examples

simple configuration
package main

import (
	"os"
	"time"

	"github.com/vitaliy-ukiru/fsm-telebot"
	"github.com/vitaliy-ukiru/fsm-telebot/storages/memory"
	tele "gopkg.in/telebot.v3"
)

func main() {
	bot, err := tele.NewBot(tele.Settings{
		Token:  os.Getenv("BOT_TOKEN"),
		Poller: &tele.LongPoller{Timeout: 3 * time.Second},
	})
	if err != nil {
		panic(err)
	}

	// for example using memory storage
	// but prefer will use redis or file storage.
	storage := memory.NewStorage()
	manager := fsm.NewManager(
		bot,     // tele.Bot
		nil,     // handlers will setups to this group. Default: creates new
		storage, // storage for states and data
		nil,     // context maker. Default: NewFSMContext
	)
	manager.Bind("/state", fsm.AnyState, func(c tele.Context, state fsm.Context) error {
		userState, err := state.State()
		if err != nil {
			return c.Send("error: " + err.Error())
		}

		return c.Send(userState.GoString())
	})

}

Many complex examples in directory examples.

fsm-telebot's People

Contributors

nacknime-official avatar rusq avatar vitaliy-ukiru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fsm-telebot's Issues

Right middleware binding

Using some telebot groups with some fsm manager is a bad idea. Because managers will rewrites base group. Need create mechanism to saves middlewares to handlers, using groups for more handlers and save back compatibility.

Previous attempts had a problem. The one that copied the tele.Group behavior - it allowed to create subgroups,
but in the end all middlewares were still bound to one handler in telebot.

So there was a problem with them (all middlewares in 1 endpoint).
Now middlewares are saved for each fsm handler. All calls to Manager.handle will be served by separate middlewares.

See details in #16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.