Automated Article Posting. Telegra.ph Automation

Dmitriy Ka

Client
Регистрация
03.05.2016
Сообщения
773
Благодарностей
517
Баллы
93
118357


Hello everyone,
Especially for this contest, I have prepared a small but very useful template for automating article posting based on Telegraph.

Here are some articles we'll be getting: An article.
Example of using the template: Link

Telegra.ph is a unique platform provided by Telegram that allows users to create beautifully formatted articles and publish them online without the need for registration or creating a separate account. It's a simple and effective tool for creating and publishing content directly from the messenger.

Features of Telegra.ph:
1) Ease of use: The platform has an intuitive interface that allows to create and edit articles quickly. The lack of registration makes the process even more convenient.
2) Rich functionality: Telegra.ph supports various content elements such as text, images, and videos. Users can easily format their articles using the available formatting tools.
3) Flexibility and universality: Publications on Telegra.ph can be accessed via a direct link or shared in Telegram channels and groups.
4) Open API: Telegra.ph provides an API for interacting with the platform, opening up wide possibilities for automating content creation and management.
Using the Telegra.ph API makes it easy and simple to automate content publication and extend the functionality of the Telegram messenger.

Next, I will explain in more detail how to launch autoposting to work with content.
  1. Create an object of the MyTelegraph class.
  2. Create an account using the CreateAccount() method – get an AccessToken for further work. (It can be saved separately from the AccessToken property for further work without creating a new account each time)
  3. If you need to upload an image to the Telegra.ph servers, use the UploadImg() method – get URL for further use.
  4. Using the ContentBuilder field, create content blocks for your article.
    C#:
    var t = new Telegraf(project);
    var creator = t.ContentBuilder;
    var content = creator
    .AddImg(imgUrl)
    .AddText(text)
    .AddText("")
    .AddLink("https://zennolab.com/discussion/threads/posting-statej-na-avtomate-avtomatizacija-telegra-ph.118163", "Read")
        .Create();
  5. Use the CreatePage() method to write the article title and pass content from ContentBuilder to create the article.
For a better understanding, I have attached a template with an example. You can also familiarize yourself with the full code in the "Common Code" section.

Short Documentation
For the operation, a separate class called Telegraf is written, which represents a client for interacting with the Telegra.ph API.

Fields:
- ContentBuilder: an instance of the ContentBuilder class for quick and convenient creation of JSON content structure before creating a page.

Properties:
- ShortName: the short name of the created Telegra.ph account.
- AccessToken: access token for the Telegra.ph API.

Methods:
- MyTelegraph(IZennoPosterProjectModel project): class constructor, initializes an instance of the MyTelegraph class.
Parameters:
- project: an object representing the project in ZennoPoster.

- bool CreateAccount (string shortName, string authorName = "", string authorUrl = ""): creates an account on Telegra.ph.
Parameters:
- shortName: short name of the account.
- authorName: author's name (default is empty).
- authorUrl: author's link (default is empty).
Returns:
- true if the account is successfully created.
Exceptions:
- Exception: in case of an error during account creation.

- void SetAccessToken (string accessToken): sets the user's AccessToken for accessing the Telegra.ph API.
Parameters:
- accessToken: user's AccessToken.

- string CreatePage (string title, string content, string authorName = "", string authorUrl = "", bool isReturnContent = false): creates a page on Telegra.ph.
Parameters:
- title: page title.
- content: page content in JSON format.
- authorName: author's name (default is empty).
- authorUrl: author's link (default is empty).
- isReturnContent: specifies whether to return the content in the page object (default is false).
Returns:
- URL of the created page on Telegra.ph.
Exceptions:
- Exception: in case of an error during page creation.

- string UploadImg (string pathImg): uploads an image to Telegra.ph. (works without accessToken)
Parameters:
- pathImg: path to the image.
Returns:
- URL of the uploaded image on Telegra.ph.
Exceptions:
- Exception: in case of an error during image upload.

The auxiliary class ContentBuilder represents a JSON content builder for posting on Telegra.ph. Called via the ContentBuilder field of the MyTelegraph class.

Methods:
- string Create(): creates and returns the final content in JSON format.
Returns:
- final content in JSON format.

- ContentBuilder AddImg (string urlImg): adds an image to the content.
Parameters:
- urlImg: image URL.
Returns:
- an instance of the ContentBuilder class to support method chaining (Fluent Interface).

- ContentBuilder AddText (string text): adds a text element to the content.
Parameters:
- text: text to add.
Returns:
- an instance of the ContentBuilder class to support method chaining (Fluent Interface).

- ContentBuilder AddLink (string link, string name): adds a link to the content.
Parameters:
- link: link URL.
- name: link name.
Returns:
-an instance of the ContentBuilder class to support method chaining (Fluent Interface).

Thank you for reading my article. I hope it was useful and interesting for you. If you have any questions or suggestions, please write in the comments. Thank you for your attention and I wish you success in your work!
 

Вложения

Последнее редактирование:
  • Спасибо
Реакции: wildjack

Dmitriy Ka

Client
Регистрация
03.05.2016
Сообщения
773
Благодарностей
517
Баллы
93
Updated the template
 

Вложения

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)