diff --git a/gallery/go-telegram-bot-goland/README.md b/gallery/go-telegram-bot-goland/README.md new file mode 100644 index 0000000..efabf46 --- /dev/null +++ b/gallery/go-telegram-bot-goland/README.md @@ -0,0 +1,19 @@ +# go-telegram-bot-goland + +This is a basic Telegram bot built using github copilot. It uses [telebot module](https://github.com/tucnak/telebot). + +After you installed the Copilot plugin and enabled it, you can follow below steps to build your bot. + +Create a new project, e.g. `go-telegram-bot-goland` +- add `github.com/tucnak/telebot` to your project by running `go get -u gopkg.in/tucnak/telebot` +- create a new file `main.go` in your project +- import `tb "github.com/tucnak/telebot"` +- in your main func() type `bot, err := tb.NewBot(` and press ALT+\ to invoke copilot. +- by pressing ALT+\ a few more times you can add error checking, command handlers and a call to Start() the bot. + +To run the telegram bot: + - You need to use `BotFather` in Telegram to create a new bot and get its token. + - You'll use the token to create a bot instance. + - As a best practice, store the token in the environment variable `TELEGRAM_BOT_TOKEN` and in your code retrieve it from the environment. + - Start the bot and interact with it in Telegram. + diff --git a/gallery/go-telegram-bot-goland/go-telegram-bot-goland.mp4 b/gallery/go-telegram-bot-goland/go-telegram-bot-goland.mp4 new file mode 100644 index 0000000..c9db956 Binary files /dev/null and b/gallery/go-telegram-bot-goland/go-telegram-bot-goland.mp4 differ diff --git a/gallery/go-telegram-bot-goland/go.mod b/gallery/go-telegram-bot-goland/go.mod new file mode 100644 index 0000000..71a20cd --- /dev/null +++ b/gallery/go-telegram-bot-goland/go.mod @@ -0,0 +1,8 @@ +module go-telegram-bot-goland + +go 1.17 + +require ( + github.com/pkg/errors v0.9.1 // indirect + gopkg.in/tucnak/telebot.v2 v2.4.0 // indirect +) diff --git a/gallery/go-telegram-bot-goland/go.sum b/gallery/go-telegram-bot-goland/go.sum new file mode 100644 index 0000000..69ffe38 --- /dev/null +++ b/gallery/go-telegram-bot-goland/go.sum @@ -0,0 +1,11 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/tucnak/telebot.v2 v2.4.0 h1:nOeqOWnOAD3dzbKW+NRumd8zjj5vrWwSa0WRTxvgfag= +gopkg.in/tucnak/telebot.v2 v2.4.0/go.mod h1:BgaIIx50PSRS9pG59JH+geT82cfvoJU/IaI5TJdN3v8= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gallery/go-telegram-bot-goland/main.go b/gallery/go-telegram-bot-goland/main.go new file mode 100644 index 0000000..5d16952 --- /dev/null +++ b/gallery/go-telegram-bot-goland/main.go @@ -0,0 +1,22 @@ +package main + +import ( + tb "gopkg.in/tucnak/telebot.v2" + "log" + "os" + "time" +) +func main() { + bot, err := tb.NewBot(tb.Settings{ + Token: os.Getenv("TELEGRAM_TOKEN"), + Poller: &tb.LongPoller{Timeout: 10 * time.Second}, + }) + if err != nil { + log.Fatal(err) + } + bot.Handle("/start", func(m *tb.Message) { + bot.Send(m.Sender, "Hello from copilot, "+m.Sender.FirstName+"!") + }) + bot.Start() + +}