Last year I created a proof-of-concept solution that showed how to integrate Dynamics CRM with HP Haven OnDemand (then called HP IDOL OnDemand) to perform sentiment analysis and index records to support "find similar" queries. While I was working through the AzureCon challenge a few weeks ago, I thought it would be an interesting exercise to update my sentiment analysis code to work with the Text Analytics offering from the Microsoft Azure Marketplace.
As with my Haven OnDemand solution, the approach I'm using with Azure relies on a custom workflow activity that does the following:
- Parse a supplied text input and strip any HTML tags using a helper function.
- Create a JSON sentiment analysis request and post it to Azure Text Analytics with an HttpWebRequest.
- Deserialize the JSON respsonse returned by Azure Text Analytics to a custom class object using a DataContractJsonSerializer.
- Return the sentiment score to the calling process.
There are two main differences with the my Azure Text Analytics solution:
- The Azure service only returns a sentiment score, so this custom workflow activity doesn't return a positive/negative string value.
- Instead of embedding an access key in the custom workflow activity code, I've made it a parameter, which means you can take the solution straight from GitHub and start using it in your CRM organization as soon as you sign up for the Text Analytics service.
The solution in action
Here's a sample dialog I've created to demonstrate the use of the custom workflow activity.
Here's how the process works for the sample text "I hate you."
Wrapping it up on a more positive note, here's the same dialog with "I love you" instead.
As you can see, the score for "I hate you" is about .06, and the score for "I love you" is about .91, which makes sense as scores closer to one are more positive, and scores closer to zero are more negative.
You can download all the custom code and a CRM solution extract from my Crm-Sample-Code repository on GitHub. Let me know what you think in the comments!