From 07c37cd94c839f7f746dfb84f6620e87ffb94f85 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 6 May 2018 12:51:48 +0200 Subject: [PATCH] Add send_bot_keyboards.py example --- examples/README.md | 3 +- .../{inline_bots.py => query_inline_bots.py} | 0 examples/send_bot_keyboards.py | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) rename examples/{inline_bots.py => query_inline_bots.py} (100%) create mode 100644 examples/send_bot_keyboards.py diff --git a/examples/README.md b/examples/README.md index 72aa6393..2b854427 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,5 +13,6 @@ you can simply copy-paste and run, the only things you have to change are your s - [**get_history.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_history.py) - [**get_participants.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_participants.py) - [**get_participants2.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_participants2.py) -- [**inline_bots.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/inline_bots.py) +- [**query_inline_bots.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/query_inline_bots.py) +- [**send_bot_keyboards.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/send_bot_keyboards.py) - [**raw_update_handler.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/raw_update_handler.py) diff --git a/examples/inline_bots.py b/examples/query_inline_bots.py similarity index 100% rename from examples/inline_bots.py rename to examples/query_inline_bots.py diff --git a/examples/send_bot_keyboards.py b/examples/send_bot_keyboards.py new file mode 100644 index 00000000..21c1a60e --- /dev/null +++ b/examples/send_bot_keyboards.py @@ -0,0 +1,51 @@ +from pyrogram import Client, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton + +"""This example will show you how to send normal and inline keyboards. + +You must log-in as a regular bot in order to send keyboards (use the token from @BotFather). +Any attempt in sending keyboards with a user account will be simply ignored by the server. + +send_message() is used as example, but a keyboard can be sent with any other send_* methods, +like send_audio(), send_document(), send_location(), etc... +""" + +# Create a client using your bot token +app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") +app.start() + +app.send_message( + "haskell", # Edit this + "This is a ReplyKeyboardMarkup example", + reply_markup=ReplyKeyboardMarkup( + [ + ["A", "B", "C", "D"], # First row + ["E", "F", "G"], # Second row + ["H", "I"], # Third row + ["J"] # Fourth row + ], + resize_keyboard=True # Make the keyboard smaller + ) +) + +app.send_message( + "haskell", # Edit this + "This is a InlineKeyboardMarkup example", + reply_markup=InlineKeyboardMarkup( + [ + [ # First row + # Generates a callback query when pressed + InlineKeyboardButton("Button", callback_data="data"), + # Opens a web URL + InlineKeyboardButton("URL", url="https://docs.pyrogram.ml"), + ], + [ # Second row + # Opens the inline interface of a bot in another chat with a pre-defined query + InlineKeyboardButton("Choose chat", switch_inline_query="pyrogram"), + # Same as the button above, but the inline interface is opened in the current chat + InlineKeyboardButton("Inline here", switch_inline_query_current_chat="pyrogram"), + ] + ] + ) +) + +app.stop()