Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Add a sample go project using GoLand #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gallery/go-telegram-bot-goland/README.md
Original file line number Diff line number Diff line change
@@ -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.

Binary file not shown.
8 changes: 8 additions & 0 deletions gallery/go-telegram-bot-goland/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 11 additions & 0 deletions gallery/go-telegram-bot-goland/go.sum
Original file line number Diff line number Diff line change
@@ -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=
22 changes: 22 additions & 0 deletions gallery/go-telegram-bot-goland/main.go
Original file line number Diff line number Diff line change
@@ -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()

}