Skip to content

Instantly share code, notes, and snippets.

@anchetaWern
Last active June 27, 2019 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchetaWern/2c37c6dda87e11f314a81d897d0f6792 to your computer and use it in GitHub Desktop.
Save anchetaWern/2c37c6dda87e11f314a81d897d0f6792 to your computer and use it in GitHub Desktop.
React Native Stream Chat Profanity Filtering: Filter out profanity
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