Telegraph API framework

Published on December 26, 2016

Telegraph API framework

image


On December 20, 2016, Telegram opened the API for the Telegraph . To work with it, I wrote a simple and functional library for JavaScript .


A few words about Telegraph


Telegraph is a minimalist style note and story service developed by the Telegram team. Also support for Instant View when viewing from Telegram.


More about Telegraph



Installation


npm install --save telegraph-node

Connection


const telegraph = require('telegraph-node')
const ph = new telegraph()

Available Methods



createAccount


Account Creation:


ph.createAccount(short_name, options).then((resulr) => {
 console.log(result)
})

editAccountInfo


Editing an account:


 ph.editAccountInfo(access_token, options).then((resulr) => {
 console.log(result)
})

getAccountInfo


Getting account information:


ph.getAccountInfo(access_token, options).then((resulr) => {
 console.log(result)
})

revokeAccessToken


Token reissue:


ph.revokeAccessToken(access_token).then((resulr) => {
 console.log(result)
})

createPage


Page creation:


ph.createPage(access_token, title, content, options).then((resulr) => {
 console.log(result)
})

editPage


Page Editing:


ph.editPage(access_token, path, title, content, options).then((resulr) => {
 console.log(result)
})

getPage


Getting page:


ph.getPage(path, options).then((resulr) => {
 console.log(result)
})

getPageList


Getting a list of pages:


ph.getPageList(access_token, options).then((resulr) => {
 console.log(result)
})

getViews


Getting the pageview count:


ph.getViews(path, options).then((resulr) => {
 console.log(result)
})

Query Processing


To process and send POST requests to the API, I used the Tiny Request framework


Application


I will use it to create Telegram Bot. It often happens that you need to display a large amount of information with pictures and locations, sending many messages solves the problem, but I believe that Telegraph can cope better with its Instant View.


Github


Telegraph-Node


Thanks to all those who have mastered the article. Waiting for your feedback and suggestion!


Update: Promise Support