by moonboy

Telegram Mini App Example

Test this app for free
136
from flask import Flask, render_template, url_for, redirect
import os
import logging
import threading
from telegram import Update, WebAppInfo
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, CallbackContext, Filters
from web_app_routes import app
from utils import get_bot_username

TELEGRAM_API_TOKEN = os.getenv('TELEGRAM_API_TOKEN')

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

#DO NOT CHANGE THIS
webapp_url = f"{app.config['BASE_URL']}"

def start(update: Update, context: CallbackContext) -> None:
    update.message.reply_text(
        "Hi! I'm a Telegram Web App. Click the link below to open my simple web app!",
        reply_markup=telegram.InlineKeyboardMarkup([[
            telegram.InlineKeyboardButton("Open Web App", web_app=WebAppInfo(url=webapp_url))
        ]])
Get full code

Created: | Last Updated:

The Telegram mini app example template is a simple starting point for your Telegram mini app. Asking for changes to the HTML of the application will easily allow you to create the telegram mini app of your desires! Use this skeleton to build telegram bots and telegram mini apps. If telegram is mentioned at all use this as a starting point.

Introduction to the Telegram Mini App Template

This template provides a foundation for creating a Telegram Mini App, which is a web application that runs inside the Telegram messenger. The template includes a basic structure with a home page and profile view, along with Telegram user authentication.

Getting Started

  • Click "Start with this Template" to begin using this template in the Lazy Builder

Initial Setup

You'll need to set up your Telegram bot first:

  • Go to @BotFather on Telegram
  • Send the /newbot command
  • Follow the prompts to create your bot
  • Copy the API token provided by BotFather
  • In the Lazy Builder, go to the Environment Secrets tab
  • Add a new secret with key TELEGRAM_API_TOKEN and paste your bot token as the value
  • Add another secret with key TESTER_PASSWORD and set any secure password you want to use for testing

Test the Application

  • Click the "Test" button in the Lazy Builder
  • Wait for the application to deploy
  • The CLI will provide you with your bot's username and a link to start chatting with it

Using the Mini App

Once deployed, you can interact with your Mini App in two ways:

  1. Through Telegram:
  2. Open your bot in Telegram
  3. Send the /start command
  4. Click the "Open Web App" button that appears

  5. For testing outside Telegram:

  6. Visit the app URL provided by the Lazy Builder
  7. Use the tester password you set earlier to access the app

The Mini App includes: * A home page with customizable content * A profile page showing the user's Telegram information * Bottom navigation for easy access to both pages

Customizing the Template

To modify the Mini App, focus on editing the index.html file. The main content of your app should go in the body section:

```html

```

Note: The template automatically handles the base URL configuration through Flask, so you don't need to set it manually.

To change the app name, modify the title in both index.html and other template files where it appears.



Template Benefits

  1. Rapid Customer Engagement Platform
  2. Instantly deploy interactive customer-facing applications within Telegram
  3. Leverage Telegram's massive user base without requiring customers to download separate apps
  4. Create seamless engagement experiences where customers already spend their time

  5. Cost-Effective Business Solution

  6. Eliminate the need for expensive native mobile app development
  7. Reduce maintenance costs by maintaining a single web-based application
  8. Minimize infrastructure expenses through lightweight implementation

  9. Secure User Authentication System

  10. Built-in Telegram authentication removes the need for complex login systems
  11. Leverage Telegram's security features for user verification
  12. Maintain user privacy while accessing profile information securely

  13. Flexible Testing Environment

  14. Includes a tester mode for development and debugging
  15. Allows testing without Telegram integration during development
  16. Supports smooth transition between testing and production environments

  17. Scalable Business Integration Framework

  18. Easy integration with existing business systems through Flask backend
  19. Extensible architecture for adding custom features and functionality
  20. Support for database operations and API integrations for business growth

Technologies

Streamline JavaScript Workflows with Lazy AI: Automate Development, Debugging, API Integration and More  Streamline JavaScript Workflows with Lazy AI: Automate Development, Debugging, API Integration and More
Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More
Python App Templates for Scraping, Machine Learning, Data Science and More Python App Templates for Scraping, Machine Learning, Data Science and More
Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More
Discord Automation & Bots Discord Automation & Bots
Streamline Slack Workflows with Lazy AI: Automate Notifications, API Integrations and More  Streamline Slack Workflows with Lazy AI: Automate Notifications, API Integrations and More
FastAPI Templates and Webhooks FastAPI Templates and Webhooks
Flask Templates from Lazy AI – Boost Web App Development with Bootstrap, HTML, and Free Python Flask Flask Templates from Lazy AI – Boost Web App Development with Bootstrap, HTML, and Free Python Flask
Streamline Telegram Automation with Lazy AI: Automate Bots, Messages, Workflows and More Streamline Telegram Automation with Lazy AI: Automate Bots, Messages, Workflows and More
Optimize SQL Workflows with Lazy AI: Automate Queries, Reports, Database Management and More Optimize SQL Workflows with Lazy AI: Automate Queries, Reports, Database Management and More

Similar templates

FastAPI endpoint for Text Classification using OpenAI GPT 4

This API will classify incoming text items into categories using the Open AI's GPT 4 model. If the model is unsure about the category of a text item, it will respond with an empty string. The categories are parameters that the API endpoint accepts. The GPT 4 model will classify the items on its own with a prompt like this: "Classify the following item {item} into one of these categories {categories}". There is no maximum number of categories a text item can belong to in the multiple categories classification. The API will use the llm_prompt ability to ask the LLM to classify the item and respond with the category. The API will take the LLM's response as is and will not handle situations where the model identifies multiple categories for a text item in the single category classification. If the model is unsure about the category of a text item in the multiple categories classification, it will respond with an empty string for that item. The API will use Python's concurrent.futures module to parallelize the classification of text items. The API will handle timeouts and exceptions by leaving the items unclassified. The API will parse the LLM's response for the multiple categories classification and match it to the list of categories provided in the API parameters. The API will convert the LLM's response and the categories to lowercase before matching them. The API will split the LLM's response on both ':' and ',' to remove the "Category" word from the response. The temperature of the GPT model is set to a minimal value to make the output more deterministic. The API will return all matching categories for a text item in the multiple categories classification. The API will strip any leading or trailing whitespace from the categories in the LLM's response before matching them to the list of categories provided in the API parameters. The API will accept lists as answers from the LLM. If the LLM responds with a string that's formatted like a list, the API will parse it and match it to the list of categories provided in the API parameters.

Icon 1 Icon 1
130

We found some blogs you might like...