Skip to content

sirlori/tgbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tgbot

GoDoc

A Golang Telegram bot framework

Expect many breaking changes. Open an issue if you have any feature requests.

If you want just API bindings, check out telegram-bot-api.

###Examples

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	log.SetOutput(os.Stdout)

	// Create a new bot
	bot, err := tgbot.NewBot(TOKEN)
	if err != nil {
		log.Panic(err)
	}
	log.Printf("Authorized on account %s", bot.API.Self.UserName)

	// Add commands to your plugin
	plugin := tgbot.NewPlugin("BOT")
	// Aommand setup in your plugin	
	plugin.AddSetup(InitHelp)
	plugin.AddSetup(InitEcho)
	
	// Add plugin to the bot:
	// In future this will be handled by our package
	// so it will be possible to add plugins from command-line
	// from our repo.
	bot.AddPlugin(plugin)
	
	// A function that runs fore every update without conditions
	bot.BeforeCommands = SomeStuff
	// Start to recieve commands
	bot.Start()
}

This is the init function for the echo command:

func InitEcho(plugincommands *tgbot.MultipleParser) error {

	parser := tgbot.NewParser()
	parser.Cmd = "^/echo"
	parser.Profile = []tgbot.Argouments{
		tgbot.NewArgs("printer", []string{"string"}),
	}

	parser.Tasks["printer"] = func(cmd *tgbot.Command, up *tgbotapi.Update,
		bot *tgbotapi.BotAPI) {
		msg := tgbotapi.NewMessage(up.Message.Chat.ID, cmd.Args["string"])
		bot.SendMessage(msg)
	}
	plugincommands.Add(parser)
	return nil
}

The docs are still poor, but try to read them to understand more!

About

A Golang Telegram bot framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages