mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Added examples for formatting
This commit is contained in:
parent
191164cba0
commit
532011138c
52
examples/asynchronous_telebot/formatting_example.py
Normal file
52
examples/asynchronous_telebot/formatting_example.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
from telebot.async_telebot import AsyncTeleBot
|
||||||
|
from telebot import formatting
|
||||||
|
|
||||||
|
bot = AsyncTeleBot('token')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
async def start_message(message):
|
||||||
|
await bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
# function which connects all strings
|
||||||
|
formatting.format_text(
|
||||||
|
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters
|
||||||
|
formatting.mitalic(message.from_user.first_name, escape=True),
|
||||||
|
formatting.munderline(message.from_user.first_name, escape=True),
|
||||||
|
formatting.mstrikethrough(message.from_user.first_name, escape=True),
|
||||||
|
formatting.mcode(message.from_user.first_name, escape=True),
|
||||||
|
separator=" " # separator separates all strings
|
||||||
|
),
|
||||||
|
parse_mode='MarkdownV2'
|
||||||
|
)
|
||||||
|
|
||||||
|
# just a bold text using markdownv2
|
||||||
|
await bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.mbold(message.from_user.first_name, escape=True),
|
||||||
|
parse_mode='MarkdownV2'
|
||||||
|
)
|
||||||
|
|
||||||
|
# html
|
||||||
|
await bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.format_text(
|
||||||
|
formatting.hbold(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hitalic(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hunderline(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hstrikethrough(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hcode(message.from_user.first_name, escape=True),
|
||||||
|
separator=" "
|
||||||
|
),
|
||||||
|
parse_mode='HTML'
|
||||||
|
)
|
||||||
|
|
||||||
|
# just a bold text in html
|
||||||
|
await bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.hbold(message.from_user.first_name, escape=True),
|
||||||
|
parse_mode='HTML'
|
||||||
|
)
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
asyncio.run(bot.polling())
|
51
examples/formatting_example.py
Normal file
51
examples/formatting_example.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
from telebot import TeleBot
|
||||||
|
from telebot import formatting
|
||||||
|
|
||||||
|
bot = TeleBot('TOKEN')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
def start_message(message):
|
||||||
|
bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
# function which connects all strings
|
||||||
|
formatting.format_text(
|
||||||
|
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters
|
||||||
|
formatting.mitalic(message.from_user.first_name, escape=True),
|
||||||
|
formatting.munderline(message.from_user.first_name, escape=True),
|
||||||
|
formatting.mstrikethrough(message.from_user.first_name, escape=True),
|
||||||
|
formatting.mcode(message.from_user.first_name, escape=True),
|
||||||
|
separator=" " # separator separates all strings
|
||||||
|
),
|
||||||
|
parse_mode='MarkdownV2'
|
||||||
|
)
|
||||||
|
|
||||||
|
# just a bold text using markdownv2
|
||||||
|
bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.mbold(message.from_user.first_name, escape=True),
|
||||||
|
parse_mode='MarkdownV2'
|
||||||
|
)
|
||||||
|
|
||||||
|
# html
|
||||||
|
bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.format_text(
|
||||||
|
formatting.hbold(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hitalic(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hunderline(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hstrikethrough(message.from_user.first_name, escape=True),
|
||||||
|
formatting.hcode(message.from_user.first_name, escape=True),
|
||||||
|
separator=" "
|
||||||
|
),
|
||||||
|
parse_mode='HTML'
|
||||||
|
)
|
||||||
|
|
||||||
|
# just a bold text in html
|
||||||
|
bot.send_message(
|
||||||
|
message.chat.id,
|
||||||
|
formatting.hbold(message.from_user.first_name, escape=True),
|
||||||
|
parse_mode='HTML'
|
||||||
|
)
|
||||||
|
|
||||||
|
bot.infinity_polling()
|
Loading…
Reference in New Issue
Block a user