1

I'm trying to install telegram bot api module for golang from this link:
https://github.com/go-telegram-bot-api/telegram-bot-api

the installation example that showed there isnt working and raises the next error:

cannot find package "github.com/go-telegram-bot-api/telegram-bot-api/v5" in any of:
    /usr/local/go/src/github.com/go-telegram-bot-api/telegram-bot-api/v5 (from $GOROOT)
    /home/foo/go/src/github.com/go-telegram-bot-api/telegram-bot-api/v5 (from $GOPATH)

I looked on google and I saw some people recommending use "go install", but that raises the same error.

I would like to some help here, I'm trying figuring this out without a success for a while now. and feel free to ask for any further infotmation if you need

Thanks in advance!

  • Looking at the repo, you're trying to `go install` a _module_. The repo doesn't have a `main` package, so it's not supposed to be compiled to a standalone binary. The example in the readme would be something you write, and you import the package using `go get` (not `go install`). Then you can `go install` the main package _you_ wrote. – Elias Van Ootegem Aug 22 '22 at 15:15

1 Answers1

0

So to elaborate on my comment:

The package you're trying to use is a module. It has no main function (or main package). The example in the readme file is something you would write yourself. Say you want to call it "mybot", you'd go about it something like this:

$ mkdir mybot
$ go mod init github.com/yourname/mybot
$ go get -u github.com/go-telegram-bot-api/telegram-bot-api/v5
$ vim main.go

In this main.go you can paste the example, then run:

$ go build .

It'll generate a binary in the current directory called mybot. You can run this like any executable:

$ ./mybot

Once you're up and running, install it using go install .. This will put the binary in $GOPATH/bin. If you added that to your $PATH variable, you can just run the binary by running mybot from anywhere...

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149