modulepackage
0.2.1
Repository: https://github.com/techminerapps/telegraph.git
Documentation: pkg.go.dev
# README
Golang library for Telegraph API
This project is just to provide a wrapper around the API without any additional features.
Caution! This library is under refactoring, interface may change.
Start using telegraph
Download and install it:
$ go get -u github.com/TechMinerApps/telegraph
Import it in your code:
import "github.com/TechMinerApps/telegraph"
Document
See GoDoc
QuickStart
// Content in a string format (for this example).
// Be sure to wrap every media in a <figure> tag, okay? Be easy.
const data = `
<figure>
<img src="/file/6a5b15e7eb4d7329ca7af.jpg"/>
</figure>
<p><i>Hello</i>, my name is <b>Page</b>, <u>look at me</u>!</p>
<figure>
<iframe src="https://youtu.be/fzQ6gRAEoy0"></iframe>
<figcaption>
Yes, you can embed youtube, vimeo and twitter widgets too!
</figcaption>
</figure>
`
func Example_fastStart() {
var err error
// Create new Telegraph account.
requisites := telegraph.Account{
ShortName: "toby3d", // required
// Author name/link can be epmty. So secure. Much anonymously. Wow.
AuthorName: "Maxim Lebedev", // optional
AuthorURL: "https://t.me/toby3d", // optional
}
client := telegraph.NewClient()
account, err = client.CreateAccount(requisites)
if err != nil {
// Do error check
}
// Make sure that you have saved acc.AuthToken for create new pages or make
// other actions by this account in next time!
// Format content to []telegraph.Node array. Input data can be string, []byte
// or io.Reader.
content, err = client.ContentFormat(data)
if err != nil {
// Do error check
}
// Boom!.. And your text will be understandable for Telegraph. MAGIC.
// Create new Telegraph page
pageData := telegraph.Page{
Title: "My super-awesome page", // required
Content: content, // required
// Not necessarily, but, hey, it's just an example.
AuthorName: account.AuthorName, // optional
AuthorURL: account.AuthorURL, // optional
}
page, err = client.CreatePage(pageData, false)
if err != nil {
// Do error check
}
// Show link from response on created page.
log.Println("Kaboom! Page created, look what happened:", page.URL)
}
Credit
Original developer: @toby3d
License
This Project is licensed under MIT License
# Functions
NewClient return a empty client useful when creating new account or testing otherwise should use NewClientWithToken.
NewClientWithToken create a client from a valid token the client is already usable with account info set correctly.
# Constants
FieldAuthorName used as GetAccountInfo argument for getting author name.
FieldAuthorURL used as GetAccountInfo argument for getting profile link.
FieldAuthURL used as GetAccountInfo argument for getting URL to authorize a browser on telegra.ph.
FieldPageCount used as GetAccountInfo argument for getting number of pages belonging to the Telegraph account.
FieldShortName used as GetAccountInfo argument for getting account name.
# Variables
ErrFloodWait is returned when recieving a flood error.
ErrInvalidDataType is returned when ContentFormat function are passed a data argument of invalid type.
ErrNoInputData is returned when any method get nil argument.
# Structs
All types used in the Telegraph API responses are represented as JSON-objects.
All types used in the Telegraph API responses are represented as JSON-objects.
All types used in the Telegraph API responses are represented as JSON-objects.
All types used in the Telegraph API responses are represented as JSON-objects.
All types used in the Telegraph API responses are represented as JSON-objects.
Response contains a JSON object, which always has a Boolean field ok.