Giter VIP home page Giter VIP logo

telegram-md's Introduction

telegram-md

Telegram MarkdownV2 formatter

GitHub CI Codecov NPM

telegram-md is a powerful TypesScript library designed to simplify the formatting of text messages in Telegram MarkdownV2 format. It provides a range of methods for applying markdown formatting, such as bold, italic, and links, making it easier to create richly formatted messages programmatically.

Table of Contents

  1. How to Install
  2. Usage Examples
  3. API Documentation

How to install

npm install @vlad-yakovlev/telegram-md

Usage Examples

import { md } from '@vlad-yakovlev/telegram-md'

// Simple message formatting
const message = md`Hello, ${md.bold('World')}!`
api.sendMessage(chatId, md.build(message))

// Using different formatting styles
const complexMessage = md`
  This is an ${md.italic('italic')}
  and ${md.bold('bold')} text
  with a ${md.link('link', 'http://example.com')}!
`
api.sendMessage(chatId, md.build(complexMessage))

API Documentation

Every method escapes all unescaped input. Input is assumed to be escaped only when it's an instance of Markdown.

Markdown

Stores the result of executing md methods. Used to differentiate between normal strings and escaped strings.

md

Template tag which can be used to build markdown formatted messages.

md`Hello, ${md.bold('World')}!` // => Markdown with value 'Hello, *World*\\!'

md.build

Returns message text that cat be safely sent to telegram API.

md.build(md`Hello, ${md.bold('World')}!`) // => 'Hello, *World*\\!'
md.build('Hello, World!') // => 'Hello, World\\!'

md.bold

md.bold('bold *text') // => Markdown with value '*bold \*text*'

md.italic

md.italic('italic *text') // => Markdown with value '_italic \*text_'

md.underline

md.underline('underline') // => Markdown with value '__underline__'

md.strikethrough

md.strikethrough('strikethrough') // => Markdown with value '~strikethrough~'

md.spoiler

md.spoiler('spoiler') // => Markdown with value '||spoiler||'

md.link

md.link('inline URL', 'http://www.example.com/') // => Markdown with value '[inline URL](http://www\\.example\\.com/)'
md.link('inline mention of a user', 'tg://user?id=123456789') // => Markdown with value '[inline mention of a user](tg://user?id\\=123456789)'

md.inlineCode

md.inlineCode('inline fixed-width code') // => Markdown with value '`inline fixed\\-width code`'

md.codeBlock

md.code(
  'pre-formatted fixed-width code block',
) // => Markdown with value
```
pre\\-formatted fixed\\-width code block
```
md.code(
  'pre-formatted fixed-width code block written in the Python',
  'python',
) // => Markdown with value
```python
pre\\-formatted fixed\\-width code block written in the Python
```

telegram-md's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar vlad-iakovlev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

neguindev

telegram-md's Issues

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.

Error

After run this code

import { md } from '@vlad-yakovlev/telegram-md'
...
let markupResponse = md.build("Test");
...

I received errors:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/andrey/sandbox/test/current/node_modules/@vlad-yakovlev/telegram-md/dist/index.js from /Users/andrey/sandbox/test/current/backend/src/modules/application.module.ts not supported.
Instead change the require of index.js in /Users/andrey/sandbox/test/current/backend/src/modules/application.module.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions..jsx.require.extensions..js (/private/var/folders/f9/1b1jz83s4ysfn9zfncbsb8y40000gn/T/ts-node-dev-hook-9053394042309917.js:114:20)
    at Object.nodeDevHook [as .js] (/Users/andrey/sandbox/test/current/node_modules/ts-node-dev/lib/hook.js:63:13)
    at Object.<anonymous> (/Users/andrey/sandbox/test/current/backend/src/modules/application.module.ts:23:23)
    at Module._compile (/Users/andrey/sandbox/test/current/node_modules/source-map-support/source-map-support.js:568:25)

Version

  • "grammy": "1.20.3",
  • "@vlad-yakovlev/telegram-md": "^2.0.0",
  • "@vlad-yakovlev/grammy-reply-with-markdown": "^2.0.1"

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

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.