Skip to content

Instantly share code, notes, and snippets.

@vadim-berman
Created November 26, 2018 04:48
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 vadim-berman/de11c71c247be8abdc85a155063d8226 to your computer and use it in GitHub Desktop.
Save vadim-berman/de11c71c247be8abdc85a155063d8226 to your computer and use it in GitHub Desktop.
Detecting abuse in an inbound PubNub message
export default (request) => {
const xhr = require('xhr');
console.log('1. original', request.message);
{
return xhr.fetch('https://api.tisane.ai/parse', {
'method' : 'POST',
'headers' : {
'Ocp-Apim-Subscription-Key': '{your subscription key}'
},
'body': JSON.stringify({
'language': 'en', // or whatever language you use
'content': request.message,
'settings': {'snippets': true} // the "snippets" setting places the relevant text snippets in the response; by default, only the offset and the length are sent
}),
'timeout' : 5000
}); }
.then((reply) => {
var responseJson = JSON.parse(reply.body);
if (responseJson.abuse) {
// enrich the message with the relevant information
request.abuse_text = responseJson.abuse.text;
request.abuse_type = responseJson.abuse.type;
console.log('2. possible abuse found', responseJson.abuse.type);
return request.abort(); // return back to the sender
}
else
return request.ok();
}).catch((err) => {
console.error(err);
return request.abort();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment