PubNub Integration

Microsoft Azure | Content Moderator

Bots & AI

Bots & AI

Chat & Social

Chat & Social

External APIs

External APIs

In-app chat

In-app chat

Multiuser Spaces

Multiuser Spaces

Last Updated:

2020/08/07

Author:

PubNub, Inc.

APISign-upDocumentation

Machine-assisted content moderation that filters possible profanity and undesirable text.

Azure Text Moderation API is part of the Microsoft Azure Content Moderator cognitive service. Supporting over 100 languages, Azure Text Moderation API is used to scan text for offensive content, sexually explicit or suggestive content, profanity, and personal data. You can even scan text against a custom terms allowing moderation according to your own content policies.

Setup:

  1. Sign-up for a Microsoft Azure account and setup the Content Moderator API

  2. Sign-up for a PubNub account, if you don't have one already.

  3. Import the Integration Block into your PubNub account. You can choose to add this to an existing application or create a new one.

  4. Configure the Integration Block module code, connecting it to your Microsoft Azure account:

    1. Create a Secret in PubNub Vault, named AZURE_COGNITIVE_SERVICES_APIKEY, with value equal to your Azure API Key for this service.

    2. Update the API_URI to point to your Azure content moderation resource.

  5. Start the Integration Block module.

  6. Try a test message (you can click on Publish to do this).

Walkthrough:

This Integration Block is setup to listen to a specific PubNub channel (CHANNEL-to-moderate-Azure) but you can configure it to listen to all channels or a subset, using wildcards, e.g. chat.*. Thus, you can add content moderation capabilities even in private chats and other secure communication channels. The Integration Block is flexible in that it can be used both as part of a PubNub messaging flow, i.e. as part of publishing data, as well as accessed separately through a REST endpoint. Additionally, customization of capabilities can be done through publish message metadata or REST query parameters. In publish metadata, the customization properties are set as part of a JSON object specific for the function named azure-text-content-moderate.

  1. TEXT_LOCATION_ID: json dot notation for locating the text field in the message payload.

  2. OUTPUT_LOCATION_ID: json dot notation for locating the output data in the final message payload. Specify meta if you want the output data to be part of the metadata property of the message payload.

  3. AUTOCORRECT: direct configuration of the Azure API property

  4. DETECT_PII: direct configuration of the Azure API property

  5. CLASSIFY: direct configuration of the Azure API property; this is the language of the input text

  6. INPUT_LANGUAGE: direct configuration of the Azure API property; this is the target language into which the input text should be translated.

Input

Publish message containing message body to input channel. Input Channel: CHANNEL-to-translate-Google You can change this channel in the PubNub Administration Portal, using the Block's Function editor.

{ "text": "This is Awesome!"}

Output

The response from Google Translate API is included in the payload, or in the meta property of the published message.

{
	"text": "This is Awesome!",
	"translations": {
		"google": {
			"data": {
				"translations": [{
					"translatedText": "¡Esto es asombroso!",
					"model": "nmt"
				}]
			}
		}
	}
}

Feedback & Support

Need help? Contact PubNub Support.


Talk to an expert

Contact Sales