### Account.start_bot usage example Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Example of starting a bot with start_bot, including the expected JSON output. ```python result = Account.start_bot("1234567") bot.sendMessage(f"Start result: {result['result']}") ``` ```json { "ok": true, "result": "Bot started successfully" } ``` -------------------------------- ### Example /start command in TPY Source: https://help.telebotcreator.com/guides-and-examples/frequently-asked-questions-faqs.md A simple TPY command that sends a welcome message when the /start command is triggered. Save the command, ensure the bot is started, and test by messaging the bot on Telegram. ```python # Example /start command bot.sendMessage("Welcome to my bot! Type /help to see available commands.") ``` -------------------------------- ### Multi-Step User Interactions with handleNextCommand Source: https://help.telebotcreator.com/core-reference/bot-features-and-functionalities.md Guide users through a sequence of steps using Bot.handleNextCommand. The example collects a name, then an email, and confirms. ```python bot.sendMessage("What is your name?") Bot.handleNextCommand("get_name") ``` ```python name = msg User.saveData("name", name) bot.sendMessage(f"Thanks, {name}! Now, what is your email?") Bot.handleNextCommand("get_email") ``` ```python email = msg User.saveData("email", email) bot.sendMessage("Your details have been saved. Thank you!") ``` -------------------------------- ### start Source: https://help.telebotcreator.com/core-reference/tpy-language-reference Starts a bot if conditions like sufficient points are met. ```APIDOC ## start ### Description Starts a bot if conditions like sufficient points are met. ### Arguments - **bot_id** (Required) - The ID of the bot to start. - **api_key** (Required) - The API key for the bot. ``` -------------------------------- ### fetchAllResourcesOfUser usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of fetching all resources for a user in JSON format and sending the file via bot.sendDocument. ```python resources_file = admin.fetchAllResourcesOfUser("12345678", "json") bot.sendDocument(resources_file) ``` -------------------------------- ### libs.Coinbase Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Automate payment transfers using Coinbase. The example shows setting API keys, creating a client, and getting balances. ```APIDOC ## libs.Coinbase ### Description Automate payment transfers using Coinbase. ### Methods - **setKeys(api_key, api_secret)** - Sets the API key and secret. - **post()** - Creates a client. - **getBalance()** - Returns wallet balances. ### Example ```python libs.Coinbase.setKeys("YOUR_API_KEY", "YOUR_API_SECRET") client = libs.Coinbase.post() balances = client.getBalance() bot.sendMessage(f"Wallet balances: {balances}") ``` ``` -------------------------------- ### TON Connect Integration Example Source: https://help.telebotcreator.com/libraries-and-integrations/ton-library-documentation.md Two-step example: initialize a TON Connect session and check its connection status. Uses create_ton_connect_session and verify_ton_connect_session. ```python # Step 1: Initialize wallet connection def handle_connect_wallet(message): user_id = str(message.from_user.id) session = libs.TonLib.create_ton_connect_session(user_id) # Store session_id for later verification db.set_user_data(user_id, "ton_session_id", session["session_id"]) # Send connection link to user bot.send_message( chat_id=message.chat.id, text=f"Connect your TON wallet by opening this link:\n{session['connect_url']}" ) # Step 2: Check wallet connection status def handle_check_connection(message): user_id = str(message.from_user.id) session_id = db.get_user_data(user_id, "ton_session_id") if not session_id: return bot.send_message(message.chat.id, "You haven't started a connection yet") status = libs.TonLib.verify_ton_connect_session(session_id) if status["status"] == "connected": bot.send_message( chat_id=message.chat.id, text=f"Wallet connected: {status['wallet_address']}" ) else: bot.send_message( chat_id=message.chat.id, text="Wallet not connected yet. Try again later." ) ``` -------------------------------- ### Bot.getAllData usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of retrieving all global data entries matching 'config' and sending them as a document. ```python all_configs = Bot.getAllData("config") bot.sendDocument(all_configs) ``` -------------------------------- ### Account.info usage example Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Example of retrieving account information with info, including the expected JSON output. ```python info = Account.info() bot.sendMessage(f"Account plan: {info.plan}, Points left: {info.points_left}") ``` ```json { "email": "ACCOUNT_EMAIL", "plan": "Premium", "points_resetAt": "2023-06-01 00:00:00", "points_left": 8500, "ep": 1000 } ``` -------------------------------- ### Example usage of TPY bot methods Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Shows how to transfer a bot to another account and start it, start a broadcast, and generate a unique ID using the TPY bot class. ```python # Transfer a bot to another account and start it bot.Transfer(email="NEW_OWNER_EMAIL", bot_id="12345", run_now=True) # Start a broadcast bot.broadcast(command="send_newsletter", function="broadcast_news") # Generate a unique ID unique_id = bot.genId() ``` -------------------------------- ### Command Example: start_command Source: https://help.telebotcreator.com/guides-and-examples/glossary-and-key-concepts Example of defining a command function in TPY. ```python def start_command(): bot.sendMessage("Hello! This is the start command.") ``` -------------------------------- ### Bot.getDataFile usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of retrieving a global data file named 'config' and sending it as a document. ```python config_file = Bot.getDataFile("config") bot.sendDocument(config_file) ``` -------------------------------- ### Account.getAllData usage example Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Example of retrieving all account data with getAllData, including the expected JSON output format. ```python data_file = Account.getAllData("config_") bot.sendDocument(data_file) ``` ```text # Returns a file-like object containing JSON data in the format: # [ # { # "name": "config_user", # "data": {"setting1": "value1", "setting2": "value2"}, # "time": "2023-05-15 14:30:22" # }, # { # "name": "config_bot", # "data": {"timeout": 30, "retry": true}, # "time": "2023-05-16 09:15:43" # } # ] ``` -------------------------------- ### Coinpayments: Set keys and get client Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Example usage of libs.Coinpayments: setKeys stores public and private keys, post returns a configured CoinPaymentsAPI client. The client is from the external 'coinpayments' package; its methods are defined by that library. ```python libs.Coinpayments.setKeys("YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY") client = libs.Coinpayments.post() # client is a CoinPaymentsAPI instance — call its methods as documented by CoinPayments ``` -------------------------------- ### reward_ad with then command Source: https://help.telebotcreator.com/libraries-and-integrations/monetization.md Shows how to use `libs.tbcads.reward_ad()` with a `then` command. The `then` command must start with `claim()` to verify the ad view; otherwise users could type the command name directly and get the reward without watching. ```python libs.tbcads.reward_ad("Watch to unlock the file", then="/sendfile") ``` ```python # /sendfile if not libs.tbcads.claim(): raise ReturnCommand # not a verified ad view — stop here bot.sendDocument(FILE_ID, caption="Here is your file 📄") ``` -------------------------------- ### Example: User.getAllData with bot.sendDocument Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example usage of User.getAllData to retrieve all data matching 'settings' and send it via bot.sendDocument. ```python data_file = User.getAllData("settings") bot.sendDocument(data_file) ``` -------------------------------- ### Account.start_bot Source: https://help.telebotcreator.com/core-reference/advanced-features.md Starts a bot you own. ```APIDOC ## Account.start_bot ### Description Starts a bot you own. ### Method Account.start_bot ### Parameters - **botid** (string) - Required - The ID of the bot to start. ### Request Example ```python Account.start_bot(botid) ``` ### Response Returns a dict shaped like `{"ok": True/False, "result": ...}`. ``` -------------------------------- ### Account.getData usage example Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Example of retrieving account data with getData, including the expected JSON output. ```python settings = Account.getData("global_settings") if settings: bot.sendMessage(f"Theme: {settings['theme']}") else: bot.sendMessage("No settings found") ``` ```json { "theme": "dark", "notifications": true } ``` -------------------------------- ### Account.start_bot(botid) Source: https://help.telebotcreator.com/core-reference/tpy-method-index Starts a bot. This method starts the bot with the given bot ID. ```APIDOC ## Account.start_bot(botid) ### Description Starts a bot. ### Method Account.start_bot ### Parameters - **botid** (string) - Required - The bot identifier. ### Response No explicit response documented. ``` -------------------------------- ### Bot.getBotUsersFile usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of retrieving bot users as a CSV file including creation dates, then sending it as a document. ```python users_file = Bot.getBotUsersFile(output_format="csv", include_creation_date=True) bot.sendDocument(users_file) ``` -------------------------------- ### Set Up Coinbase Client Source: https://help.telebotcreator.com/guides-and-examples/real-world-use-cases.md Configures the Coinbase client with API keys using libs.Coinbase.setKeys and creates a client instance. ```python libs.Coinbase.setKeys("your_api_key", "your_api_secret") client = libs.Coinbase.post() ``` -------------------------------- ### User class data management example Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Example usage of User class methods: saveData, getData, getDataFile, and getAllDataOfUser. Demonstrates saving a profile, retrieving it, getting it as a file, and getting all data for a user. ```python # Save user data User.saveData("profile", {"name": "Alice", "age": 30}) # Get user data profile = User.getData("profile") bot.sendMessage(f"User profile: {profile}") # Get user data as a file profile_file = User.getDataFile("profile") bot.sendDocument(profile_file) # Get all data for a specific user all_user_data = User.getAllDataOfUser("12345678") bot.sendDocument(all_user_data) ``` -------------------------------- ### libs.Coinbase setKeys and post example Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Sets Coinbase API keys and initializes a Coinbase client using libs.Coinbase.setKeys and libs.Coinbase.post(). ```python libs.Coinbase.setKeys("your_api_key", "your_secret_key") client = libs.Coinbase.post() ``` -------------------------------- ### TPY Examples Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Examples of using TPY to send messages, get user points, and schedule reminders. ```APIDOC ## TPY Examples ### Description Examples of using TPY to send messages, get user points, and schedule reminders. ### Example 1: Sending a Welcome Message ```python bot.sendMessage("Welcome to the bot!") ``` ### Example 2: Get User Points ```python points = left_points bot.sendMessage(f"You have {points} points remaining.") ``` ### Example 3: Scheduling a Reminder In the /set_reminder command: ```python bot.sendMessage("Reminder set for 5 seconds later.") bot.runCommandAfter(5, "send_reminder") ``` In the send_reminder command: ```python bot.sendMessage("This is your reminder!") ``` ``` -------------------------------- ### HTTP requests with built-in HTTP module Source: https://help.telebotcreator.com/guides-and-examples/frequently-asked-questions-faqs.md Shows GET and POST requests using the built-in HTTP module (recommended since 4.9.0). The GET example parses JSON and sends the result; the POST example sends a JSON body. ```python # Using built-in HTTP (recommended since 4.9.0) response = HTTP.get("https://api.example.com/data") data = response.json() bot.sendMessage(f"Result: {data}") # POST request with JSON body response = HTTP.post("https://api.example.com/submit", json={"key": "value"}) ``` -------------------------------- ### Basic /start command Source: https://help.telebotcreator.com/getting-started/command-in-tpy.md Sends a welcome message when the /start command is triggered. ```python bot.sendMessage("Welcome to my bot! Use /help to see available commands.") ``` -------------------------------- ### Get current UTC time with libs.DateAndTime.utcnow() Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Use libs.DateAndTime.utcnow() to get the current UTC date and time. The example sends the time via bot.sendMessage. ```python current_time = libs.DateAndTime.utcnow() bot.sendMessage(f"The current UTC time is: {current_time}") ``` -------------------------------- ### runCommand example Source: https://help.telebotcreator.com/getting-started/command-in-tpy.md Immediately triggers another command, here redirecting to /help. ```python bot.sendMessage("Redirecting you to the /help command...") bot.runCommand("help") ``` -------------------------------- ### checkTONTransaction(address, api_key=None, endpoint=None, limit=10) - Get recent transactions Source: https://help.telebotcreator.com/libraries-and-integrations/ton-library-documentation.md Gets the recent transactions for an address. The example iterates over transactions and processes incoming ones. ```python transactions = libs.TonLib.checkTONTransaction("EQD...") for tx in transactions: if tx["type"] == "incoming": from_address = tx["from"] amount = tx["amount"] # Process the incoming transaction... ``` -------------------------------- ### Bot.start(bot_id=None, api_key=None) Source: https://help.telebotcreator.com/core-reference/tpy-method-index.md Starts the bot. Optionally specify bot_id and api_key. ```APIDOC ## Bot.start(bot_id=None, api_key=None) ### Description Starts the bot. ### Method start ### Parameters - **bot_id** (string) - Optional - The bot ID. - **api_key** (string) - Optional - The API key. ``` -------------------------------- ### Restart a bot with Account.restart_bot Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Restarts a bot by stopping and then starting it. The example calls Account.restart_bot with a bot ID and sends the result via bot.sendMessage. ```python Account.restart_bot(botid) ``` ```python result = Account.restart_bot("1234567") bot.sendMessage(f"Restart result: {result['result']}") ``` ```json { "ok": true, "result": "Bot started successfully" } ``` -------------------------------- ### TON Library Example: Generate Wallet, Check Balance, Send TON Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Demonstrates using TonLib to generate a wallet, retrieve its address, check the TON balance, and send TON with a comment. The example shows the basic workflow for wallet creation and transactions. ```python # Generate a wallet wallet = TonLib.generateWallet() address = wallet["address"] # Check balance balance = TonLib.getBalance(address) bot.sendMessage(f"Balance: {balance} TON") # Send TON TonLib.sendTON( to_address="EQD...", amount=0.1, comment="Test payment" ) ``` -------------------------------- ### Get command info with Account.get_command_info Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Retrieves detailed information about a specific command. Requires botid and command name. The example sends the command code from the result. ```python Account.get_command_info(botid, command) ``` ```python info = Account.get_command_info("1234567", "/hello") if info["ok"]: cmd_info = info["result"] bot.sendMessage(f"Command code: {cmd_info['code']}") ``` ```json { "ok": true, "result": { "command": "/hello", "code": "bot.sendMessage('Hello, world!')", "code_length": 31, "stats": { "executions": 342, "last_executed": "2023-05-15T14:30:22Z" } } } ``` -------------------------------- ### Add a welcome message with /start command Source: https://help.telebotcreator.com/guides-and-examples/chatgpt-telegram-bot.md Sends a greeting when the user starts the bot. ```python # Command: /start bot.sendMessage("Hi! I am an AI assistant. Ask me anything.") ``` -------------------------------- ### Get command list with Account.get_command_list Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Retrieves a list of all commands for a bot. Requires botid. The example iterates over the result and sends each command's name and has_code flag. ```python Account.get_command_list(botid) ``` ```python commands = Account.get_command_list("1234567") if commands["ok"] and commands["result"]: for cmd in commands["result"]: bot.sendMessage(f"Command: {cmd['command']}, Has code: {cmd['has_code']}") ``` ```json { "ok": true, "result": [ { "command": "/start", "code_length": 256, "has_code": true }, { "command": "/help", "code_length": 128, "has_code": true }, { "command": "/settings", "code_length": 512, "has_code": true } ] } ``` -------------------------------- ### Account.get_bot_info - Get bot details Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Retrieves detailed information about a specific bot. Requires the bot ID. The example sends a message with the bot's name, user count, and command count. ```python Account.get_bot_info(botid) ``` ```python info = Account.get_bot_info("1234567") if info["ok"]: bot_info = info["result"] bot.sendMessage(f"Bot {bot_info['name']}: {bot_info['user_count']} users, {bot_info['command_count']} commands") ``` ```json { "ok": true, "result": { "botid": "1234567", "name": "Support Bot", "username": "support_bot", "status": "working", "creation_date": "14:30:22 01:05:2023", "has_token": true, "command_count": 12, "user_count": 278, "points_used": 5432 } } ``` -------------------------------- ### Command Chaining - Start the Workflow Source: https://help.telebotcreator.com/core-reference/advanced-features.md First step of a multi-step registration workflow: sends a welcome message and sets the next command to 'get_name'. ```python bot.sendMessage("Welcome! Let's start with your name.") Bot.handleNextCommand("get_name") ``` -------------------------------- ### Using libs.Resources.userRes to manage points Source: https://help.telebotcreator.com/core-reference/advanced-features.md Shows how to create a per-user resource named 'points', add and cut values, and send the balance. Also demonstrates fetching the top 5 leaderboard entries using getAllData(5). ```python points = libs.Resources.userRes("points", u) points.add(10) points.cut(3) bot.sendMessage(f"Balance: {points.value()}") leaderboard = libs.Resources.userRes("points").getAllData(5) # top 5 ``` -------------------------------- ### libs.Coinbase.post Source: https://help.telebotcreator.com/core-reference/tpy-language-reference Initializes a Coinbase client. ```APIDOC ## libs.Coinbase.post ### Description Initializes a Coinbase client. ### Method post ### Parameters - **api_key** (Optional) - The API key. - **secret** (Optional) - The API secret. ### Request Example ``` libs.Coinbase.post(api_key=None, secret=None) ``` ### Response No response details provided. ``` -------------------------------- ### get_stats: Retrieve comprehensive account-level statistics Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Calls Account.get_stats() to get account-level statistics. The example checks the 'ok' field and sends a message with total bots and users. The output includes plan, points, and bot/user summaries. ```python Account.get_stats() ``` ```python stats = Account.get_stats() if stats["ok"]: account_stats = stats["result"] bot.sendMessage(f"Account stats: {account_stats['bots']['total']} bots, {account_stats['users']['total']} users") ``` ```json { "ok": true, "result": { "email": "ACCOUNT_EMAIL", "plan": "Premium", "points_left": 8500, "points_used": 23450, "points_reset_at": "2023-06-01", "account_created": "2022-11-15 09:30:45", "bots": { "total": 5, "botids": ["1234567", "7654321", "2345678", "8765432", "3456789"] }, "users": { "total": 2584, "active_30d": 943 }, "commands": { "total": 68 } } } ``` -------------------------------- ### Check caller IP and implement whitelist with options.ip Source: https://help.telebotcreator.com/changelog/version-7.1.2-update.md Use options.ip to get the client's IP address. The example shows sending a message with the caller IP and a whitelist check that returns a forbidden response if the IP is not allowed. ```python # Check caller IP caller_ip = options.ip bot.sendMessage(f"Request from: {caller_ip}") # IP whitelist example ALLOWED_IPS = ["212.47.77.122", "1.2.3.4"] if options.ip not in ALLOWED_IPS: Api.setWebhookResult({"ok": False, "error": "Forbidden"}) returnCommand() ``` -------------------------------- ### Initialize Oxapay client with libs.Oxapay.post() Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Use libs.Oxapay.post() with your merchant API key to initialize the Oxapay client. The example sends a confirmation message. ```python client = libs.Oxapay.post("your_merchant_api_key") bot.sendMessage("Oxapay client initialized!") ``` -------------------------------- ### get_bots_stats: Retrieve statistics for all bots in the account Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Calls Account.get_bots_stats() to get statistics for all bots in the account. The example checks the 'ok' field and sends a message with total bots and total users. The output shows an array of bot statistics. ```python Account.get_bots_stats() ``` ```python stats = Account.get_bots_stats() if stats["ok"]: all_stats = stats["result"] bot.sendMessage(f"Total bots: {all_stats['total_bots']}, Total users: {all_stats['total_users']}") ``` ```json { "ok": true, "result": { "total_bots": 5, "total_users": 2584, "total_active_users": 943, "total_commands": 68, "bots": [ { "botid": "1234567", "name": "Support Bot", "username": "support_bot", "status": "working", "users": 1250, "active_users": 450, "commands": 15, "points_used": 5432, "blocked_users": 12 }, { "botid": "7654321", "name": "Quiz Bot", "username": "quiz_master_bot", "status": "working", "users": 856, "active_users": 312, "commands": 8, "points_used": 2345, "blocked_users": 5 } ] } } ``` -------------------------------- ### Access webhook headers with options.headers Source: https://help.telebotcreator.com/changelog/version-7.1.2-update.md Use options.headers to retrieve any HTTP header sent with the webhook request. Headers like Host, Cookie, and Authorization are excluded for security. The example shows how to get Content-Type, X-Coinsway-Signature, and a custom header, then send a message with the Content-Type. ```python # Access any header content_type = options.headers.get("Content-Type", "") signature = options.headers.get("X-Coinsway-Signature", "") custom_header = options.headers.get("X-My-Custom-Header", "") bot.sendMessage(f"Content-Type: {content_type}") ``` -------------------------------- ### .env command example Source: https://help.telebotcreator.com/core-reference/advanced-features.md Example .env command defining global variables. Each line is KEY = value; values are parsed as Python literals when possible, otherwise kept as text. Multi-line list/dict values are supported, and # lines are comments. ```text API_KEY = "sk-abc123" MAX_RETRIES = 3 ADMINS = [12345, 67890] WELCOME = "Hello and welcome!" ``` -------------------------------- ### Automate payments with Coinpayments library Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs.md Example of setting keys and creating a client for Coinpayments to create transactions or check balances. ```python libs.Coinpayments.setKeys("merchant_public_key", "merchant_private_key") client = libs.Coinpayments.post() # Use the client to create a transaction / check balances ``` -------------------------------- ### get_bot_stats: Retrieve statistics for a specific bot Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Calls Account.get_bot_stats(botid) to get comprehensive statistics for a single bot. The example checks the 'ok' field and sends a message with the bot name and user counts. The output shows the structure of the result, including user activity and command usage. ```python Account.get_bot_stats(botid) ``` ```python stats = Account.get_bot_stats("1234567") if stats["ok"]: bot_stats = stats["result"] bot.sendMessage(f"Bot {bot_stats['name']}: {bot_stats['users']['total']} users, {bot_stats['users']['active_30d']} active") ``` ```json { "ok": true, "result": { "botid": "1234567", "name": "Support Bot", "username": "support_bot", "status": "working", "users": { "total": 1250, "active_30d": 450, "new_7d": 75, "blocked": 12 }, "commands": { "total": 15, "usage": { "start": 523, "help": 186, "settings": 94 } }, "points_used": 8765, "all_time_users": 1584 } } ``` -------------------------------- ### Get command usage with Account.get_command_usage Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Retrieves usage statistics for a specific command. Requires botid and command name; optional period parameter accepts "hour", "day", "week", "month", or "all". The example uses "week" and sends the result. ```python Account.get_command_usage(botid, command, period="all") ``` ```python usage = Account.get_command_usage("1234567", "/hello", "week") if usage["ok"]: bot.sendMessage(f"Command usage: {usage['result']}") ``` ```json { "ok": true, "result": { "command": "/hello", "count": 123, "update_types": { "message": 85, "callback_query": 38 }, "execution_types": { "direct": 95, "celery": 28 }, "period": "week" } } ``` -------------------------------- ### removeAllData usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of removing all resource data for the bot. ```python admin = libs.Resources.adminRes("points") admin.removeAllData() ``` -------------------------------- ### Full rewarded ad example with fallback and claim Source: https://help.telebotcreator.com/libraries-and-integrations/monetization.md This group shows a fuller example of showing a rewarded ad with custom button and after text, handling the case when no ad is available, and then claiming the reward in the 'then' command. The 'claim()' call must be used to verify the reward before granting points. ```python shown = libs.tbcads.reward_ad( "🎁 Your reward is locked\n\nTap below to view a quick sponsored offer.", button="📺 Click here", after="after_text", after_text="✅ Ad watched!", then="/myreward") if not shown: # No ad available right now — never leave the user stuck. bot.sendMessage("Ads are not available right now. Please try again shortly.") ``` ```python # /myreward — your reward code, whatever it is if not libs.tbcads.claim(): raise ReturnCommand points = libs.Resources.userRes("points", u) points.add(10) bot.sendMessage("✅ +10 points — you now have " + str(points.value())) ``` -------------------------------- ### removeAllDataOfUser usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of removing all resource data for a specific user. ```python admin = libs.Resources.adminRes("points") admin.removeAllDataOfUser("12345678") ``` -------------------------------- ### Sending a Welcome Message example Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Sends a welcome message using bot.sendMessage. ```python bot.sendMessage("Welcome to the bot!") ``` -------------------------------- ### removeDataOfUser usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of removing resource data for a specific user. ```python admin = libs.Resources.adminRes("points") admin.removeDataOfUser("12345678") ``` -------------------------------- ### Example usage of accountRes resource methods Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Demonstrates creating an account-level resource, adding points, checking the current value, and cutting points. Uses bot.sendMessage to report results. ```python # Create an account-level resource account_points = libs.Resources.accountRes("subscription_points") # Add points new_value = account_points.add(100) bot.sendMessage(f"Added points. New value: {new_value}") # Check current value current = account_points.value() bot.sendMessage(f"Current points: {current}") # Use points account_points.cut(50) bot.sendMessage(f"Used 50 points. Remaining: {account_points.value()}") ``` -------------------------------- ### clearAllData usage example Source: https://help.telebotcreator.com/changelog/version-4.7.0-update.md Example of clearing data for a specific user and for all users. ```python admin = libs.Resources.adminRes("points") admin.clearAllData("12345678") # Clear for specific user admin.clearAllData() # Clear for all users ``` -------------------------------- ### OpenAI integration with libs.openai_lib Source: https://help.telebotcreator.com/guides-and-examples/frequently-asked-questions-faqs.md Shows how to create an OpenAI client and assistant, send a message, and reply with the response. Requires your OpenAI API key. AI commands can run up to 160 seconds. ```python client = libs.openai_lib.OpenAIClient(api_key="YOUR_OPENAI_KEY") assistant = libs.openai_lib.AIAssistant( openai_client=client, model="gpt-4o", system_message="You are a helpful assistant." ) response = assistant.send_message(msg) bot.sendMessage(str(response.get("content")[0]['text']['value'])) ``` -------------------------------- ### TPY Example: bot.sendMessage Source: https://help.telebotcreator.com/guides-and-examples/glossary-and-key-concepts Example of sending a message using TPY (Telebot Python). ```python bot.sendMessage("Welcome to my bot!") ``` -------------------------------- ### Reply Keyboard Example Source: https://help.telebotcreator.com/core-reference/keyboards-and-buttons Shows how to send a reply keyboard that replaces the phone keyboard. ```APIDOC ## Reply Keyboard Example ### Description Sends a reply keyboard. Pressing a button sends its text as a normal message. The command whose name is exactly that text runs (here the commands named `Balance` and `Help`). With no such command, `*` runs. ### Method sendMessage ### Endpoint bot.sendMessage ### Parameters #### Request Body - **text** (string) - Required - The message text. - **reply_markup** (object) - Required - A dictionary containing the keyboard layout. - **keyboard** (array) - Required - Array of rows, each row is an array of button objects. - **text** (string) - Required - Button label. - **resize_keyboard** (boolean) - Optional - Whether to resize the keyboard. - **one_time_keyboard** (boolean) - Optional - Whether the keyboard is one-time. - **is_persistent** (boolean) - Optional - Whether the keyboard is persistent. - **input_field_placeholder** (string) - Optional - Placeholder text for the input field. ### Request Example ```json { "text": "Choose an option", "reply_markup": { "keyboard": [ [{"text": "Balance"}, {"text": "Help"}] ], "resize_keyboard": true } } ``` ### Response No explicit response documented. ``` -------------------------------- ### get_bot_usage: Retrieve usage statistics for a specific bot Source: https://help.telebotcreator.com/changelog/version-4.8.0-update.md Calls Account.get_bot_usage(botid, period="all") to get detailed usage statistics. The optional 'period' parameter accepts "day", "week", "month", or "all". The example uses "month" and sends the result. The output shows command counts, update types, and execution types. ```python Account.get_bot_usage(botid, period="all") ``` ```python usage = Account.get_bot_usage("1234567", "month") if usage["ok"]: bot.sendMessage(f"Bot usage: {usage['result']}") ``` ```json { "ok": true, "result": { "commands": { "/start": { "count": 523, "update_types": { "message": 400, "callback_query": 123 }, "execution_types": { "direct": 450, "celery": 73 } }, "/help": { "count": 186, "update_types": { "message": 150, "callback_query": 36 }, "execution_types": { "direct": 160, "celery": 26 } } }, "period": "month", "bot": { "botid": "1234567", "name": "Support Bot", "username": "support_bot", "status": "working" } } } ``` -------------------------------- ### libs.Oxapay.post Source: https://help.telebotcreator.com/core-reference/tbc-libraries-libs Initializes the Oxapay client with your API key. ```APIDOC ## libs.Oxapay.post ### Description Initializes the Oxapay client with your API key. ### Function Signature `post(merchant_api_key)` ### Parameters - **merchant_api_key** (str) - Required - Your Oxapay merchant API key. ### Returns No explicit return value documented. ``` -------------------------------- ### Handling normal updates with standard commands Source: https://help.telebotcreator.com/core-reference/tpy-language-reference.md Shows how to handle normal updates (message and callback_query) using standard command names. The /start command handles message updates, /joined handles new chat join events, and a command named 'show_profile' handles callback queries. ```python # /start command handles message updates with text "/start" # Command name in TBC: /start bot.sendMessage("Welcome to my bot!") # /joined command handles new chat join events # Command name in TBC: /joined bot.sendMessage("Welcome to the group!") # command for handling callback queries named "show_profile" # Command name in TBC: show_profile (callback data name) bot.answerCallbackQuery(callback_query_id=message.id, text="Loading profile...") ```