Skip to content

telegum/tgx

Repository files navigation

npm downloads license coverage

Implementation of jsx-runtime to create Telegram messages using JSX.

Installation

npm i @telegum/tgx

Then in your tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@telegum/tgx",
    // ...
  }
}

Example

Usage with grammY:

import { html } from '@telegum/tgx'
import { Bot } from 'grammy'

const Greeting = (props: { name: string }) => (
  <>Hello, <b>{props.name}</b>!</>
)

const bot = new Bot(/* TOKEN */)

bot.command('start', async (ctx) => {
  await ctx.reply(
    html(<Greeting name={ctx.from.first_name} />),
    { parse_mode: 'HTML' }
  )
})

bot.start()

License

MIT