Here you will find files of an example inline telegram bot and everything you need to know about its guts.
Here you can find a source code of an inline telegram bot.
Plain Bash C++ C# CSS Diff HTML/XML Java JavaScript Markdown PHP Python Ruby SQL
import asyncio
import logging
import sys
import uuid
from aiogram import F
from aiogram.types import Message, InlineQuery, InlineQueryResultArticle, InputTextMessageContent, InlineQueryResultPhoto
from aiogram.filters import Command
from aiogram.utils.i18n import gettext as _
from config import bot_dispatcher, bot
@bot_dispatcher.inline_query(F.query == "greeting")
async def send_greetings (inline_query: InlineQuery ):
results = []
results.append(InlineQueryResultArticle(
id =str (uuid.uuid4()),
title=_("Обычное приветствие" ),
input_message_content=InputTextMessageContent(
disable_web_page_preview=True ,
message_text=_("Приветствую я вас сегодня." )
)
))
results.append(InlineQueryResultArticle(
id =str (uuid.uuid4()),
title=_("Жёсткое приветствие" ),
input_message_content=InputTextMessageContent(
disable_web_page_preview=True ,
message_text=_("Ну чё, как дела" )
)
))
results.append(InlineQueryResultArticle(
id =str (uuid.uuid4()),
title=_("Спокойное приветствие" ),
input_message_content=InputTextMessageContent(
disable_web_page_preview=True ,
message_text=_("Привет" )
)
))
await inline_query.answer(results)
@bot_dispatcher.inline_query(F.query == "memes")
async def send_user_images (inline_query: InlineQuery ):
results = []
results.append(InlineQueryResultPhoto(
id =str (uuid.uuid4()),
photo_url="https://wisconsinskydivingcenter.com/wp-content/uploads/2024/05/you-dont-need-a-parachute-to-go-skydiving-meme.jpeg" ,
thumbnail_url="https://wisconsinskydivingcenter.com/wp-content/uploads/2024/05/you-dont-need-a-parachute-to-go-skydiving-meme.jpeg"
))
results.append(InlineQueryResultPhoto(
id =str (uuid.uuid4()),
photo_url="https://jungleroots.com/wp-content/uploads/2022/11/1_OkVxoXBTygSKB8K-zbB7uQ-300x176.jpeg" ,
thumbnail_url="https://jungleroots.com/wp-content/uploads/2022/11/1_OkVxoXBTygSKB8K-zbB7uQ-300x176.jpeg"
))
results.append(InlineQueryResultPhoto(
id =str (uuid.uuid4()),
photo_url="https://livestorm.imgix.net/1127/1651607695-obi-wan-alarm-work-meme.jpeg?h=auto&w=730&fm=jpeg&auto=format&q=90&dpr=1" ,
thumbnail_url="https://livestorm.imgix.net/1127/1651607695-obi-wan-alarm-work-meme.jpeg?h=auto&w=730&fm=jpeg&auto=format&q=90&dpr=1"
))
await inline_query.answer(results)
@bot_dispatcher.message(Command('help'))
async def help (message: Message ):
await message.answer(_("Этот бот является примером того, как можно реализовать inline функционал для него." ))
await message.answer(_("/startapp - запустить приложение" ))
await message.answer(_("@joker_gut_bot memes - запросить мемы для показа" ))
await message.answer(_("@joker_gut_bot greeting - запросить ответы по умолчанию" ))
@bot_dispatcher.message(Command("startapp"))
async def start_app (message: Message ):
await message.answer(_("Этот бот является примером того, как можно реализовать inline функционал для него." ))
async def main () -> None :
await bot_dispatcher.start_polling(bot)
if __name__ == "__main__" :
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
Reviews
(0)