When dealing with bots, a user is in very often in a position of giving out personal information. Keeping track of what personal data may be captured by the bot is therefore part of the normal development of bots. The Pre-logging script event can be used to anonymize personal data and in a way where the functionality of the bot is not affected. With the Pre-logging script we can
On this page, we will show you how to anonymize personal data with the following steps:
For this example, we will replace the value in Lib_sUserFirstName, which stores the users first name. This variable is located inside the Longberry Barista solution and comes together with the Teneo Dialogue Resources.
_.getDialogHistoryUtilities().replaceVariables(['Lib_sUserFirstName'], 'John Doe')
. This will automatically replace the variable value to 'John Doe' right before its starts logging it.This does not affect the functionality in your solution, the variable is replaced once the conversation is over and the tasks is done. This is also possible with Outputs, Metadata and much more. Please visit reference documentations for more details.
One other scenario where its powerful to use Pre-logging scripts is when you want to anonymize personal data. Teneo is powerful at recognizing different values of personal data thanks to the Named-entity recognizer and Part-of-speech annotation tags. In the following example we will go ahead and redact the names mentioned while communicating with our bot, using the PERSON.NER annotation tag.
Here's a list of the Part-of-speech (POS) and Named-entity recognition (NER) tags included in Teneo.
As a first step, we need to create a new Global variable that will store the values we want to redact:
toRedact
, and set its initial value to an empty list: []
. (Make sure to edit the "Value" field and not the "Description" field)Next in line is to add a Post-processing script to store the relevant values in the global variable we created in the previous step.
// Find names that have been mentioned by the user
_.inputAnnotations.getByName('PERSON.NER').each { person ->
def sentence = _.sentences[person.sentenceIndex]
def firstWord = sentence.words[person.wordIndices.first()]
def lastWord = sentence.words[person.wordIndices.last()]
def beginIndex = firstWord.beginIndex
def endIndex = lastWord.endIndex
// Select the items to redact
def itemToRedact = [
'historyIndex': _.dialogHistoryLength,
'beginIndex': beginIndex,
'endIndex': endIndex,
'value': sentence.text.substring(beginIndex, endIndex)
]
toRedact.add(itemToRedact)
}
The value to store can be changed by replacing the PERSON.NER in line 2, to any other Part-of-speech (POS) or Named-entity recognition (NER) tag.
Finally, we will add a Pre-logging script to redact the values stored in the global variable.
// Define the values
def values = [*toRedact.collect {it.value}, Lib_sUserFirstName]
// Replace output
_.dialogHistoryUtilities.replaceResponseText(values, '****')
// Replace input
_.dialogHistoryUtilities.replaceUserInputText(values, '****')
Make sure you return to Try Out and reload the engine before continuing on the next step
In order to see if our scripts work, you will need to publish your bot. Proceed as follows:
You might see a warning saying 'Publish to 'Default env' stopped with warnings. '
This is nothing to worry about; the warning is shown when you publish your solution for the first time or when you have made certain global changes. To proceed, just check the checkbox 'Perform full application deployment on Try again' and click the 'Try again' button.
The publication may take a couple of minutes; the video below is sped up slightly. When it has finished, you'll receive a confirmation pop-up.
Teneo Web Chat is also available in the Bots section in your team console. You need to publish the bot from Teneo Studio before using it.
Hi, my name is John Doe
Goodbye!
Now return to your Teneo Studio and open up Log Data Source to see if the name has been redacted.
A new window should now open. This is the Log Data window, described here. The next step is to open a new Session Viewer tab to retrieve the latest session.
You should see the following conversation. If not, please repeat the steps above.
Was this page helpful?