An open API service indexing awesome lists of open source software.

https://github.com/nickname76/telegrambot

Telegram Bot API library in Go, but with more clean code
https://github.com/nickname76/telegrambot

api bot go go-telegram-api go-telegram-bot-api golang library telegram telegram-bot telegram-bot-api wrapper

Last synced: 10 months ago
JSON representation

Telegram Bot API library in Go, but with more clean code

Awesome Lists containing this project

README

          

# [ Telegrambot](https://github.com/nickname76/telegrambot#example-usage) [](https://goreportcard.com/report/github.com/nickname76/telegrambot)

[](https://discord.gg/rX4EhxsW6X)

The most clean and strongly typed Telegram Bot API library in Go

Completely covers Bot API version - **6.2**

Telegram Bot API documentaion: https://core.telegram.org/bots/api

Telegram deep links list: https://core.telegram.org/api/links

More Telegram deep links: https://t.me/DeepLink

**DISCORD**: [https://discord.gg/golang](https://discord.gg/rX4EhxsW6X) (#telegrambot channel)

**Documentation on this library:**

- API https://pkg.go.dev/github.com/nickname76/telegrambot
- Tools https://pkg.go.dev/github.com/nickname76/telegrambot/tools

_Please, **star** this repository, if you found this library useful!_

## Example usage

```Go
package main

import (
"fmt"
"log"
"os"
"os/signal"

"github.com/nickname76/telegrambot"
)

func main() {
api, me, err := telegrambot.NewAPI("YOUR_TELEGRAM_BOT_API_TOKEN")
if err != nil {
log.Fatalf("Error: %v", err)
}

stop := telegrambot.StartReceivingUpdates(api, func(update *telegrambot.Update, err error) {
if err != nil {
log.Printf("Error: %v", err)
return
}

msg := update.Message
if msg == nil {
return
}

_, err = api.SendMessage(&telegrambot.SendMessageParams{
ChatID: msg.Chat.ID,
Text: fmt.Sprintf("Hello %v, I am %v", msg.From.FirstName, me.FirstName),
ReplyMarkup: &telegrambot.ReplyKeyboardMarkup{
Keyboard: [][]*telegrambot.KeyboardButton{{
{
Text: "Hello",
},
}},
ResizeKeyboard: true,
OneTimeKeyboard: true,
},
})

if err != nil {
log.Printf("Error: %v", err)
return
}
})

log.Printf("Started on %v", me.Username)

exitCh := make(chan os.Signal, 1)
signal.Notify(exitCh, os.Interrupt)

<-exitCh

// Waits for all updates handling to complete
stop()
}

```

## See also

If you want to develop Telegram bot, you should also see these libraries, which might be useful for you

- [Repeater](https://github.com/nickname76/repeater) - Go library for creating repeating function calls
- [QiwiP2P](https://github.com/nickname76/qiwip2p) - Go library for Qiwi P2P API