Last active
June 27, 2019 02:46
-
-
Save anchetaWern/2c37c6dda87e11f314a81d897d0f6792 to your computer and use it in GitHub Desktop.
React Native Stream Chat Profanity Filtering: Filter out profanity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { message } = JSON.parse(req.body); | |
const user = message.user; | |
const text = message.text; | |
const content = JSON.stringify([{ | |
'Text': text | |
}]); | |
const language = 'en'; | |
const filter_instance = axios.create(axios_base_instance_opt); | |
const profanity_action = 'Marked'; | |
const profanity_marker = 'Asterisk'; | |
const filter_response = await filter_instance.post( | |
`https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=${language}&profanityAction=${profanity_action}&profanityMarker=${profanity_marker}`, | |
content | |
); | |
const filtered_text = filter_response.data[0].translations[0].text; | |
// next: add code for updating message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment