Automatically analyze sentiment in text fields and add sentiment scores and categories to your Flatfile records
<field_name>_sentiment_score
and <field_name>_sentiment_category
. It also adds informational messages to the record detailing the outcome of the analysis. This is useful for automatically classifying customer feedback, product reviews, support tickets, or any other free-text data to quickly gauge user sentiment.
sheetSlug
(required)string
textFields
string[]
['description']
automaticValidation
boolean
false
, the plugin will add an info message to each record indicating that analysis is disabled but will not perform any analysis.false
- The analysis only runs if this is explicitly set to true
.errorMessages
object
enrichSentiment(config: EnrichSentimentConfig)
recordHook
with Flatfile that performs sentiment analysis on incoming records based on the provided configuration.
Parameters:
config
(EnrichSentimentConfig): An object containing configuration options
sheetSlug
(string): The slug of the sheet to targettextFields
(string[]): An array of field keys to analyze. Defaults to ['description']
automaticValidation
(boolean): Must be true
to enable analysis(listener: FlatfileListener) => void
which is used to install the plugin into a Flatfile listener.
analyzeSentiment(text: string)
text
(string): The input text to analyzescore
(number): A numerical score representing the sentiment. Positive values are positive, negative values are negativecategory
(‘positive’ | ‘negative’ | ‘neutral’): A string category for the sentimentperformEnrichSentiment(value: string, field: string)
analyzeSentiment
that includes basic validation and formats the output for use within a record hook. It checks for empty input and structures the return value with either an error or a result object.
Parameters:
value
(string): The text value from the record fieldfield
(string): The name of the field being analyzed, used for creating informative messages{ error: null, result: { score: number, category: string, message: string } }
{ error: string, result: null }
textFields
configuration is empty or null, the plugin will not throw an error. Instead, it will add a warning to the record using record.addWarning()
with a message like “No text found for sentiment analysis in field: [field_name]”.
automaticValidation
is set to false
or is omitted, the plugin will not perform any analysis or add any warnings. It will only add an informational message to the record stating that automatic analysis is disabled.
automaticValidation: true
to enable sentiment analysis.textFields
are specified, the plugin will default to analyzing the description
field.<field_name>_sentiment_score
: Contains the numerical sentiment score<field_name>_sentiment_category
: Contains the sentiment category (‘positive’, ‘negative’, or ‘neutral’)automaticValidation
(boolean), not autoAnalysis
.errorMessages
property in the EnrichSentimentConfig
type is defined but not currently implemented in the plugin’s logic.sentiment
npm package for its analysis logic.