Push Notifications

misbot.push_notifications.get_user_list()

Retrieves the chatID of all users from Chat table. A tuple is returned which is then unpacked into a list by iterating over the tuple.

Returns:List of user chat IDs
Return type:list
misbot.push_notifications.get_bot()

Create an instance of the telegram.bot.Bot object.

Returns:Telegram bot object.
Return type:telegram.bot.Bot
misbot.push_notifications.push_message_threaded(message, user_list)

Use ThreadPoolExecutor to send notification message asynchronously to all users. Before sending the message, we create a record of the sent message in the PushMessage DB model.

We pass the message_uuid generated from created the record of the message previously and pass it to the push_t().

After messages have been sent, we bulk commit all the PushNotification records created within push_t() to our database.

Parameters:
  • message (str) – Notification message
  • user_list (list) – List of all bot users
Returns:

Time taken to send messages and the message_uuid

Return type:

tuple

misbot.push_notifications.push_t(bot, message, message_uuid, chat_id)

Sends the message to the specified chat_id. Records the message_id received into PushNotification DB Model. Appends the record object to list_of_objs to be bulk committed after all messages have been sent through ThreadPoolExecutor

Parameters:
  • bot (telegram.bot.Bot) – Telegram Bot object
  • message (str) – Notification message
  • message_uuid (str) – UUID of the notification message created in push_message_threaded
  • chat_id (int|str) – 9-Digit unique user ID
misbot.push_notifications.delete_threaded(message_id_list, user_list)

Use ThreadPoolExecutor to delete notification message asynchronously for all users.

Parameters:
  • message_id_list (list) – List of message ids stored in our DB.
  • user_list (list) – List of all bot users
Returns:

Time taken to send all delete requests

Return type:

float

misbot.push_notifications.delete(bot, message_id, chat_id)

Sends a delete request for a particular chat_id and message_id

Parameters:
  • bot (telegram.bot.Bot) – Telegram Bot object
  • message_id (int) – The message ID for the notification message
  • chat_id (int | str) – 9-Digit unique user ID