Building a Sentiment Detection Bot with Google Cloud, a Chat Client, and Ruby.

Our next steps will be the following:Read any text sent to the botSend text to google for sentiment analysisReturn the sentiment score to the user via our botFirst, let’s make a function that detects and returns the sentiment of its input..We can do that with the following methods:These method are quite straightforward..“google_language_client” simply instantiates the client, and “get_sentiment” uses said client and returns the sentiment analysis of any viable text input.Lets change our “/post” route to the following:That settles it…Given all of your external services are set properly, you should be able to chat with your bot, and it returns the sentiment score of your text..Let’s try it out:Just returning a sentiment score is pretty boring for anyone unfortunate enough to interact with such a bot..Let’s give it a bit of personality.Let’s modify our main.rb file to the following:We made a few changes here..First we added some constants to hold our text responses, and we also added a new method “get_sentiment_response” which checks the sentiment score, and returns an appropriate reply..Let’s try it out:And there we have it!.Our bot can detect sentiment in a message, albeit with a limited vocabulary, and respond accordingly.In the next post in this series, we will give our bot the ability to understand the images we send it, by utilizing Google Cloud Vision API.. More details

Leave a Reply