-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Labels
Description
Description
UnicodeEncodeError is throwing when trying to send unicode characters with teams.j2 template
Why is this needed?
Using unicode characters emoji helps to create more attractive messages
Additional Information
I'm trying to send unicode characters in my teams.j2 template.
Unfortunately it does not work ans i can see the following message in the output log:
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f525' in position 769: Body ('π₯') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.Here is my teams.j2 template file:
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"style": "{% if status=='firing' %}attention{% elif status=='resolved' %}good{% else %}warning{% endif %}",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"weight": "Bolder",
"size": "ExtraLarge",
"color": "{% if status=='firing' %}attention{% elif status=='resolved' %}good{% else %}warning{% endif %}",
"text": "{% if status=='firing' %}π₯{% elif status=='resolved' %}β
{% else %}β οΈ{% endif %} Prometheus alert {% if status=='resolved' %}(Resolved){% elif status=='firing' %}(Firing){% elif status=='unknown' %}(Unknown){% else %}(Warning){% endif %}"
},
{
"type": "TextBlock",
"weight": "Bolder",
"size": "ExtraLarge",
"text": "{% if status=='resolved' %}(Resolved) {% endif %}{{ msg_text.summary }}",
"wrap": true
},
]
}
]
},
{
"type": "FactSet",
"facts": [
{ "title": "Status", "value": "{{ msg_text.status }} {% if status=='firing' %}π₯{% elif status=='resolved' %}β
{% else %}β οΈ{% endif %}" }
{% if msg_text.name %} , { "title": "Alert", "value": "{{ msg_text.name }}" } {% endif %}
{% if msg_text.instance %} , { "title": "In host", "value": "{{ msg_text.instance }}" } {% endif %}
{% if msg_text.severity %} , { "title": "Severity", "value": "{{ msg_text.severity }} {% if msg_text.severity=='critical' %}β{% elif msg_text.severity=='error' %}βοΈ{% elif msg_text.severity=='warning' %}β οΈ{% elif msg_text.severity=='info' %}βΉοΈ{% else %}β{% endif %}" } {% endif %}
{% if msg_text.description %} , { "title": "Description", "value": "{{ msg_text.description }}" } {% endif %}
{% if msg_text.extra_labels %}
{% for key in msg_text.extra_labels %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_labels[key] }}" }
{% endfor %}
{% endif %}
{% if msg_text.extra_annotations %}
{% for key in msg_text.extra_annotations %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_annotations[key] }}" }
{% endfor %}
{% endif %}
]
}
]
{% if msg_text.runbook_url %}
,
"actions": [
{
"type": "Action.OpenUrl",
"title": "View details",
"url": "{{ msg_text.runbook_url }}"
}
]
{% endif %}
}
}
]
}Reactions are currently unavailable