As shown in this “Tell me a joke” example, the Google Assistant SDK sometimes includes emoji in the text response. Any ideas how to filter the emoji out of the text? I’ve been trying every form of regex_replace but can’t figure out a reliable way to detect emoji.
I somewhat answered my own question with the below regex. The regex doesn’t cover every edge case, but seems to cover the basic emoji that Google Assistant SDK is using.
Note that the code below sends two notifications - one with the raw text (including emoji) and one without. My version of print statement debugging.
- service: google_assistant_sdk.send_text_command
data:
command: Tell me a joke
response_variable: responses
- service: notify.mobile_app_pixel_7_pro
data:
title: Joke raw text
message: "{{ responses.responses[0].text }}"
enabled: true
- service: notify.mobile_app_pixel_7_pro
data:
title: Joke with emoji removed
message: >-
{% set regex_filter = "[^-\w\d\s!?,.:;']" %}
"{{ responses.responses[0].text | regex_replace(find=regex_filter,
replace='', ignorecase=False) }}"
1 Like
The following regex should work too: "[^\u1F600-\u1F6FF\s]"
By the way, you might be interested in http://github.com/tronikos/google_assistant_sdk_custom