Skip to content

Commit

Permalink
Merged latest v5 (5.5.1) API from upstream project.
Browse files Browse the repository at this point in the history
  • Loading branch information
semog committed Jan 6, 2025
2 parents c3784e1 + 4126fa6 commit 27f97fe
Show file tree
Hide file tree
Showing 32 changed files with 7,425 additions and 2,393 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

on:
push:
branches:
- master
- develop
pull_request:

jobs:
build:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build -v .

- name: Test
run: go test -coverprofile=coverage.out -covermode=atomic -v .

- name: Upload coverage report
uses: codecov/codecov-action@v1
with:
file: ./coverage.out
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
coverage.out
tmp/
book/
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
This package is a fork to add minimal new features, and to bring support for the
latest Telegram Bot API.

[![Go Reference](https://pkg.go.dev/badge/github.com/go-telegram-bot-api/telegram-bot-api/v5.svg)](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5)
[![Test](https://github.com/go-telegram-bot-api/telegram-bot-api/actions/workflows/test.yml/badge.svg)](https://github.com/go-telegram-bot-api/telegram-bot-api/actions/workflows/test.yml)

All methods are fairly self-explanatory, and reading the [godoc](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5) page should
explain everything. If something isn't clear, open an issue or submit
a pull request.

There are more tutorials and high-level information on the website, [go-telegram-bot-api.dev](https://go-telegram-bot-api.dev).

The scope of this project remains close to the original project, but adds
a simple command dispatching model that makes it easy to get your bot up
and running quickly without having to implement the same boilerplate code
Expand All @@ -16,6 +25,9 @@ from the original development version.

## Example

First, ensure the library is installed and up to date by running
`go get -u github.com/semog/telegram-bot-api/v5`.

This sample shows a main() function that connects to the bot,
and then starts the command listener loop. This is all that is required in the
main() function. The RunBot() function will handle running your bot and dispatch
Expand All @@ -31,7 +43,7 @@ package main
import (
"log"

tg "github.com/semog/telegram-bot-api"
tg "github.com/semog/telegram-bot-api/v5"
)

func main() {
Expand Down Expand Up @@ -78,7 +90,7 @@ func mybotOnCommand(bot *tg.BotAPI, cmd string, msg *tg.Message) bool {

func doTextReply(bot *tg.BotAPI, msg *tg.Message) {
log.Printf("[%s] %s", msg.From.UserName, msg.Text)
replymsg := tgbotapi.NewMessage(msg.Chat.ID, msg.Text)
replymsg := tg.NewMessage(msg.Chat.ID, msg.Text)
replymsg.ReplyToMessageID = msg.MessageID
bot.Send(replymsg)
}
Expand All @@ -101,7 +113,7 @@ package main
import (
"log"
"net/http"
tg "github.com/semog/telegram-bot-api"
tg "github.com/semog/telegram-bot-api/v5"
)

func main() {
Expand All @@ -114,17 +126,22 @@ func main() {

log.Printf("Authorized on account %s", bot.Self.UserName)

_, err = bot.SetWebhook(tg.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
wh, _ := tg.NewWebhookWithCert("https://www.example.com:8443/"+bot.Token, "cert.pem")

_, err = bot.Request(wh)
if err != nil {
log.Fatal(err)
}

info, err := bot.GetWebhookInfo()
if err != nil {
log.Fatal(err)
}

if info.LastErrorDate != 0 {
log.Printf("Telegram callback failed: %s", info.LastErrorMessage)
}

updates := bot.ListenForWebhook("/" + bot.Token)
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)

Expand All @@ -134,7 +151,7 @@ func main() {
}
```

If you need, you may generate a self signed certficate, as this requires
If you need, you may generate a self-signed certificate, as this requires
HTTPS / TLS. The above example tells Telegram that this is your
certificate and that it should be trusted, even though it is not
properly signed.
Expand Down
9 changes: 9 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[book]
authors = ["Syfaro"]
language = "en"
multilingual = false
src = "docs"
title = "Go Telegram Bot API"

[output.html]
git-repository-url = "https://github.com/go-telegram-bot-api/telegram-bot-api"
Loading

0 comments on commit 27f97fe

Please sign in to comment.