项目作者: dynastymasra

项目描述 :
Telegram bot API Go SDK
高级语言: Go
项目地址: git://github.com/dynastymasra/telegraph.git
创建时间: 2017-10-24T01:46:09Z
项目社区:https://github.com/dynastymasra/telegraph

开源协议:MIT License

下载


Telegraph

Build Status
Coverage Status
Go Report Card
GoDoc
Version
License: MIT

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

Installation

  1. $ go get github.com/dynastymasra/telegraph

How to use

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.

  1. client := telegraph.NewClient(<access_token>)
  2. res, err := client.SetWebHook("https://www.cubesoft.co.id").SetCertificate("./LICENSE").SetMaxConnection(100).SetAllowedUpdates("1", "2", "3").Commit()
  3. if err != nil {
  4. // Do something when error
  5. }
  6. info, res, err := client.GetWebHookInfo().Commit()
  7. if err != nil {
  8. // Do something when error
  9. }

Create new client with use back off retry, with params access token obtain from telegram bot father and max interval and max elapsed time

  1. client := telegraph.NewClientWithBackOff(<access_token>, telegraph.NewBackOff(<max_interval>, <max_elapsed_time>))
  2. res, err := client.DeleteWebHook().Commit()
  3. if err != nil {
  4. // Do something when error
  5. }

Parse telegram web hook request, reference to telegram Documentation

  1. message, err := telegraph.WebHookParseRequest(<request_in_[]byte>)
  2. if err != nil {
  3. // Do something when error
  4. }

Send message to telegram use Telegraph SDK

  1. client := telegraph.NewClientWithBackOff(<access_token>, telegraph.NewBackOff(<max_interval>, <max_elapsed_time>))
  2. // Use upload false if file from url
  3. message, res, err := client.SendPhoto(<chat_id>, "http://www.images.com/images/jpg", false).SetCaption("test image").Commit()
  4. if err != nil {
  5. // Do something when error
  6. }
  7. // Use upload true if from path file
  8. message, res, err := client.SendAudio(<chat_id>, "/home/audio/audio.mp3", true).SetCaption("test audio").SetDuration(1000).Commit()
  9. if err != nil {
  10. // Do something when error
  11. }

Contributing

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.

Library

  • 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