Skip to content

Commit

Permalink
async support & file renames
Browse files Browse the repository at this point in the history
  • Loading branch information
nypava committed Aug 13, 2024
1 parent adbf425 commit b198c3a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
33 changes: 33 additions & 0 deletions examples/asynchronous_telebot/mini_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# The source of the "https://pytelegrambotminiapp.vercel.app" can be found in https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples/mini_app_web

import asyncio
from telebot.async_telebot import AsyncTeleBot
from telebot.types import (
ReplyKeyboardMarkup,
KeyboardButton,
WebAppInfo,
InlineKeyboardMarkup,
InlineKeyboardButton
)

BOT_TOKEN = ""
WEB_URL = "https://pytelegrambotminiapp.vercel.app"

bot = AsyncTeleBot(BOT_TOKEN)

@bot.message_handler(commands=["start"])
async def start(message):
reply_keyboard_markup = ReplyKeyboardMarkup(resize_keyboard=True)
reply_keyboard_markup.row(KeyboardButton("Start MiniApp", web_app=WebAppInfo(WEB_URL)))

inline_keyboard_markup = InlineKeyboardMarkup()
inline_keyboard_markup.row(InlineKeyboardButton('Start MiniApp', web_app=WebAppInfo(WEB_URL)))

await bot.reply_to(message, "Click the bottom inline button to start MiniApp", reply_markup=inline_keyboard_markup)
await bot.reply_to(message, "Click keyboard button to start MiniApp", reply_markup=reply_keyboard_markup)

@bot.message_handler(content_types=['web_app_data'])
async def web_app(message):
await bot.reply_to(message, f'Your message is "{message.web_app_data.data}"')

asyncio.run(bot.polling())
4 changes: 3 additions & 1 deletion examples/webapp/bot.py → examples/mini_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# The source of the "https://pytelegrambotminiapp.vercel.app" can be found in https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples/mini_app_web

from telebot import TeleBot
from telebot.types import (
ReplyKeyboardMarkup,
Expand All @@ -8,7 +10,7 @@
)

BOT_TOKEN = ""
WEB_URL = "https://pytelegrambotminiapp.vercel.app" # https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples/webapp/webapp
WEB_URL = "https://pytelegrambotminiapp.vercel.app"

bot = TeleBot(BOT_TOKEN)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

<p class="header-text"> closing confirmation [Bot API 6.2+]</p>
<div class="content-block content-block_close-confirmation close-confirmation">
<p class="content-block__text"> Confimation dialog when closing mini app </p>
<p class="content-block__text"> Confimation dialog when closing miniapp </p>
<div class="content-block__toggle-box">
<button class="default-button default-button_disable" id="enable-close-confirm-button" value="disable"> Enable </button>
<button class="default-button" id="disable-close-confirm-button" value="enable"> Disable </button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ text.platform.innerText += telegram.platform;

button.send_message.addEventListener('click', () => {
telegram.sendData(input.message.value);
if (telegram.initDataUnsafe) telegram.showAlert('SendData only works in webapp that opened with reply keyboard.')
if (telegram.initDataUnsafe) telegram.showAlert('SendData only works in miniapp that opened with reply keyboard.')
input.message.value = ''
});

Expand Down
File renamed without changes.

0 comments on commit b198c3a

Please sign in to comment.