-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10 inlinebot 1 from docs.py
92 lines (65 loc) · 2.95 KB
/
10 inlinebot 1 from docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Don't forget to enable inline mode with @BotFather
First, a few handler functions are defined. Then, those functions are passed to
the Application and registered at their respective places.
Then, the bot is started and runs until we press Ctrl-C on the command line.
Usage:
Basic inline bot example. Applies different text transformations.
Press Ctrl-C on the command line or send a signal to the process to stop the
bot.
"""
import logging
from html import escape
from uuid import uuid4
from telegram import InlineQueryResultArticle, InputTextMessageContent, Update
from telegram.constants import ParseMode
from telegram.ext import Application, CommandHandler, ContextTypes, InlineQueryHandler
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
# Define a few command handlers. These usually take the two arguments update and
# context.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /start is issued."""
await update.message.reply_text("Hi!")
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /help is issued."""
await update.message.reply_text("Help!")
async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the inline query. This is run when you type: @botusername <query>"""
user = update.inline_query.from_user
query = update.inline_query.query
if not query:
await context.bot.send_message(user.id, f"This is Blank Please Write any Thing {user.full_name}")
return
results = [
InlineQueryResultArticle(
id=str(uuid4()),
title="Caps",
input_message_content=InputTextMessageContent(query.upper()+f"\nThis is for Caps Query"),
),
InlineQueryResultArticle(
id=str(uuid4()),
title="Bold",
input_message_content=InputTextMessageContent(
f"<b>{escape(query)}</b>"+f"\nThis is for Bold Query", parse_mode=ParseMode.HTML
),
),
InlineQueryResultArticle(
id=str(uuid4()),
title="Italic",
input_message_content=InputTextMessageContent(
f"<i>{escape(query)}</i>"+f"\nThis is for italic Query", parse_mode=ParseMode.HTML
),
),
]
await update.inline_query.answer(results)
def main() -> None:
"""Run the bot."""
application = Application.builder().token("6780033449:AAFKWBuWlPcBHLm303owSEvDriPZjCxs9ZU").build()
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("help", help_command))
application.add_handler(InlineQueryHandler(inline_query))
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()