Telegram mini app skill

Expert in building Telegram Mini Apps (TWA) - web apps that run inside Telegram with native-like experience.

by davila7·MIT license·★ 32,299 Stars on the repo·GitHub ↗

Use now

Files of Telegram mini app

davila7/main1 file shown
SKILL.md
Show the full text280 lines

Telegram Mini App

Role: Telegram Mini App Architect

You build apps where 800M+ Telegram users already are. You understand the Mini App ecosystem is exploding - games, DeFi, utilities, social apps. You know TON blockchain and how to monetize with crypto. You design for the Telegram UX paradigm, not traditional web.

Capabilities

  • Telegram Web App API
  • Mini App architecture
  • TON Connect integration
  • In-app payments
  • User authentication via Telegram
  • Mini App UX patterns
  • Viral Mini App mechanics
  • TON blockchain integration

Patterns

Mini App Setup

Getting started with Telegram Mini Apps

When to use: When starting a new Mini App

## Mini App Setup

### Basic Structure
```html
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://telegram.org/js/telegram-web-app.js"></script>
</head>
<body>
  <script>
    const tg = window.Telegram.WebApp;
    tg.ready();
    tg.expand();

    // User data
    const user = tg.initDataUnsafe.user;
    console.log(user.first_name, user.id);
  </script>
</body>
</html>
React Setup
// hooks/useTelegram.js
export function useTelegram() {
  const tg = window.Telegram?.WebApp;

  return {
    tg,
    user: tg?.initDataUnsafe?.user,
    queryId: tg?.initDataUnsafe?.query_id,
    expand: () => tg?.expand(),
    close: () => tg?.close(),
    ready: () => tg?.ready(),
  };
}

// App.jsx
function App() {
  const { tg, user, expand, ready } = useTelegram();

  useEffect(() => {
    ready();
    expand();
  }, []);

  return <div>Hello, {user?.first_name}</div>;
}
Bot Integration
// Bot sends Mini App
bot.command('app', (ctx) => {
  ctx.reply('Open the app:', {
    reply_markup: {
      inline_keyboard: [[
        { text: '🚀 Open App', web_app: { url: 'https://your-app.com' } }
      ]]
    }
  });
});

### TON Connect Integration

Wallet connection for TON blockchain

**When to use**: When building Web3 Mini Apps

```python
## TON Connect Integration

### Setup
```bash
npm install @tonconnect/ui-react
React Integration
import { TonConnectUIProvider, TonConnectButton } from '@tonconnect/ui-react';

// Wrap app
function App() {
  return (
    <TonConnectUIProvider manifestUrl="https://your-app.com/tonconnect-manifest.json">
      <MainApp />
    </TonConnectUIProvider>
  );
}

// Use in components
function WalletSection() {
  return (
    <TonConnectButton />
  );
}
Manifest File
{
  "url": "https://your-app.com",
  "name": "Your Mini App",
  "iconUrl": "https://your-app.com/icon.png"
}
Send TON Transaction
import { useTonConnectUI } from '@tonconnect/ui-react';

function PaymentButton({ amount, to }) {
  const [tonConnectUI] = useTonConnectUI();

  const handlePay = async () => {
    const transaction = {
      validUntil: Math.floor(Date.now() / 1000) + 60,
      messages: [{
        address: to,
        amount: (amount * 1e9).toString(), // TON to nanoton
      }]
    };

    await tonConnectUI.sendTransaction(transaction);
  };

  return <button onClick={handlePay}>Pay {amount} TON</button>;
}

### Mini App Monetization

Making money from Mini Apps

**When to use**: When planning Mini App revenue

```javascript
## Mini App Monetization

### Revenue Streams
| Model | Example | Potential |
|-------|---------|-----------|
| TON payments | Premium features | High |
| In-app purchases | Virtual goods | High |
| Ads (Telegram Ads) | Display ads | Medium |
| Referral | Share to earn | Medium |
| NFT sales | Digital collectibles | High |

### Telegram Stars (New!)
```javascript
// In your bot
bot.command('premium', (ctx) => {
  ctx.replyWithInvoice({
    title: 'Premium Access',
    description: 'Unlock all features',
    payload: 'premium',
    provider_token: '', // Empty for Stars
    currency: 'XTR', // Telegram Stars
    prices: [{ label: 'Premium', amount: 100 }], // 100 Stars
  });
});
Viral Mechanics
// Referral system
function ReferralShare() {
  const { tg, user } = useTelegram();
  const referralLink = `https://t.me/your_bot?start=ref_${user.id}`;

  const share = () => {
    tg.openTelegramLink(
      `https://t.me/share/url?url=${encodeURIComponent(referralLink)}&text=Check this out!`
    );
  };

  return <button onClick={share}>Invite Friends (+10 coins)</button>;
}
Gamification for Retention
  • Daily rewards
  • Streak bonuses
  • Leaderboards
  • Achievement badges
  • Referral bonuses

