telegra.ph-next
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

📝 telegra.ph-next

Tiny API helper for Telegra.ph, forked from telegra.ph with various improvements:

  • No dependencies
  • No frivolous tests
  • 100% typescript source
  • Use any HTTP client
  • Uses JSDoc

Installation

$ npm install telegra.ph-next --save

Example

Create an account

import Telegraph from "telegra.ph-next"

const client = new Telegraph()

const account = client.createAccount()
client.token = account.access_token

const pages = await client.getPageList()
console.log(pages)

Use existing account

import Telegraph from "telegra.ph-next"

const client = new Telegraph(process.env.TOKEN)

const pages = await client.getPageList()
console.log(pages)

Use arbitrary HTTP Client

fetch

import Telegraph from "telegra.ph-next"
import { Fetch } from "telegra.ph/clients"

const client = new Telegraph(process.env.TOKEN, { client: Fetch })

const pages = await client.getPageList()
console.log(pages)

external

import Telegraph from "telegra.ph-next"
import type { Client } from "telegra.ph-next/clients"
import axios, { type AxiosInstance } from "axios"

class Axios implements Client {
    protected client: AxiosInstance

    constructor(public baseURL: string) {
        this.client = axios.create({ baseURL })
    }

    public async get<R = unknown>(path: string): Promise<R> {
        const { data } = await this.client.get<{ result: R }>(path)
        return data.result
    }

    public async post<R = unknown>(path: string, body: unknown): Promise<R> {
        const { data } = await this.client.post<{ result: R }>(path, body)
        return data.result
    }
}

const client = new Telegraph(process.env.TOKEN, { client: Axios })

API documentation

createAccount

.createAccount(shortName, name, url)

createPage

.createPage(title, content, authorName, authorUrl, returnContent)

editAccountInfo

.editAccountInfo(shortName, name, url)

editPage

.editPage(path, title, content, authorName, authorUrl, returnContent)

getPage

.getPage(path, returnContent)

getViews

.getViews(path, year, month, day, hour)

getPageList

.getPageList(path, offset, limit)

revokeAccessToken

.revokeAccessToken()

Readme

Keywords

Package Sidebar

Install

npm i telegra.ph-next

Weekly Downloads

1

Version

2.0.6

License

MIT

Unpacked Size

31.3 kB

Total Files

25

Last publish

Collaborators

  • godbleak