bot package
Submodules
bot.receive_msg module
- class bot.receive_msg.ReceivingMessage(shutdown_event, config, loop, camera_task_queue_async, door_open_task_queue)
Bases:
objectReceiving Telegram Bot messages
- Parameters:
shutdown_event (threading.Event)
config (config_util.Configuration)
camera_task_queue_async (asyncio.Queue)
door_open_task_queue (queue.Queue)
- start()
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.
- Return type:
None
- 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.
- receive_any_msg_text(message)
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
- Parameters:
message (Message)
- Return type:
None
- take_foto(message)
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.
- Parameters:
message (Message)
- Return type:
None
- take_picam_foto(message)
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
- Parameters:
message (Message)
- Return type:
None
- take_blink_foto(message)
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.
- Parameters:
message (Message)
- Return type:
None
- register_bink_authentication(message)
Registers a Blink authentication based on the received message.
- Args:
self: the object instance message (telebot.types.Message): the message received
- Returns:
None
- Parameters:
message (Message)
- Return type:
None
- rcv_blink_auth(message)
- Parameters:
message (Message)
- Return type:
None
- get_allowed(message)
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.
- Parameters:
message (Message)
- Return type:
bool
- get_allowed_user(message)
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.
- Parameters:
message (Message)
- Return type:
bool
- validate_msg_text_has_code(message)
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.
- Parameters:
message (Message)
- Return type:
bool
- verify_otp_code_in_msg(message)
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.
- Parameters:
message (Message)
- Return type:
bool
bot.send_msg module
- class bot.send_msg.SendMessage(shutdown_event, config, loop, message_task_queue)
Bases:
object- Parameters:
shutdown_event (Event)
config (Configuration)
message_task_queue (Queue)
- start()
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
- Return type:
None
- stop()
A method to stop the bot. It logs the action of stopping bot polling, stops the bot from polling, removes the webhook.
- Return type:
None
- reply_message(chat_id, text, 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.
- Parameters:
chat_id (str)
text (str)
message (Message)
- send_message(chat_id, text)
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
- Parameters:
chat_id (str)
text (str)
- Return type:
None
- send_photo(chat_id, image_path)
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
- Parameters:
chat_id (str)
image_path (str)
- Return type:
None