1
0
Fork 0
📚 Official unofficial Golang bindings for Telegraph API https://telegra.ph/api
Find a file
2024-08-08 04:24:42 +05:00
assets 🚚 Moved and fixed README.md 2024-08-05 16:09:43 +05:00
v2 🏷️ Fixed missing URL domain usage in EditAccountInfo method 2024-08-08 04:24:28 +05:00
.editorconfig 🎨 Format EditorConfig 2024-08-05 02:02:59 +05:00
.gitignore 🙈 Formatted .gitignore 2024-08-05 02:21:43 +05:00
content.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
content_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
CONTRIBUTING.md 📝 Updated CONTRIBUTING.md 2024-08-05 02:22:31 +05:00
create_account.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
create_account_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
create_page.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
create_page_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
doc.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
edit_account_info.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
edit_account_info_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
edit_page.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
edit_page_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
example_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_account_info.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_account_info_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_page.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_page_list.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_page_list_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_page_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_views.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
get_views_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
go.mod 📌 Upgraded go modules 2024-08-05 16:21:28 +05:00
go.sum 📌 Upgraded go modules 2024-08-05 16:21:28 +05:00
LICENSE.md 📄 Updated LICENSE.md date and name 2024-02-10 11:13:52 +06:00
README.en.md 🚚 Moved and fixed README.md 2024-08-05 16:09:43 +05:00
README.ru.md 🚚 Moved and fixed README.md 2024-08-05 16:09:43 +05:00
revoke_access_token.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
revoke_access_token_test.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
telegraph.go Revert removing old version changes 2024-08-05 16:19:50 +05:00
types.go Revert removing old version changes 2024-08-05 16:19:50 +05:00

telegraph Go Reference

A simple package with minimum official dependencies to work with Telegraph API.

Download:

$ go get -u source.toby3d.me/toby3d/telegraph/v2

Import:

import "source.toby3d.me/toby3d/telegraph/v2"

Fill commands structs and execute it:

package main

import (
  "context"
  "fmt"
  "log"
  "net/http"

  "source.toby3d.me/toby3d/telegraph/v2"
)

func Must[T any](v T, err error) T {
  if err != nil {
    panic(err)
  }

  return v
}

func main() {
  client := http.DefaultClient

  account, err := telegraph.CreateAccount{
    AuthorURL:  nil,
    AuthorName: Must(telegraph.NewAuthorName("Anonymous")),
    ShortName:  *Must(telegraph.NewShortName("Sandbox")),
  }.Do(context.Background(), client)
  if err != nil {
    log.Fatalln("cannot create account:", err)
  }

  page, err := telegraph.CreatePage{
    AuthorURL:   nil,
    AccessToken: account.AccessToken,
    Title:       *Must(telegraph.NewTitle("Sample Page")),
    AuthorName:  &account.AuthorName,
    Content: []telegraph.Node{{
      Element: &telegraph.NodeElement{
        Tag:      telegraph.P,
        Children: []telegraph.Node{{Text: "Hello, World!"}},
      },
    }},
    ReturnContent: true,
  }.Do(context.Background(), client)
  if err != nil {
    log.Fatalln("cannot create page:", err)
  }

  fmt.Printf("'%s' by %s\n%s", page.Title, page.AuthorName, page.Content[0])
  // 'Sample Page' by Anonymous
  // <p>Hello, World!</p>
}

If you need help, email me. If you want to help me, send a donation.