-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
128-feature/show-subject-in-slack-and-telegram #129
128-feature/show-subject-in-slack-and-telegram #129
Conversation
…ke node down message for testing
we could just define |
Here's how I would do it. I'll leave it up to you whether you want to do it this way or not. There is no right answer here. long_string = "This is a very long string that I want to split into batches of 10 characters."
def batched(iterable, n):
from itertools import islice
"""Batch data into lists of length *n*. The last batch may be shorter.
>>> list(batched('ABCDEFG', 3))
[('A', 'B', 'C'), ('D', 'E', 'F'), ('G',)]
On Python 3.12 and above, this is an alias for :func:`itertools.batched`.
"""
if n < 1:
raise ValueError('n must be at least one')
it = iter(iterable)
while True:
batch = tuple(islice(it, n))
if not batch:
break
yield batch
parts1 = [long_string[i:i+10] for i in range(0, len(long_string), 10)]
print(parts1)
parts2 = ["".join(batch) for batch in batched(long_string, 10)]
print(parts2)
assert parts1 == parts2 |
node_monitor/node_monitor.py
Outdated
if channels: | ||
err1 = self.slack_bot.send_messages(channels, message) | ||
err1 = self.slack_bot.send_messages(channels, subject, message) | ||
if preferences['notify_telegram'] == True: | ||
if self.telegram_bot: | ||
chats = telegram_chats.get(node_provider_id, []) | ||
if chats: | ||
err2 = self.telegram_bot.send_messages(chats, message) | ||
err2 = self.telegram_bot.send_messages(chats, subject, message) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the send_messages()
api the same as before, and instead concatenate the subject+message here, before the function gets called.
node_monitor/bot_telegram.py
Outdated
max_message_length = 4096 | ||
message_parts = textwrap.wrap(message, width=max_message_length) | ||
message_parts = [dispatch[i:i + max_message_length] for i in range(0, len(dispatch), max_message_length)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend defining and using batched
here, but i'll let you decide what you want to do. If you decide to keep it this way, please add a comment TODO: use itertools.batched here when python version is updated to >=3.12
.
If you decide to define batched
here, please add a comment TODO: delete this for itertools.batched when python version is updated to >=3.12
.
dispatch = f"{subject}\n\n{message}" | ||
if preferences['notify_email'] == True: | ||
recipients = email_recipients.get(node_provider_id, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Description
Fixes #128
Changes made
subject
argument tosend_message
functions in bothbot_slack.py
andbot_telegram.py
.Testing
Additional comments