Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 1.03 KB

README.md

File metadata and controls

58 lines (46 loc) · 1.03 KB

Pluggable Telegram bot written in Golang

Travis GoDoc

Plugin example

package main

import (
	"gopkg.in/devalecs/tgbot.v1"
	"gopkg.in/devalecs/tgo.v1"
)

type PingPlugin struct{}

func (p *PingPlugin) Reply(b tgbot.B, update *tgo.Update) {
	b.SendMessage(tgo.SendMessageParams{
		ChatID: update.Message.Chat.ID,
		Text:   "pong",
	})
}

func (p *PingPlugin) Match(b tgbot.B, update *tgo.Update) bool {
	return b.MessageTextMatch(update, "ping")
}

func (p *PingPlugin) Settings() tgbot.PluginSettings {
	return tgbot.PluginSettings{
		Help: "*/ping*: Sample ping pong plugin",
	}
}

Bot example

package main

import (
	"log"

	"gopkg.in/devalecs/tgbot.v1"
)

func main() {
	b := tgbot.NewBot(tgbot.Config{
		Token: "yourBotAPIToken",
	})

	b.RegisterPlugins(
		new(PingPlugin),
	)

	err := b.Start()
	if err != nil {
		log.Fatal(err)
	}
}