Giter Club home page Giter Club logo

skeleton's Introduction

Skeleton ☠️

Skeleton is a telegram bot framework based by github.com/go-telegram-bot-api/telegram-bot-api You can use all methods github.com/go-telegram-bot-api/telegram-bot-api library.

Examples

Simple app:

	func main() {
		// create app
		app := skeleton.NewBot("TELERAM-TOKEN-BOT", )
		
		// create new handler
		// seach commad /start
		// work only private
		app.HandleFunc("^/start$", func (c *skeleton.Context) bool {

		c.BotAPI.Send(tgbotapi.NewMessage(c.ChatId(),
		"Hello, " + c.Update.Message.Chat.FirstName))

		c.Pipeline().Next()

		return true
		
		}).Border(sk.Private).Methods(sk.Commands)

        // start app
		app.Run()
	}

Pipeline app:

    func main() {
    
    	// create app
    	app := skeleton.NewBot("TELERAM-TOKEN-BOT")
    
    	// create pipeline
    	// enter point command start
    	// work only bot
    	//
    	// Append() add next
    	pl := app.HandleFunc("/start", func(c *skeleton.Context) bool {
    		c.BotAPI.Send(tgbotapi.NewMessage(c.ChatId(),
    			"Hello, "+c.Update.Message.Chat.FirstName+" how old are you?"))
    
    		// set next command
    		c.Pipeline().Next()
    
    		return true
    	}).Border(skeleton.Private).Methods(skeleton.Commands).Append()
    
    	// add next command
    	// set timeout 20 second
    	pl = pl.Func(func(c *skeleton.Context) bool {
    		c.BotAPI.Send(tgbotapi.NewMessage(c.ChatId(),
    			"Ok! You "+c.Update.Message.Text+" old! Where you were born?"))
    
    		// set next command
    		c.Pipeline().Next()
    
    		return true
    	}).Timeout(time.Second * 20).Append()
    
    	// add next command
    	// set timeout 20 second
    	pl = pl.Func(func(c *skeleton.Context) bool {
    		c.BotAPI.Send(tgbotapi.NewMessage(c.ChatId(),
    			"Ok! You born "+c.Update.Message.Text+"! Nice to meet you"))
    
    		// stop pipeline
    		c.Pipeline().Stop()
    
    		return true
    	}).Timeout(time.Second * 20)
    
    	app.Run()
    }

Keyboard app:

	func main() {

        // create app
		app := skeleton.NewBot(
			"TELERAM-TOKEN-BOT"")

        // create new handler
        // seach commad /start
        // work only private
		app.HandleFunc("^/start$", func(c *skeleton.Context) bool {
            
            // create new text message
			msg := tgbotapi.NewMessage(c.ChatId(),
				"Hello, "+c.Update.Message.Chat.FirstName+", tap to button")

            // create new inline keyboard generator
			k := skeleton.NewInlineKeyboard(1, 3)
			// add buttons
			k.Buttons.Add("1", "is-1")
			k.Buttons.Add("2", "is-2")
			k.Buttons.Add("3", "is-3")
			k.Buttons.Add("4", "is-4")
			k.Buttons.Add("5", "is-5")
			k.Buttons.Add("6", "is-6")
			k.Buttons.Add("7", "is-7")
			// add control buttons
			k.ControlButtons.AddPagesControl()

            // generate keyboard and add in message markup
			msg.ReplyMarkup = k.Generate().InlineKeyboardMarkup()

            // if message send dont have errors - save keyboard state
			if m, err := c.BotAPI.Send(msg); err == nil {
				c.Keyboards().SaveState(&m, k)
			}

			return true
		}).Border(skeleton.Private).Methods(skeleton.Commands)

        // add new handler callback from inline keyboard
		app.HandleFunc(`is-(\d{1,})`, func(c *skeleton.Context) bool {

            // RegexpResult using FindStringSubmatch()
		    // more in processor.go func (a *app) processor(update *tgbotapi.Update) {]
			c.BotAPI.AnswerCallbackQuery(tgbotapi.NewCallbackWithAlert(
				c.Update.CallbackQuery.ID,
				"Is "+c.RegexpResult[1]+" number!"))

			return true
		}).Border(skeleton.Private).Methods(skeleton.Callbacks)

        // start app
		app.Run()
	}

skeleton's People

Contributors

vbchekhov avatar

Watchers

 avatar

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.