Install and quick start - SakoDroid/telego GitHub Wiki
Installation
Install the package into your $GOPATH with the go command from terminal :
$ go get -u github.com/SakoDroid/telego/[email protected]
Git needs to be installed on your computer.
⚠️ Deprecation notice ⚠️
All versions and releases before v2.0.0 (including v1.8.0) have been deprecated and are considered out of date. Please consider updating to v2 ASAP.
✅ Upgrading to v2
Telego v2 is a ground breaking change in Telego. Many new features have been added and many methods declarations have been changed. Some methods have been completely deprecated. Please read the change log before upgrading to v2 and take extra caution while upgrading.
Quick start
The following code creates a bot and starts receiving updates. If the update is a text message that contains "hi" the bot will respond "hi to you too!".
import (
"fmt"
bt "github.com/SakoDroid/telego"
cfg "github.com/SakoDroid/telego/configs"
objs "github.com/SakoDroid/telego/objects"
)
func main(){
bot, err := bt.NewBot(cfg.Default("your API key"))
if err == nil{
err == bot.Run(false)
if err == nil{
go start(bot)
}
}
}
func start(bot *bt.Bot){
//The general update channel.
updateChannel := bot.GetUpdateChannel()
//Adding a handler. Everytime the bot receives message "hi" in a private chat, it will respond "hi to you too".
bot.AddHandler("hi",func(u *objs.Update) {
_,err := bot.SendMessage(u.Message.Chat.Id,"hi to you too","",u.Message.MessageId,false,false)
if err != nil{
fmt.Println(err)
}
},"private")
//Monitores any other update. (Updates that don't contain text message "hi" in a private chat)
for {
update := <- updateChannel
//Some processing on the update
}
}