Skip to content
/ tgx Public

✨ JSX runtime for composing Telegram messages.

License

Notifications You must be signed in to change notification settings

grom-dev/tgx

Repository files navigation

tgx

npm jsr

JSX runtime for composing Telegram messages.

Installation

# Using npm
npm install @grom.js/tgx

# Using JSR
deno add jsr:@grom/tgx

Then in your tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@grom.js/tgx" // "@grom/tgx" for JSR
    // ...
  }
}

Examples

Usage with grammY:

import { Bot } from 'grammy'
import { renderHtml } from '@grom.js/tgx'

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

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

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

bot.start()

Usage with effect-tg:

import { Content, Dialog, Send, Text } from 'effect-tg'

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

const greet = (id, name) => Send.sendMessage({
  dialog: Dialog.user(id),
  content: Content.text(Text.tgx(<Greeting name={name} />))
})

License

MIT

About

✨ JSX runtime for composing Telegram messages.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •