Spfx Field Customiser sample using Text Analytics API
This sample shows how to use the Text Analytics API (Cognitive Services) to render a sentiment icon based on the text of a field in the List. The language is also auto-detected using the API, so it works with text based in any language supported by the API.
Used SharePoint Framework Version
|react-field-text-analytics-api||Luis Mañez (MVP, ClearPeople, @luismanez)|
|1.0.0||January 7, 2018||Initial release|
|2.0.0||January 18, 2018||Language auto-detection added|
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
- Cognitive Services Text Analytics API Key (more info https://azure.microsoft.com/en-us/services/cognitive-services/)
Minimal Path to Awesome
- register a Cognitive Services Vision API in your Azure subscription
- create a List and add a Field called "SPFxSentimentIcon" (type: Number)
- clone repo
- update serve.json pointing to your List URL, Text Analytics API Key, and Field name to analyse
- run gulp serve --configuration=sentimentAnalytics
Sample SharePoint Framework list field customiser calling the Cognitive Services Text Analytics API and showing the sentiment of the Text with an Icon.
This sample illustrates the following concepts on top of the SharePoint Framework:
- using Text Analytics API to get the sentiment score from a given Text
- using async / await for the async calls
Depending on the number of items in the list, you could get a 429 Too Many Request response when calling the API.