Socket
Book a DemoInstallSign in
Socket

tgast-util-to-telegram-entity

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tgast-util-to-telegram-entity

tgast utility that turns a tgast syntax tree into a Telegram message with entities.

0.0.1
next
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

tgast-util-to-telegram-entity

NPM Version Static Badge Static Badge

tgast utility that converts a tgast tree into a Telegram message with entities.

What is this?

This package turns a tgast syntax tree into a plain Telegram message, with formatting preserved using message entities.

It is used in regram-parse and helps with transforming Telegram content.

When should I use this?

Use this if you work directly with syntax trees and want to output Telegram messages. If you prefer a simpler way to process content, check out regram.

Install

# deno
deno add npm:tgast-util-to-telegram-entity

# bun
bun add tgast-util-to-telegram-entity

# pnpm
pnpm add tgast-util-to-telegram-entity

# yarn
yarn add tgast-util-to-telegram-entity

# npm
npm install tgast-util-to-telegram-entity

Use

Say we have this tgast tree:

import type { Root } from 'tgast-util-to-telegram-entity'
import { toTelegramEntity } from 'tgast-util-to-telegram-entity'

const tree: Root = {
  type: 'root',
  children: [
    {
      type: 'bold',
      children: [
        {
          type: 'text',
          value: 'This is a bold text.',
        },
      ],
    },
  ],
}

const message = toTelegramEntity(tree)

console.log(message)

...now the console.log(message) will yield:

{
  "text": "This is a bold text.",
  "entities": [
    {
      "offset": 0,
      "length": 20,
      "type": "bold"
    }
  ]
}

API

Exports:

There is no default export.

toTelegramEntity

(click to see)
function toTelegramEntity(tree: Root): Message

Converts a tgast tree into a plain Telegram message with entities.

Type reference: https://github.com/tgast-ecosystem/tgast-util-to-telegram-entity/blob/main/src/to-telegram-entity.ts#L12

Parameters

  • tree (Root) — A tgast syntax tree.

Returns

A Message with text and entities.

Root

(click to see)
interface Root {
  type: 'root'
  position?: Position
  data?: RootData
  children: RootContent[]
}

The root node of the tgast tree.

Type reference: https://github.com/tgast-ecosystem/tgast/blob/main/src/nodes/root.ts#L16-L25

Message

(click to see)
interface Message {
  text: string
  entities: MessageEntity[]
}

Represents a Telegram message with formatted text.

Type reference: https://github.com/tgast-ecosystem/tgast-util-to-telegram-entity/blob/main/src/types/message.type.ts#L4-L11

Properties

  • text (string) — The plain text of the message.
  • entities (MessageEntity[]) — Special parts like bold, url, and mention.

MessageEntity

(click to see)
interface MessageEntity {
  type: string
  offset: number
  length: number
  language?: string
  custom_emoji_id?: string
  url?: string
  user?: {
    id: number
    is_bot: boolean
    first_name: string
    last_name?: string
    username?: string
    language_code?: string
    is_premium?: true
    added_to_attachment_menu?: true
  }
}

Represents a formatting part of the message like bold, url, or mention.

Type reference: https://github.com/grammyjs/types/blob/main/message.ts#L507-L562

Keywords

telegram

FAQs

Package last updated on 31 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.