예제 #1
0
# This example uses the configuration of `config.ini` (see examples/README)
client = BotIntegrationClient(
    bot_under_test='@BotListBot',
    session_name=
    'tgintegration_examples',  # Arbitrary file path to the Pyrogram session file
    max_wait_response=8,  # Maximum timeout for bot responses
    min_wait_consecutive=2,  # Minimum time to wait for consecutive messages
    raise_no_response=
    True  # Raise `InvalidResponseError` when no response received
)

print("Starting...")
client.start()

print("Clearing chat to start with a blank screen...")
client.clear_chat()

print(
    "Send the /start command to the bot_under_test and 'await' exactly three messages..."
)
response = client.send_command_await("start", num_expected=3)

assert response.num_messages == 3
print("Three messages received.")
assert response.messages[0].sticker
print("First message is a sticker.")

print("Let's examine the buttons in the response...")
inline_keyboard = response.inline_keyboards[0]
assert len(inline_keyboard.rows[0]) == 3
print("There are three buttons in the first row.")
예제 #2
0
from tgintegration import BotIntegrationClient

# This example uses the configuration of `config.ini` (see examples/README)
client = BotIntegrationClient(
    bot_under_test='@BotListBot',
    session_name=
    'my_account',  # Arbitrary file path to the Pyrogram session file
    max_wait_response=8,  # Maximum timeout for bot responses
    min_wait_consecutive=2,  # Minimum time to wait for consecutive messages
    raise_no_response=
    True  # Raise `InvalidResponseError` when no response received
)

client.start()
client.clear_chat()  # Let's start with a blank screen

### Now let's send the /start command to the bot_under_test and "await" exactly three messages:
response = client.send_command_await("start", num_expected=3)

assert response.num_messages == 3
assert response.messages[0].sticker  # First message is a sticker

### Let's examine these buttons in the response...
inline_keyboard = response.inline_keyboards[0]
# Three buttons in the first row
assert len(inline_keyboard.rows[0]) == 3

### We can also query and press the inline keyboard buttons:
# Click the first button matching the pattern
examples = response.inline_keyboards[0].press_button_await(