Telegraph is Telegram bot API SDK for Go(Golang), Can use back off retry request to Telegram bot API
Reference to Telegram bot API Documentation
$ go get github.com/dynastymasra/telegraph
import library github.com/dynastymasra/telegraph
,
See Telegram API Documentation to know available method can used,
and what params can use in a method.
Create new client with no use back off retry, use params access token
obtain from telegram bot father.
client := telegraph.NewClient(<access_token>)
res, err := client.SetWebHook("https://www.cubesoft.co.id").SetCertificate("./LICENSE").SetMaxConnection(100).SetAllowedUpdates("1", "2", "3").Commit()
if err != nil {
// Do something when error
}
info, res, err := client.GetWebHookInfo().Commit()
if err != nil {
// Do something when error
}
Create new client with use back off retry, with params access token
obtain from telegram bot father and max interval
and max elapsed time
client := telegraph.NewClientWithBackOff(<access_token>, telegraph.NewBackOff(<max_interval>, <max_elapsed_time>))
res, err := client.DeleteWebHook().Commit()
if err != nil {
// Do something when error
}
Parse telegram web hook request, reference to telegram Documentation
message, err := telegraph.WebHookParseRequest(<request_in_[]byte>)
if err != nil {
// Do something when error
}
Send message to telegram use Telegraph SDK
client := telegraph.NewClientWithBackOff(<access_token>, telegraph.NewBackOff(<max_interval>, <max_elapsed_time>))
// Use upload false if file from url
message, res, err := client.SendPhoto(<chat_id>, "http://www.images.com/images/jpg", false).SetCaption("test image").Commit()
if err != nil {
// Do something when error
}
// Use upload true if from path file
message, res, err := client.SendAudio(<chat_id>, "/home/audio/audio.mp3", true).SetCaption("test audio").SetDuration(1000).Commit()
if err != nil {
// Do something when error
}
If you find any issue you want to fix it, feel free to send me a pull request. And also if you have idea for improvement this library, feel free to send me a pull request.
- GoRequest - Simplified HTTP client ( inspired by famous SuperAgent lib in Node.js )
- Backoff - The exponential backoff algorithm in Go (Golang)
- Gock - HTTP traffic mocking and expectations made easy for Go
- Testify - A toolkit with common assertions and mocks that plays nicely with the standard library