text analytics recognition

Image source: Microsoft Cognitive Services, Text Analytics API https://www.microsoft.com/cognitive-services/en-us/text-analytics-api

In Part 2 of this blog series (Introduction to Face Recognition), we looked at how to invoke the Face API of the Microsoft Cognitive Services suite and its potential use cases when paired with Dynamics CRM.

In this article, we are going to discuss how to invoke the Text Analytics API and how to use it within Dynamics CRM.

Prerequisites to this article

If you have been following my blog series, then you should already have an account on Cognitive Services and a set of API keys handy. Otherwise, you can see instructions on how to obtain these in the Part 2 of this series.

Introduction to Text Analytics API

The Text Analytics API contains many features for you to leverage on and the below summarizes the individual APIs and what it could perform.

APIWhat It Could Perform
Sentiment AnalysisAccepts text content in 4 languages (English, French, Spanish, Portuguese) and returns a score between 0 & 1. The score is generated using text classification techniques.
Key Phrase ExtractionReturns a list of strings denoting the key talking points of the entered text using the Microsoft Office’s sophisticated natural language processing techniques which supports for English, German, Spanish & Japanese text.
Topic DetectionReturns a list of strings denoting topics detected within the text along with corresponding key phrases which are related to the topic. The API requires minimum of 100 text documents to be submitted.
Language DetectionReturns a language code and a score between 0 & 1 which indicates the certainty level of the detected language. Supports for 120 languages.

Calling API Functions within Dynamics CRM

The sample API function code which can be found within the API documentation uses the “HttpClient” library which doesn’t allow partially trusted callers. This might work for CRM On Premise, but if you are running CRM Online or wanting to write a custom plugin or workflow, the sample code will not work. Similarly, there are few other things to work out such technique to use for JSON serialisation/deserialization, etc.

I have done a few experiments recently, and “WebClient” library and NewtonSoft JSON library work well within Dynamics CRM SandBox environments such as Dynamics CRM Online.

Setting up Case Entity

For the below examples, I’ve written a plugin that fires on creation of a new Case which invokes the API to gather additional information. Once the information is gathered and written back onto the Case record, I then use an automatic case routing rule to route the case to a Manager’s queue if the sentiment score is less than 0.50.

Case Entity Form

case entity form

Setting up the Case Routing Rule

case routing rule


You can set up the Case routing rule by navigating to Settings > Service Management > Routing Rules.

The Plugin


Example – Analyse Case Description text using the API and returns the score


The “language” parameter is optional and is required if requesting sentiment analysis on non-English text. There are few limitations in this API such as the total text content size cannot exceed more than 1 MB, a single text document can only be a maximum of 10KB in size, and only 1000 individual text documents can be passed within 1 request. The API could be triggered for a single text document or per Case in this example, or the text content could be batched up as the API supports for 1000 text documents to be processed at a time.

Example 2 – Detect Language of Case


The same techniques in Example 1 have been used here and the result now contains additional information as to what the language is based on requested text content. The language detection passes back a score as well which denotes its confidence level in picking up the language.

Example 3 – Extract Key Phrases from Case Description


Like the previous example, this code returns the key phrases detected in the input text content which can be stored back in the CRM Case.

Result – Processed Case

Based on the example plugin, once the Case is saved the text characteristics are filled in automatically by using the Cognitive Services API, and the routing rule routes the case to the Manager’s queue as per the received sentiment score.

cognitive services api

cognitive services api 2

Hope this article gave you an insight on how to get started by creating a simple plugin and logic within Dynamics CRM to detect characteristics of text content of a Case in CRM.

Stay tuned for the next article in this blog series to learn more about the capabilities of Microsoft Cognitive Services.

Read More:

Introduction to Cognitive Services

Facial Recognition in CRM