Skip to content
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

Add support to send Teams messages as HTML content #224

Merged
merged 3 commits into from
May 7, 2024

Conversation

pantherale0
Copy link

Hi,

Created this PR so that messages can be sent in HTML format alongside plain text. Text is set as the default, but can be overridden to html which will allow inserting html such as:

<b>Here is some bold text</b> and some that is not bold and finally here is a picture
<img src="...."/>

Also I've cleaned up CHAT_SERVICE_SEND_MESSAGE_SCHEMA as this had been defined three times which shouldn't be necessary.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pantherale0 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +468 to +477
content_type:
name: Content Type
description: The type of content to send, html if you are sending a HTML message or text for plain text
example: text
required: false
selector:
select:
mode: dropdown
options:
- label: HTML
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider marking 'content_type' as required if it's critical for message formatting.

If the content type is essential for the message to be formatted correctly, it might be better to enforce its specification by making it required.

@@ -168,15 +168,15 @@ def extra_state_attributes(self):
attributes[ATTR_DATA] = self.coordinator.data[self.entity_key][ATTR_DATA]
return attributes

def send_chat_message(self, chat_id, message):
def send_chat_message(self, chat_id, message, content_type="text"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Validate 'content_type' parameter to ensure it only accepts 'text' or 'html'.

Adding a validation step for 'content_type' can prevent errors from unsupported types and ensure that the function behaves as expected.

Suggested change
def send_chat_message(self, chat_id, message, content_type="text"):
def send_chat_message(self, chat_id, message, content_type="text"):
valid_content_types = ["text", "image", "video"]
if content_type not in valid_content_types:
raise ValueError("Unsupported content type")

@@ -148,6 +148,7 @@ target:
data:
chat_id: xxxxxxxxxxxxxxxxxxxxxxxxx
message: Hello world
content_type: text
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Update documentation to explain the optional nature of 'content_type' and its defaults.

Expanding the documentation to clarify when and how to use the 'content_type' field can enhance user understanding and correct usage of the API.

Suggested change
content_type: text
content_type: text
# The `content_type` field specifies the type of content being sent.
# Use this field to define the format of the message content.
# For example, 'text' indicates that the message content is plain text.

@RogerSelwyn RogerSelwyn merged commit 919a0a5 into RogerSelwyn:master May 7, 2024
4 checks passed
@RogerSelwyn
Copy link
Owner

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants