kamihi.tg.client
⚓︎
Telegram client module.
This module provides a Telegram client for sending messages and handling commands.
License
MIT
Examples:
>>> from kamihi.tg.client import TelegramClient
>>> from kamihi.base.config import KamihiSettings
>>> client = TelegramClient(KamihiSettings(), [])
>>> client.run()
Classes:
Name | Description |
---|---|
TelegramClient |
Telegram client class. |
TelegramClient
⚓︎
TelegramClient(
settings: KamihiSettings, handlers: list[BaseHandler]
)
Telegram client class.
This class provides methods to send messages and handle commands.
Initialize the Telegram client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
KamihiSettings
|
The settings object. |
required |
|
list[BaseHandler]
|
List of handlers to register. |
required |
Methods:
Name | Description |
---|---|
register_run_once_job |
Add a job to run once. |
reset_scopes |
Reset the command scopes for the bot. |
run |
Run the Telegram bot. |
set_scopes |
Set the command scopes for the bot. |
stop |
Stop the Telegram bot. |
Source code in src/kamihi/tg/client.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
register_run_once_job
⚓︎
register_run_once_job(
callback: callable, when: int
) -> None
Add a job to run once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
callable
|
The callback function to run. |
required |
|
int
|
second from now to run the job. |
required |
Source code in src/kamihi/tg/client.py
146 147 148 149 150 151 152 153 154 155 |
|
reset_scopes
async
⚓︎
reset_scopes(context: CallbackContext) -> None
Reset the command scopes for the bot.
This method clears all command scopes and sets the default commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
CallbackContext
|
The context of the callback. Not used but required for this function to be registered as a job. |
required |
Source code in src/kamihi/tg/client.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
run
⚓︎
run() -> None
Run the Telegram bot.
Source code in src/kamihi/tg/client.py
157 158 159 160 |
|
set_scopes
async
⚓︎
set_scopes(scopes: dict[int, list[BotCommand]]) -> None
Set the command scopes for the bot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict[int, list[BotCommand]]
|
The command scopes to set. |
required |
Source code in src/kamihi/tg/client.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
stop
async
⚓︎
stop() -> None
Stop the Telegram bot.
Source code in src/kamihi/tg/client.py
162 163 164 165 |
|