|
11 | 11 |
|
12 | 12 | # This example uses the configuration of `config.ini` (see examples/README)
|
13 | 13 | examples_dir = Path(__file__).parent.parent.absolute()
|
| 14 | +SESSION_NAME: str = "tgintegration_examples" |
14 | 15 |
|
15 |
| -client = Client( |
16 |
| - "tgintegration_examples", |
17 |
| - workdir=examples_dir, |
18 |
| - config_file=examples_dir / "config.ini", |
19 |
| -) |
20 |
| - |
21 |
| -controller = BotController( |
22 |
| - peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot |
23 |
| - client=client, |
24 |
| - max_wait=8, # Maximum timeout for responses (optional) |
25 |
| - wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional) |
26 |
| - raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True) |
27 |
| - global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional) |
28 |
| -) |
29 | 16 |
|
| 17 | +# This example uses the configuration of `config.ini` (see examples/README) |
| 18 | +def create_client(session_name: str = SESSION_NAME) -> Client: |
| 19 | + client = Client( |
| 20 | + session_name=session_name, |
| 21 | + workdir=examples_dir, |
| 22 | + config_file=examples_dir / "config.ini", |
| 23 | + ) |
| 24 | + client.load_config() |
| 25 | + return client |
| 26 | + |
| 27 | + |
| 28 | +async def run_example(client: Client): |
| 29 | + controller = BotController( |
| 30 | + peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot |
| 31 | + client=client, |
| 32 | + max_wait=8, # Maximum timeout for responses (optional) |
| 33 | + wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional) |
| 34 | + raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True) |
| 35 | + global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional) |
| 36 | + ) |
30 | 37 |
|
31 |
| -async def run_example(): |
32 | 38 | print("Clearing chat to start with a blank screen...")
|
33 | 39 | await controller.clear_chat()
|
34 | 40 |
|
@@ -80,4 +86,4 @@ async def run_example():
|
80 | 86 |
|
81 | 87 |
|
82 | 88 | if __name__ == "__main__":
|
83 |
| - asyncio.get_event_loop().run_until_complete(run_example()) |
| 89 | + asyncio.get_event_loop().run_until_complete(run_example(create_client())) |
0 commit comments