Skip to content

Commit 0d57241

Browse files
committed
Update examples
1 parent 6ad9caa commit 0d57241

8 files changed

Lines changed: 65 additions & 12 deletions

File tree

examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ can be freely used as basic building blocks for your own applications without wo
1010

1111
Example | Description
1212
---: | :---
13-
[**hello**](hello.py) | Demonstration of basic API usage
14-
[**echo**](echo.py) | Reply to every private text message
13+
[**hello_world**](hello_world.py) | Demonstration of basic API usage
14+
[**echobot**](echobot.py) | Echo every private text message
1515
[**welcome**](welcome.py) | The Welcome Bot in [@PyrogramChat](https://t.me/pyrogramchat)
1616
[**history**](history.py) | Get the full message history of a chat
1717
[**chat_members**](chat_members.py) | Get all the members of a chat
1818
[**dialogs**](dialogs.py) | Get all of your dialog chats
19-
[**inline_bots**](inline_bots.py) | Query an inline bot and send a result to a chat
19+
[**using_inline_bots**](using_inline_bots.py) | Query an inline bot (as user) and send a result to a chat
2020
[**keyboards**](keyboards.py) | Send normal and inline keyboards using regular bots
2121
[**callback_queries**](callback_queries.py) | Handle queries coming from inline button presses
22+
[**inline_queries**](inline_queries.py) | Handle inline queries
2223
[**raw_updates**](raw_updates.py) | Handle raw updates (old, should be avoided)

examples/callback_queries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
from pyrogram import Client
77

8-
app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
8+
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
99

1010

1111
@app.on_callback_query()
1212
def answer(client, callback_query):
13-
callback_query.answer('Button contains: "{}"'.format(callback_query.data), show_alert=True)
13+
callback_query.answer("Button contains: '{}'".format(callback_query.data), show_alert=True)
1414

1515

1616
app.run() # Automatically start() and idle()

examples/chat_members.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pyrogram import Client
44

5-
app = Client("my_count")
5+
app = Client("my_account")
66
target = "pyrogramchat" # Target channel/supergroup
77

88
with app:
File renamed without changes.

examples/inline_queries.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""This example shows how to handle inline queries.
2+
Two results are generated when users invoke the bot inline mode, e.g.: @pyrogrambot hi.
3+
It uses the @on_inline_query decorator to register an InlineQueryHandler.
4+
"""
5+
6+
from uuid import uuid4
7+
8+
from pyrogram import (
9+
Client, InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardMarkup, InlineKeyboardButton
10+
)
11+
12+
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
13+
14+
15+
@app.on_inline_query()
16+
def answer(client, inline_query):
17+
inline_query.answer(
18+
results=[
19+
InlineQueryResultArticle(
20+
id=uuid4(),
21+
title="Installation",
22+
input_message_content=InputTextMessageContent(
23+
"Here's how to install **Pyrogram**"
24+
),
25+
url="https://docs.pyrogram.ml/start/Installation",
26+
description="How to install Pyrogram",
27+
thumb_url="https://i.imgur.com/JyxrStE.png",
28+
reply_markup=InlineKeyboardMarkup(
29+
[
30+
[InlineKeyboardButton("Open website", url="https://docs.pyrogram.ml/start/Installation")]
31+
]
32+
)
33+
),
34+
InlineQueryResultArticle(
35+
id=uuid4(),
36+
title="Usage",
37+
input_message_content=InputTextMessageContent(
38+
"Here's how to use **Pyrogram**"
39+
),
40+
url="https://docs.pyrogram.ml/start/Usage",
41+
description="How to use Pyrogram",
42+
thumb_url="https://i.imgur.com/JyxrStE.png",
43+
reply_markup=InlineKeyboardMarkup(
44+
[
45+
[InlineKeyboardButton("Open website", url="https://docs.pyrogram.ml/start/Usage")]
46+
]
47+
)
48+
)
49+
],
50+
cache_time=1
51+
)
52+
53+
54+
app.run() # Automatically start() and idle()

examples/keyboards.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pyrogram import Client, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
1111

1212
# Create a client using your bot token
13-
app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
13+
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
1414

1515
with app:
1616
app.send_message(
@@ -33,19 +33,17 @@
3333
reply_markup=InlineKeyboardMarkup(
3434
[
3535
[ # First row
36-
3736
InlineKeyboardButton( # Generates a callback query when pressed
3837
"Button",
39-
callback_data=b"data"
40-
), # Note how callback_data must be bytes
38+
callback_data=b"data" # Note how callback_data must be bytes
39+
),
4140
InlineKeyboardButton( # Opens a web URL
4241
"URL",
4342
url="https://docs.pyrogram.ml"
4443
),
4544
],
4645
[ # Second row
47-
# Opens the inline interface
48-
InlineKeyboardButton(
46+
InlineKeyboardButton( # Opens the inline interface
4947
"Choose chat",
5048
switch_inline_query="pyrogram"
5149
),

0 commit comments

Comments
 (0)