Description
Bindings for Telegram Bot API on Go. API v4.4 (29 July 2019) is supported. All methods and types represent their alter ego from Telegram Bot API so you would expect what you see in the official documentation. And you don't need to study the new API to use this library.
Telegraphist alternatives and similar packages
Based on the "Third-party APIs" category.
Alternatively, view Telegraphist alternatives based on common mentions on social networks and blogs.
-
goamz
Popular fork of goamz which adds some missing API calls to certain packages. -
webhooks
:fishing_pole_and_fish: Webhook receiver for GitHub, Bitbucket, GitLab, Gogs -
githubql
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). -
geo-golang
Go library to access geocoding and reverse geocoding APIs -
twitter-scraper
Scrape the Twitter Frontend API without authentication with Golang. -
lark
Feishu/Lark Open API Go SDK, Support ALL Open API and Event Callback. -
gostorm
GoStorm is a Go library that implements the communications protocol required to write Storm spouts and Bolts in Go that communicate with the Storm shells. -
hipchat (xmpp)
A golang package to communicate with HipChat over XMPP -
clarifai
DEPRECATED: please use https://github.com/Clarifai/clarifai-go-grpc -
hipchat
This project implements a Go client library for the Hipchat API. -
go-trending
Go library for accessing trending repositories and developers at Github. -
go-lark
An easy-to-use SDK for Feishu and Lark Open Platform (Messaging API only) -
go-tgbot
Golang telegram bot API wrapper, session-based router and middleware -
cachet
Go(lang) client library for Cachet (open source status page system). -
simples3
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK) -
go-postman-collection
Go module to work with Postman Collections -
ynab
Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.
Static code analysis for 29 languages.
Do you think we are missing an alternative of Telegraphist or a related project?
README
Telegraphist
Telegram Bot API on Go. API v4.4 (29 July 2019) is supported. All methods and types represent their alter ego from Telegram Bot API so you would expect what you see in the official documentation. And you don't need to study the new API to use this library.
Documentation
- Official Telegram Bot API documentation
- telegraphist
- telegraphist/telegram
Installation
go get -u github.com/xamut/telegraphist
Usage
package main
import (
"encoding/json"
"fmt"
"os"
Telegraphist "github.com/xamut/telegraphist"
Telegram "github.com/xamut/telegraphist/telegram"
)
func printResp(resp interface{}, err error) {
if err != nil {
fmt.Println(err)
}
respAsJSON, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println(string(respAsJSON))
}
func main() {
telegraphist, err := Telegraphist.NewClient(&Telegraphist.ClientConfig{
BotToken: "YOUR_BOT_TOKEN",
})
if err != nil {
fmt.Println(err)
}
printResp(telegraphist.GetMe()) // Simple method to obtain basic bot info
// https://core.telegram.org/bots/api#getme
// Returns an User struct
chatID := int64(<YOUR_CHAT_ID>)
printResp(telegraphist.SendMessage(&Telegram.SendMessageParams{ // Send a text message to a chat
ChatID: chatID, // https://core.telegram.org/bots/api#sendmessage
Text: "Hello there!", // Returns a Message struct
}))
photo, _ := os.Open("<PATH_TO_PHOTO>")
printResp(telegraphist.SendPhoto(&Telegram.SendPhotoParams{ // Send a photo to a chat
ChatID: chatID, // https://core.telegram.org/bots/api#sendphoto
Photo: photo, // Returns a Message struct
Caption: "Just a nice photo",
}))
}
Getting updates
Webhook
- Find your IP
curl ifconfig.co
Use nip.io to pretend you have a domain, for example, "app.X.X.X.X.nip.io"
Generate a certificate, replace X.X.X.X with your IP:
openssl req -newkey rsa:2048 \
-new -nodes -x509 \
-days 3650 \
-out cert.pem \
-keyout key.pem \
-subj "/O=Organization/CN=app.X.X.X.X.nip.io"
- Run server
package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"path"
Telegraphist "github.com/xamut/telegraphist"
Telegram "github.com/xamut/telegraphist/telegram"
)
func combineURL(host string, parts ...string) string {
baseURL, err := url.Parse(host)
if err != nil {
log.Fatal(err)
}
parts = append([]string{baseURL.Path}, parts...)
baseURL.Path = path.Join(parts...)
return baseURL.String()
}
func main() {
telegraphist, err := Telegraphist.NewClient(&Telegraphist.ClientConfig{
BotToken: "<YOUR_BOT_TOKEN>",
})
if err != nil {
log.Fatal(err)
}
host := "https://app.X.X.X.X.nip.io" // For example: "https://example.com"
webhookPath := "<YOUR_WEBHOOK_PATH>" // For example: "/telegram_webhook"
cert, _ := os.Open("./cert.pem")
ok, err := telegraphist.SetWebhook(&Telegram.SetWebhookParams{
URL: combineURL(host, webhookPath),
Certificate: cert,
})
if err != nil {
log.Fatal(err)
}
if !ok {
log.Println("Something went wrong and the webhook wasn't set up")
}
handlers := map[string]func(update Telegram.Update) error{
// "message": func(update Telegram.Update) error {},
// "edited_message": func(update Telegram.Update) error {},
// "channel_post": func(update Telegram.Update) error {},
// "edited_channel_post": func(update Telegram.Update) error {},
// "inline_query": func(update Telegram.Update) error {},
// "chosen_inline_result": func(update Telegram.Update) error {},
// "callback_query": func(update Telegram.Update) error {},
// "shipping_query": func(update Telegram.Update) error {},
// "pre_checkout_query": func(update Telegram.Update) error {},
// "poll": func(update Telegram.Update) error {},
"always": func(update Telegram.Update) error {
js, _ := json.MarshalIndent(update, "", "\t")
fmt.Println(string(js))
return nil
},
}
err = Telegraphist.NewServer(&Telegraphist.ServerConfig{
EnableHTTPS: true,
Webhook: webhookPath,
}, &handlers)
if err != nil {
log.Fatal(err)
}
}
NOTE: Use this example only for testing purposes, for production use something like nginx or traefik to serve HTTPS (and/or to (re)generate Let's Encrypt certificate).
License
Telegraphist is released under the MIT License.
*Note that all licence references and agreements mentioned in the Telegraphist README section above
are relevant to that project's source code only.