installing telegram bot api package failed

645 Views Asked by At

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!

1

There are 1 best solutions below

0
Elias Van Ootegem On

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...