SMS Sentiment Analysis with Azure Text Analyzer
This example uses Azure Text Analyzer to analyze SMS messages and determine the sentiment of the text.
SMS Messages sent through Nexmo will be sent to Azure Text Analyzer and a series of scores and tones returned to the console.
Azure Text Analyzer
- Reference: https://azure.microsoft.com/en-us/services/cognitive-services/text-analytics/
- API Docs: https://westcentralus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v2-1/operations/56f30ceeeda5650db055a3c7
- GitHub: https://github.com/Azure/ms-rest-js
Sign up for Azure Text Analyzer and copy the
Subscription key and
Endpoint from the service
Quick Start page.
Running the App
This sample app uses a
.env file to provide the API key and URL.
Copy the provided
.env.example file to a new file called
cp .env.example > .env
Then update the values with those from the Azure Text Analyzer service
Quick Start page, and then save.
To run the app using Docker, run the following command in a terminal:
This will create a new image with all the dependencies and run it at http://localhost:3000.
To run the app using node, run the following command in a terminal:
npm install && node index.js
This will install all the dependencies and run it at http://localhost:3000.
Linking the app to Nexmo
For this example app a Nexmo number and SMS webhook setup is needed.
This can be achieved with the Nexmo CLI. Install the CLI by following these instructions.
Rent a New Virtual Number
Renting a number will need to be in place. This can also be achieved using the CLI by running this command:
nexmo number:buy --country_code US
Adding the SMS Webhook
Update the number created with the URL of the hosted or local server.
nexmo link:sms phone_number https://my-hostname/message
Try it out
With the example Node application running in the terminal, send various SMS messages to the virtual number. The terminal will output the response from Azure Text Analyzer.
This app prints out to the console. For integration with an application, extend the
analyzeTone function to suit your needs.