@botbuildercommunity/middleware-google-language
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Google Cloud Platform Natural Language API Middleware

The Google Cloud Platform Natural Language API Middleware offers Bot Framework middleware components for the Google Cloud Platform Natural Language API. You will need an Google Cloud account.

Installing

npm install @botbuildercommunity/middleware-google-language --save

Authentication

This package assumes that you have a Google Cloud Platform account. Your Google Cloud key needs to be stored on the filesystem (it's in a JSON file), and a GOOGLE_APPLICATION_CREDENTIALS environment variable should point to that file. See Google's quickstart guide for more information.

Usage

All middleware is created and used in the same way. For example, for sentiment analysis, import the SentimentAnalysis class from the package, and add it to your bot adapter:

import { SentimentAnalysis } from '@botbuildercommunity/middleware-google-cloud';

adapter.use(new SentimentAnalysis());

When used, the turnState on the TurnContext will have a property named sentimentScore between 0 and 1. A full example can be seen in the sample bot test file.

Supported middleware classes include:

  • SentimentAnalysis
  • CategoryExtraction
  • EntityExtraction

In each case, properties are added to the turnState of the TurnContext. You can retrieve them in your bot via:

  • context.turnState.get('sentimentScore') //This is a number for SentimentAnalysis
  • context.turnState.get('categoryEntities') //This is an array of object containing a name property and a confidence property for CategoryExtraction
  • context.turnState.get('textEntities') //This is an array of strings for EntityExtraction

Note that the CategoryExtraction middleware component might not return any values if the text is too little, or if the classification cannot find a match.

Dependents (0)

Package Sidebar

Install

npm i @botbuildercommunity/middleware-google-language

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

30.3 kB

Total Files

30

Last publish

Collaborators

  • jamesemann
  • cloudguy_pro
  • imick