JSPM

telegraph-api

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q32454F
  • License MIT

API for Telegram's Telegraph

Package Exports

  • telegraph-api

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (telegraph-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Telegraph-API

Telegram's Telegraph doesn't have API. Package suggest some missed handles for publishing posts on Telegraph's platform.

Install

Terminal:

// npm
npm i telegraph-api --save

// yarn
yarn add telegraph-api

Usage

First of all you need to create new instance of telegraph-api.

const Post = require('telegraph-api');

// without params
const firstPost = new Post();

// or with params
const secondPost = new Post({
    header: 'Header',
    author: 'Author',
    paragraphs: ['Paragraph']
});

Then you can use public getters and setters methods that it provides:

  • getHeader() - returns String
  • setHeader({String})
  • getAuthor() - returns String
  • setAuthor({String})
  • getParagraphs() - returns String[]
  • setParagraphs({String[]})
  • setParagraph({String})
  • removeLastParagraph()
  • emptyHeader()
  • emptyAuthor()
  • emptyParagraphs()
  • publishPost({Function({Error}, {String})})

Examples

Filled constructor

const Post = require('telegraph-api');

const myPost = new Post({
    header: 'Telegraph-API',
    author: 'Roman Ponomarev',
    paragraphs: ['First post by Telegraph-API']
});

myPost.publishPost((err, link) => {
    if (err) {
        throw new Error(error);
    }

    console.log(`Link to Post: ${link}`); // => Link to Post: http://telegra.ph/Telegraph-API-11-28
});

Empty constructor

const Post = require('telegraph-api');

const myPost = new Post();

myPost.setHeader('Telegraph-API');
myPost.setAuthor('Roman Ponomarev');
myPost.setParagraph('Second post by Telegraph-API');

console.log(myPost.getHeader()); // => Telegraph-API
console.log(myPost.getAuthor()); // => Roman Ponomarev
console.log(myPost.getParagraphs()); // => ['Second post by Telegraph-API']

myPost.publishPost((err, link) => {
    if (err) {
        throw new Error(error);
    }

    console.log(`Link to Post: ${link}`); // => Link to Post: http://telegra.ph/Telegraph-API-11-28-2
});