Giter Site home page Giter Site logo

mcpeblocker / telegraf-entity Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 11 KB

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

License: MIT License

JavaScript 100.00%
bot telegraf telegraf-plugin telegrafjs telegram-bot

telegraf-entity's Introduction

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

telegraf-entity's People

Contributors

mcpeblocker avatar tmb-01 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

tmb-01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.