Yaamiin / telegraph

Golang Bindings for Telegraph API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang Bindings for Telegraph API

⭐️ A star from you, means a lot!

This library represents a convenient wrapper around the Telegra.ph API. This is my first project in golang, so I would love to know my mistakes.

Features

Here are the most important aspects, shown as pros and cons:

Pros

  • Auto-generated from API, leaving less space for mistakes.
  • Very easy to use.
  • Upload media to Telegraph, the method which isn't included in the official API.
  • Helpful methods like Prettify() to pretty-print any object or convert object to JSON.
  • In-built HTML to NodeElement conversion so you can directly use strings with embedded HTML
  • Highly documented (doc strings) for IDEs like VSCode.

Cons

  • Types Node and NodeElement are not implemented.
  • No custom error handling. Not much panicking. Though official errors will be returned as Error object. But I guess that's conventional, and maybe convenient?
  • The bugs you are going to find.

Installing

Just install it using the standard go get command.

go get github.com/StarkBotsIndustries/telegraph@v1.0.0

Documentation

Docs can be found here : Go Reference

Usage

This is pretty straightforward. First, import the library

import "github.com/StarkBotsIndustries/telegraph"

Now you can call any methods. Let's say, CreateAccount?

acc, err := telegraph.CreateAccount(&telegraph.CreateAccountOpts{ShortName: "Go is Love"})

acc.AccessToken
>>> abcdefghijklmnopqrstuvwxyz

acc.ShortName
>>> Go is Love

Or CreatePage

page, err := telegraph.CreatePage(&telegraph.CreatePageOpts{
    Title: "My First Page", 
    Content: "Hi <b>Brothers</b> and <code>Sisters</code>", 
    AccessToken: "abcdefghijklmnopqrstuvwxyz",
})

page.URL
>>> https://telegra.ph/My-First-Page-02-20

page.Path
>>> My-First-Page-02-20

Pretty Print an Object / Convert to JSON

acc, err := telegraph.CreateAccount(&telegraph.CreateAccountOpts{ShortName: "Go is Love"})
prettifiedObject := telegraph.Prettify(acc)

prettifiedObject
>>> {
>>>     "short_name": "Go is Love",
>>>     "author_name": "",
>>>     "author_url": "",
>>>     "access_token": "abcdefghijklmnopqrstuvwxyz",
>>>     "auth_url": "https://edit.telegra.ph/auth/lmnopqrstuvwxyzabcdefghijk",
>>>     "page_count": 0
>>> }

Upload Media to Telegraph

file, _ := os.Open("file.jpg")
// os.File is io.Reader so just pass it.
link, _ := telegraph.Upload(file, "photo")

link
>>> https://telegra.ph/file/abcdefghijklmnopqrstuvwxyz.jpg

Community and Support

Telegram Channel - StarkBots

Telegram Chat - StarkBotsChat

Copyright and License

About

Golang Bindings for Telegraph API

License:GNU General Public License v3.0


Languages

Language:Go 100.0%