mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-28 00:56:19 +00:00
Update examples
This commit is contained in:
parent
6ad9caa7c6
commit
0d5724164c
@ -10,13 +10,14 @@ can be freely used as basic building blocks for your own applications without wo
|
||||
|
||||
Example | Description
|
||||
---: | :---
|
||||
[**hello**](hello.py) | Demonstration of basic API usage
|
||||
[**echo**](echo.py) | Reply to every private text message
|
||||
[**hello_world**](hello_world.py) | Demonstration of basic API usage
|
||||
[**echobot**](echobot.py) | Echo every private text message
|
||||
[**welcome**](welcome.py) | The Welcome Bot in [@PyrogramChat](https://t.me/pyrogramchat)
|
||||
[**history**](history.py) | Get the full message history of a chat
|
||||
[**chat_members**](chat_members.py) | Get all the members of a chat
|
||||
[**dialogs**](dialogs.py) | Get all of your dialog chats
|
||||
[**inline_bots**](inline_bots.py) | Query an inline bot and send a result to a chat
|
||||
[**using_inline_bots**](using_inline_bots.py) | Query an inline bot (as user) and send a result to a chat
|
||||
[**keyboards**](keyboards.py) | Send normal and inline keyboards using regular bots
|
||||
[**callback_queries**](callback_queries.py) | Handle queries coming from inline button presses
|
||||
[**inline_queries**](inline_queries.py) | Handle inline queries
|
||||
[**raw_updates**](raw_updates.py) | Handle raw updates (old, should be avoided)
|
||||
|
@ -5,12 +5,12 @@ It uses the @on_callback_query decorator to register a CallbackQueryHandler.
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
|
||||
|
||||
@app.on_callback_query()
|
||||
def answer(client, callback_query):
|
||||
callback_query.answer('Button contains: "{}"'.format(callback_query.data), show_alert=True)
|
||||
callback_query.answer("Button contains: '{}'".format(callback_query.data), show_alert=True)
|
||||
|
||||
|
||||
app.run() # Automatically start() and idle()
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
app = Client("my_count")
|
||||
app = Client("my_account")
|
||||
target = "pyrogramchat" # Target channel/supergroup
|
||||
|
||||
with app:
|
||||
|
54
examples/inline_queries.py
Normal file
54
examples/inline_queries.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""This example shows how to handle inline queries.
|
||||
Two results are generated when users invoke the bot inline mode, e.g.: @pyrogrambot hi.
|
||||
It uses the @on_inline_query decorator to register an InlineQueryHandler.
|
||||
"""
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from pyrogram import (
|
||||
Client, InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
)
|
||||
|
||||
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
|
||||
|
||||
@app.on_inline_query()
|
||||
def answer(client, inline_query):
|
||||
inline_query.answer(
|
||||
results=[
|
||||
InlineQueryResultArticle(
|
||||
id=uuid4(),
|
||||
title="Installation",
|
||||
input_message_content=InputTextMessageContent(
|
||||
"Here's how to install **Pyrogram**"
|
||||
),
|
||||
url="https://docs.pyrogram.ml/start/Installation",
|
||||
description="How to install Pyrogram",
|
||||
thumb_url="https://i.imgur.com/JyxrStE.png",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("Open website", url="https://docs.pyrogram.ml/start/Installation")]
|
||||
]
|
||||
)
|
||||
),
|
||||
InlineQueryResultArticle(
|
||||
id=uuid4(),
|
||||
title="Usage",
|
||||
input_message_content=InputTextMessageContent(
|
||||
"Here's how to use **Pyrogram**"
|
||||
),
|
||||
url="https://docs.pyrogram.ml/start/Usage",
|
||||
description="How to use Pyrogram",
|
||||
thumb_url="https://i.imgur.com/JyxrStE.png",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("Open website", url="https://docs.pyrogram.ml/start/Usage")]
|
||||
]
|
||||
)
|
||||
)
|
||||
],
|
||||
cache_time=1
|
||||
)
|
||||
|
||||
|
||||
app.run() # Automatically start() and idle()
|
@ -10,7 +10,7 @@ like send_audio(), send_document(), send_location(), etc...
|
||||
from pyrogram import Client, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
|
||||
# Create a client using your bot token
|
||||
app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
app = Client("my_bot", bot_token="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
|
||||
with app:
|
||||
app.send_message(
|
||||
@ -33,19 +33,17 @@ with app:
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[ # First row
|
||||
|
||||
InlineKeyboardButton( # Generates a callback query when pressed
|
||||
"Button",
|
||||
callback_data=b"data"
|
||||
), # Note how callback_data must be bytes
|
||||
callback_data=b"data" # Note how callback_data must be bytes
|
||||
),
|
||||
InlineKeyboardButton( # Opens a web URL
|
||||
"URL",
|
||||
url="https://docs.pyrogram.ml"
|
||||
),
|
||||
],
|
||||
[ # Second row
|
||||
# Opens the inline interface
|
||||
InlineKeyboardButton(
|
||||
InlineKeyboardButton( # Opens the inline interface
|
||||
"Choose chat",
|
||||
switch_inline_query="pyrogram"
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user