An example of inline telegram bot

Clock
10.01.2025
Clock
14.05.2025
An eye
95
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
Теги: Bot Telegram bot
Telegram bot
Telegram bot

Description

Here you will find files of an example inline telegram bot and everything you need to know about its guts.
You can try out my telegram bot by this link: @joker_gut_bot

Functionality

Supported commands:
  1. /help - it displays info about each command
  2. /startapp - it displays a single message
  3. @joker_gut_bot greeting (inline) - give you a choice between 3 greetings
  4. @joker_gut_bot memes (inline) - give you a choice between 3 memes

Source code

Here you can find a source code of an inline telegram bot.

main.py file

#!/usr/bin/env python

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())

config.py file

from aiogram import Bot, Dispatcher
from aiogram.utils.i18n import I18n, SimpleI18nMiddleware

with open(".env", "r") as file:
buffer = file.read()
line_pos = buffer.find("BOT_TOKEN")
TOKEN = buffer[buffer.find("=", line_pos) + 1:]

bot = Bot(TOKEN)
bot_dispatcher = Dispatcher(bot=bot)

# Set up translation
i18n = I18n(path="locales", domain="messages")
i18n_handler = SimpleI18nMiddleware(i18n)
i18n_handler.setup(bot_dispatcher)

Similar tools

Simple quizer bot

Telegram bot
This is a simple telegram bot questionnaire, which is written in python/aiogram and uses a clever system of its own templates to render (send) survey results to users. https://t.me/TimQuizzerBot or @TimQuizzerBot

Telegram-bot notepad

For Linux
Telegram bot
Terminal user interface
This is a telegram bot notepad where you can create and manage your notes. Filter and group as you wish. It is also easily customizable and supports two languages: Russian, English. https://t.me/NotebookOnMarginalia_bot or @NotebookOnMarginalia_bot

heart
cloud
cloud
cloud
message

Reviews

(0)

captcha
Send
Response for
>
It's empty now. Be the first (o゚v゚)ノ