mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-24 07:51:44 +00:00
Add simple_echo example
This commit is contained in:
parent
1fca99c712
commit
b6cd30d281
34
examples/simple_echo.py
Normal file
34
examples/simple_echo.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from pyrogram import Client
|
||||||
|
from pyrogram.api import types
|
||||||
|
|
||||||
|
"""This simple example bot will reply to all private text messages"""
|
||||||
|
|
||||||
|
|
||||||
|
def update_handler(client, update, users, chats):
|
||||||
|
if isinstance(update, types.UpdateNewMessage): # Filter by UpdateNewMessage (Private Messages)
|
||||||
|
message = update.message # type: types.Message
|
||||||
|
|
||||||
|
if isinstance(message, types.Message): # Filter by Message to exclude MessageService and MessageEmpty
|
||||||
|
if isinstance(message.to_id, types.PeerUser): # Private Messages (Message from user)
|
||||||
|
client.send_message(
|
||||||
|
chat_id=message.from_id,
|
||||||
|
text=message.message,
|
||||||
|
reply_to_message_id=message.id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Pyrogram setup
|
||||||
|
client = Client("example")
|
||||||
|
|
||||||
|
# Set the update_handler callback function
|
||||||
|
client.set_update_handler(update_handler)
|
||||||
|
client.start()
|
||||||
|
|
||||||
|
# Blocks the program execution until you press CTRL+C then
|
||||||
|
# automatically stops the Client by closing the underlying connection
|
||||||
|
client.idle()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user