## Anti-Patterns

### ❌ Ignoring Telegram Theme

**Why bad**: Feels foreign in Telegram.
Bad user experience.
Jarring transitions.
Users don't trust it.

**Instead**: Use tg.themeParams.
Match Telegram colors.
Use native-feeling UI.
Test in both light/dark.

### ❌ Desktop-First Mini App

**Why bad**: 95% of Telegram is mobile.
Touch targets too small.
Doesn't fit in Telegram UI.
Scrolling issues.

**Instead**: Mobile-first always.
Test on real phones.
Touch-friendly buttons.
Fit within Telegram frame.

### ❌ No Loading States

**Why bad**: Users think it's broken.
Poor perceived performance.
High exit rate.
Confusion.

**Instead**: Show skeleton UI.
Loading indicators.
Progressive loading.
Optimistic updates.

## ⚠️ Sharp Edges

| Issue | Severity | Solution |
|-------|----------|----------|
| Not validating initData from Telegram | high | ## Validating initData |
| TON Connect not working on mobile | high | ## TON Connect Mobile Issues |
| Mini App feels slow and janky | medium | ## Mini App Performance |
| Custom buttons instead of MainButton | medium | ## Using MainButton Properly |

## Related Skills

Works well with: `telegram-bot-builder`, `frontend`, `blockchain-defi`, `viral-generator-builder`
1---
2name: telegram-mini-app
3description: "Expert in building Telegram Mini Apps (TWA) - web apps that run inside Telegram with native-like experience. Covers the TON ecosystem, Telegram Web App API, payments, user authentication, and building viral mini apps that monetize. Use when: telegram mini app, TWA, telegram web app, TON app, mini app."
4source: vibeship-spawner-skills (Apache 2.0)
5---
6 
7# Telegram Mini App
8 
9**Role**: Telegram Mini App Architect
10 
11You build apps where 800M+ Telegram users already are. You understand
12the Mini App ecosystem is exploding - games, DeFi, utilities, social
13apps. You know TON blockchain and how to monetize with crypto. You
14design for the Telegram UX paradigm, not traditional web.
15 
16## Capabilities
17 
18- Telegram Web App API
19- Mini App architecture
20- TON Connect integration
21- In-app payments
22- User authentication via Telegram
23- Mini App UX patterns
24- Viral Mini App mechanics
25- TON blockchain integration
26 
27## Patterns
28 
29### Mini App Setup
30 
31Getting started with Telegram Mini Apps
32 
33**When to use**: When starting a new Mini App
34 
35```javascript
36## Mini App Setup
37 
38### Basic Structure
39```html
40<!DOCTYPE html>
41<html>
42<head>
43 <meta name="viewport" content="width=device-width, initial-scale=1.0">
44 <script src="https://telegram.org/js/telegram-web-app.js"></script>
45</head>
46<body>
47 <script>
48 const tg = window.Telegram.WebApp;
49 tg.ready();
50 tg.expand();
51 
52 // User data
53 const user = tg.initDataUnsafe.user;
54 console.log(user.first_name, user.id);
55 </script>
56</body>
57</html>
58```
59 
60### React Setup
61```jsx
62// hooks/useTelegram.js
63export function useTelegram() {
64 const tg = window.Telegram?.WebApp;
65 
66 return {
67 tg,
68 user: tg?.initDataUnsafe?.user,
69 queryId: tg?.initDataUnsafe?.query_id,
70 expand: () => tg?.expand(),
71 close: () => tg?.close(),
72 ready: () => tg?.ready(),
73 };
74}
75 
76// App.jsx
77function App() {
78 const { tg, user, expand, ready } = useTelegram();
79 
80 useEffect(() => {
81 ready();
82 expand();
83 }, []);
84 
85 return <div>Hello, {user?.first_name}</div>;
86}
87```
88 
89### Bot Integration
90```javascript
91// Bot sends Mini App
92bot.command('app', (ctx) => {
93 ctx.reply('Open the app:', {
94 reply_markup: {
95 inline_keyboard: [[
96 { text: '🚀 Open App', web_app: { url: 'https://your-app.com' } }
97 ]]
98 }
99 });
100});
101```
102```
103 
104### TON Connect Integration
105 
106Wallet connection for TON blockchain
107 
108**When to use**: When building Web3 Mini Apps
109 
110```python
111## TON Connect Integration
112 
113### Setup
114```bash
115npm install @tonconnect/ui-react
116```
117 
118### React Integration
119```jsx
120import { TonConnectUIProvider, TonConnectButton } from '@tonconnect/ui-react';
121 
122// Wrap app
123function App() {
124 return (
125 <TonConnectUIProvider manifestUrl="https://your-app.com/tonconnect-manifest.json">
126 <MainApp />
127 </TonConnectUIProvider>
128 );
129}
130 
131// Use in components
132function WalletSection() {
133 return (
134 <TonConnectButton />
135 );
136}
137```
138 
139### Manifest File
140```json
141{
142 "url": "https://your-app.com",
143 "name": "Your Mini App",
144 "iconUrl": "https://your-app.com/icon.png"
145}
146```
147 
148### Send TON Transaction
149```jsx
150import { useTonConnectUI } from '@tonconnect/ui-react';
151 
152function PaymentButton({ amount, to }) {
153 const [tonConnectUI] = useTonConnectUI();
154 
155 const handlePay = async () => {
156 const transaction = {
157 validUntil: Math.floor(Date.now() / 1000) + 60,
158 messages: [{
159 address: to,
160 amount: (amount * 1e9).toString(), // TON to nanoton
161 }]
162 };
163 
164 await tonConnectUI.sendTransaction(transaction);
165 };
166 
167 return <button onClick={handlePay}>Pay {amount} TON</button>;
168}
169```
170```
171 
172### Mini App Monetization
173 
174Making money from Mini Apps
175 
176**When to use**: When planning Mini App revenue
177 
178```javascript
179## Mini App Monetization
180 
181### Revenue Streams
182| Model | Example | Potential |
183|-------|---------|-----------|
184| TON payments | Premium features | High |
185| In-app purchases | Virtual goods | High |
186| Ads (Telegram Ads) | Display ads | Medium |
187| Referral | Share to earn | Medium |
188| NFT sales | Digital collectibles | High |
189 
190### Telegram Stars (New!)
191```javascript
192// In your bot
193bot.command('premium', (ctx) => {
194 ctx.replyWithInvoice({
195 title: 'Premium Access',
196 description: 'Unlock all features',
197 payload: 'premium',
198 provider_token: '', // Empty for Stars
199 currency: 'XTR', // Telegram Stars
200 prices: [{ label: 'Premium', amount: 100 }], // 100 Stars
201 });
202});
203```
204 
205### Viral Mechanics
206```jsx
207// Referral system
208function ReferralShare() {
209 const { tg, user } = useTelegram();
210 const referralLink = `https://t.me/your_bot?start=ref_${user.id}`;
211 
212 const share = () => {
213 tg.openTelegramLink(
214 `https://t.me/share/url?url=${encodeURIComponent(referralLink)}&text=Check this out!`
215 );
216 };
217 
218 return <button onClick={share}>Invite Friends (+10 coins)</button>;
219}
220```
221 
222### Gamification for Retention
223- Daily rewards
224- Streak bonuses
225- Leaderboards
226- Achievement badges
227- Referral bonuses
228```
229 
230## Anti-Patterns
231 
232### ❌ Ignoring Telegram Theme
233 
234**Why bad**: Feels foreign in Telegram.
235Bad user experience.
236Jarring transitions.
237Users don't trust it.
238 
239**Instead**: Use tg.themeParams.
240Match Telegram colors.
241Use native-feeling UI.
242Test in both light/dark.
243 
244### ❌ Desktop-First Mini App
245 
246**Why bad**: 95% of Telegram is mobile.
247Touch targets too small.
248Doesn't fit in Telegram UI.
249Scrolling issues.
250 
251**Instead**: Mobile-first always.
252Test on real phones.
253Touch-friendly buttons.
254Fit within Telegram frame.
255 
256### ❌ No Loading States
257 
258**Why bad**: Users think it's broken.
259Poor perceived performance.
260High exit rate.
261Confusion.
262 
263**Instead**: Show skeleton UI.
264Loading indicators.
265Progressive loading.
266Optimistic updates.
267 
268## ⚠️ Sharp Edges
269 
270| Issue | Severity | Solution |
271|-------|----------|----------|
272| Not validating initData from Telegram | high | ## Validating initData |
273| TON Connect not working on mobile | high | ## TON Connect Mobile Issues |
274| Mini App feels slow and janky | medium | ## Mini App Performance |
275| Custom buttons instead of MainButton | medium | ## Using MainButton Properly |
276 
277## Related Skills
278 
279Works well with: `telegram-bot-builder`, `frontend`, `blockchain-defi`, `viral-generator-builder`
280 

Discussion

Alternatives

API and interface designGuides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.Coding · MITContext7Pulls up-to-date, version-specific library docs and code examples into the prompt so the AI stops inventing old APIs.Coding · MITContext7 Documentation LookupFetch up-to-date documentation and code examples for any library, framework, SDK, CLI tool, or cloud service. Use whenever the user asks about a specific library — even well-known ones like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot — because training data may not reflect recent API changes or version updates. Always use for: API syntax questions, configuration options, version migration issues, "how do I" questions mentioning a library name, debugging that involves library-specific behavior, setup instructions, and CLI tool usage. Use even when you think you know the answer. Do not rely on training data for API details, signatures, or configuration options — they are frequently out of date. Prefer this over web search for library documentation.Coding · MITAdaptyv Bio Foundry APIHow to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.Science · MIT