Push Notifications¶
-
misbot.push_notifications.
get_user_list
()¶ Retrieves the
chatID
of all users fromChat
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 thePushMessage
DB model.We pass the
message_uuid
generated from created the record of the message previously and pass it to thepush_t()
.After messages have been sent, we bulk commit all the
PushNotification
records created withinpush_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 themessage_id
received intoPushNotification
DB Model. Appends the record object tolist_of_objs
to be bulk committed after all messages have been sent throughThreadPoolExecutor
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
andmessage_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