Skip to main content

A lightweight interpreted DSL for Telegram Bots

Project description

Zyra

Zyra is a lightweight, interpreted Telegram Bot DSL (Domain Specific Language). It allows developers to create powerful Telegram bots using a simple, human-readable .zy syntax.

Installation

Lightweight (Core)

Perfect for Android/Termux and minimal environments.

pip install zyra-lang

Full (with AI and Watch mode)

pip install "zyra-lang[ai,watch]"

Quick Start

Create a new bot:

zyra new mybot
cd mybot

Run your bot directly:

zyra main.zy

Watch mode (requires zyra[watch]):

zyra watch main.zy

Syntax Guide

Basic Setup

bot "MyBot"
token env("BOT_TOKEN")

Commands

command "/start" {
    reply "Welcome to Zyra!"
}

Function Calls

Zyra supports modern function call syntax with positional and named arguments.

on command "/start" {
    // New function syntax
    reply("Welcome to Zyra!")
    
    // Support for named arguments
    reply("<b>Bold text</b>", mode="HTML")
    
    // Multiple arguments
    send(user.id, "Hello from Zyra")
}

// User-defined functions with named arguments
fn reward(uid, amount) {
    reply("User ${uid} rewarded with ${amount}")
}

on command "/reward" {
    reward(user.id, amount=10)
}

Backward Compatibility: Old syntax still works perfectly:

reply "Traditional style"
send user.id "Traditional send"

Control Flow

Zyra supports block and one-line if/elif/else syntax.

on command "/start" {
    // One-line if
    if referrer => reply("Invited by ${referrer}")

    // Complex if-elif-else chain
    if user.id == 123 {
        reply("Hello Owner")
    }
    elif user.id == 456 => reply("Hello Admin")
    else {
        reply("Hello User")
    }
}
else {
    reply("Hello User")
}

}


### Buttons
Zyra makes Telegram buttons simple and readable.

#### Reply Keyboard
```zyra
on command "/start" {
    reply("Choose an option:", buttons=[["Profile"], ["Wallet"]])
}

Inline Buttons & Callbacks

on command "/menu" {
    reply("Menu:", inline=[
        ["Profile", "profile"],
        ["Join Channel", url="https://t.me/example"]
    ])
}

on callback "profile" => reply("Your Profile")

Alerts & Notifications

Feedback for callback buttons:

on callback "update" {
    alert("Profile updated!", mode="silent") // Small top notification
}

on callback "withdraw" {
    alert("Insufficient funds!", mode="alert") // Centered popup dialog
}

Multi-row Layout

reply("Multi-row:", inline=[
    [["Row 1 - A", "a"], ["Row 1 - B", "b"]],
    [["Row 2 - C", "c"]]
])

Databases (SQLite)

table Users {
    id integer primary
    name text
}

command "/register" {
    insert Users {
        id = user.id
        name = user.first_name
    }
    reply "Registered!"
}

Referral System

Zyra has a first-class referral system. It automatically parses Telegram start payloads (e.g., /start 12345).

on command "/start" {
    if referrer {
        // User joined via referral link
        send(referrer) "Someone joined using your link!"
        reply "Welcome! You were referred by ${referrer}"
    } else {
        reply "Welcome! You joined directly."
    }
}

Features:

  • Automatic Parsing: Extracts IDs from /start <payload>.
  • Validation: Payload must be an integer and exactly 10 characters long.
  • Built-in Variables: Access via referrer or user.referrer.
  • Truthiness: if referrer works for null-checking.
  • Null Comparison: if referrer == null or if referrer != null.
  • Self-referral Protection: Users cannot refer themselves.

AI Features (requires zyra[ai])

ai {
    provider "openai"
    model "gpt-4"
}

command "/ask" {
    ai_reply message.text
}

Architecture

.zy source -> Lexer -> Parser -> AST -> Interpreter (Runtime)

Zyra executes your script directly without generating intermediate Python files, keeping your project clean and fast.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zyra_lang-0.2.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zyra_lang-0.2.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file zyra_lang-0.2.0.tar.gz.

File metadata

  • Download URL: zyra_lang-0.2.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for zyra_lang-0.2.0.tar.gz
Algorithm Hash digest
SHA256 362a7a3f8debf43e501073adc863123027ee56c3d0135c98eadadca63676a1f2
MD5 b98605fe641206359d6d75b2ff75507e
BLAKE2b-256 c5afa1489221aab4962da2dd598b5281c6901027ae208eb4c152cdc4aa292e59

See more details on using hashes here.

File details

Details for the file zyra_lang-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: zyra_lang-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for zyra_lang-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78b22117e795e52afb661325fd96494b30399826c3723c7703a74207eb5f5d6a
MD5 77792d9303b8d1e0096c42f7e63f7b6e
BLAKE2b-256 319bd65d5f63a3655eb18dae23405dbef1995adff6343377ef593505e32b0e3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page