Skip to content

A library that converts telegram message entities into html and markdown formats. (Intented to use alongside with TelegrafJS)

License

Notifications You must be signed in to change notification settings

mcpeblocker/telegraf-entity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telegraf-entity

A library that converts telegram message entities into html and markdown formats. (Intented to use alongside with TelegrafJS)

Getting started

Prerequisites

This library is intented to use alongside with telegraf. But you still can test it with other frameworks or your own codebase - all you need are text and array of entity objects in that text.

To use the example below you can have telegraf installed in your project.

$ npm install telegraf

or

$ yarn add telegraf

See offical guide for more info. Once you have installed telegraf in your project, you can use telegraf-pagination.

Installing

Run one of these commands depending on what package manager you're using:

$ npm install telegraf-entity

or

$ yarn add telegraf-entity

Quick start

Here is an example:

const { EntityMessage } = require("telegraf-entity");

bot.on("message", (ctx) => {
  if (!ctx.message.text || !ctx.message.entities) return;
  const formatter = new EntityMessage(ctx.message.text, ctx.message.entities);
  let htmlContent = formatter.html;
  let markdownContent = formatter.markdown;
  console.log("HTML: ", htlmContent);
  console.log("Markdown: ", markdownContent);
});

TODO features:

  • Default formatters:
    • mention
    • hashtag
    • cashtag
    • bot_command
    • url
    • email
    • phone_number
    • bold
    • italic
    • underline
    • strikethrough
    • spoiler
    • code
    • pre
    • text_link
    • text_mention
    • custom_emoji
  • Options for custom formatters for specific entities like spoiler, custom_emoji... (maybe for all)

Contributing

Please read CODE_OF_CONDUCT.md for details on our code of conduct. Feel free to submit any pull request.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A library that converts telegram message entities into html and markdown formats. (Intented to use alongside with TelegrafJS)

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published