📜 ⬆️ ⬇️

Framework for working with Telegraph API

image


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


A few words about the Telegraph


Telegraph is a service of notes and stories made in a minimalist style, developed by the Telegram team. Also support Instant View when viewing from Telegram.


In more detail 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 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 Re-issue:


 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


Editing page:


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

getPage


Receiving 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 page view 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 location, sending many messages solves the problem, but I believe that the Telegraph with its Instant View can do better.


Github


Telegraph-Node


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


Update: Support Promise


')

Source: https://habr.com/ru/post/318474/


All Articles