bot package
Submodules
bot.receive_msg module
- class bot.receive_msg.ReceivingMessage(shutdown_event: Event, config: Configuration, loop, camera_task_queue_async: Queue, door_open_task_queue: Queue)
Bases:
object
Receiving Telegram Bot messages
- get_allowed(message: Message) bool
Checks if the message chat ID matches the configured Telegram chat number and calls get_allowed_user if the condition is met. Returns True if the user is allowed, False otherwise.
- Parameters:
message (telebot.types.Message): The message object received.
- Returns:
bool: True if the user is allowed, False otherwise.
- get_allowed_user(message: Message) bool
Checks if the message from_user ID matches the configured allowed user IDs.
- Parameters:
message (telebot.types.Message): The message object received.
- Returns:
bool: True if the user is allowed, False otherwise.
- rcv_blink_auth(message: Message) None
- receive_any_msg_text(message: Message) None
Check if the message is received from an allowed telegram chat group and allowed user ID. If the conditions are met, check if the message text has a TOTP code and open the door if correct, otherwise do nothing.
- Parameters:
message (telebot.types.Message): The message object received.
- Returns:
None
- register_bink_authentication(message: Message) None
Registers a Blink authentication based on the received message.
- Args:
self: the object instance message (telebot.types.Message): the message received
- Returns:
None
- start() None
Starts the bot’s endless polling. Uses the bot’s infinity_polling method with specified timeout and long_polling_timeout. Logs any errors that occur during polling.
- stop()
A method to stop the bot. It logs the action of stopping bot polling, stops the bot from polling, removes the webhook, and logs the completion of stopping the bot.
- take_blink_foto(message: Message) None
Takes a photo request specific to the Blink camera from a telegram message and puts it into a camera task queue.
- Args:
message (telebot.types.Message): The telegram message object containing the photo request.
- Returns:
None
This function first logs a debug message indicating that a Blink photo request has been received with the given message. It then checks if the message is received from an allowed telegram chat group and if it was sent by an allowed user ID. If the conditions are met, it sets the event loop to the current loop and puts a camera task into the camera task queue. The camera task contains the chat ID, message, reply flag, and blink_photo flag.
- take_foto(message: Message) None
Takes a photo request from a telegram message and puts it into a camera task queue.
- Args:
message (telebot.types.Message): The telegram message object containing the photo request.
- Returns:
None
This function first logs a debug message indicating that a photo request has been received with the given message. It then checks if the message is received from an allowed telegram chat group and if it was sent by an allowed user ID. If the conditions are met, it sets the event loop to the current loop and puts a camera task into the camera task queue. The camera task contains the chat ID, message, reply flag, and photo flag.
- take_picam_foto(message: Message) None
Takes a photo request specific to the PiCam (foto API [PiCamAPI](https://github.com/OliverDrechsler/PiCam_API)) from a telegram message and puts it into a camera task queue.
- Args:
message (telebot.types.Message): The telegram message object containing the photo request.
- Returns:
None
- validate_msg_text_has_code(message: Message) bool
Validates if the message text contains a code number by using a regex search pattern. If a match is found, it calls the ‘verify_otp_code_in_msg’ method and returns the result. If no match is found, it logs a message and returns False.
- Parameters:
self: The instance of the class. message (telebot.types.Message): The message object received.
- Returns:
bool: True if the message text contains a code number, False otherwise.
- verify_otp_code_in_msg(message: Message) bool
Verifies if the received message text contains a valid TOTP code. If the code is valid, it logs a message and returns True. If the code is invalid, it logs a message and returns False.
- Parameters:
self: The instance of the class. message (telebot.types.Message): The message object received.
- Returns:
bool: True if the message text contains a valid TOTP code, False otherwise.
bot.send_msg module
- class bot.send_msg.SendMessage(shutdown_event: Event, config: Configuration, loop, message_task_queue: Queue)
Bases:
object
- reply_message(chat_id: str, text: str, message: Message)
Reply to a message in a chat.
- Args:
chat_id (str): The ID of the chat. text (str): The text of the reply message. message (telebot.types.Message): The message to reply to.
- Returns:
None
This function sends a reply message to a chat using the Telegram Bot API. It uses the reply_to method of the bot object to send the reply. The reply message contains the provided text. The function logs the reply message using the logger object.
- send_message(chat_id: str, text: str) None
Send a message to a specified chat using the Telegram Bot API.
- Args:
chat_id (str): The ID of the chat. text (str): The text of the message to be sent.
- Returns:
None
- send_photo(chat_id: str, image_path: str) None
Send a photo to a specified chat using the Telegram Bot API.
- Args:
chat_id (str): The ID of the chat. image_path (str): The path to the image file to be sent.
- Returns:
None
- start() None
Starts the thread endless loop to send telegram bot messages.
This function runs in an infinite loop until the stop_polling event is set. It continuously retrieves tasks from the message_task_queue and processes them. If a task is an instance of Message_Task, it performs the following actions based on the task attributes: - If task.send is True, it sends a message to the specified chat using the send_message method. - If task.reply is True, it replies to the specified message with the given text using the reply_message method. - If task.photo is True, it sends a photo to the specified chat using the send_photo method.
If an exception occurs during the execution of the loop, it logs the error and continues.
After the loop finishes, it calls the stop method.
- Parameters:
self (SendMessage): The instance of the SendMessage class.
- Returns:
None
- stop() None
A method to stop the bot. It logs the action of stopping bot polling, stops the bot from polling, removes the webhook.