Inspired by the great @BofA_Help bot, a demonstration of how to use Twitter's Streaming API with sentiment analysis to get yourself in trouble


The code behind @BofA_Fan.

BankFan is a little proof-of-concept Twitter bot in the spirit of Bank of America's great @BofA_Help bot, which listens to a keyword stream and tweets replies, with ... results.

The bot currently listens for mentions of Bank of America, or BofA, and then does sentiment analysis based on the AFINN wordlist.

For instance, the tweet:

Protip:the @highmuseumofart is free 4 Bank of America users the 1st weekend of every month, & the new girl w/ a pearl earring exhib is great

... appears positive. Sentiment analysis confirms:



... and so BankFan responds positively, with a link to a news story about another great Bank of America initiative: their bots!

@screenName Bank of America really rocks.

Meanwhile, the tweet:

So the Bank of America ATM wants to play games w/me tonight & take all my money I worked for all day today & say it wasn't processed. Cool.

Is recognized as negative, because we've extended the wordlist with words like 'atm', 'checking', 'routing', etc. They need help, and we respond appropriately, alerting them to the fantastic automated @BofA_Help service!

@screenName maybe @BofA_Help has some input here?

This bot is definitely abuse under the Twitter Automation Best Practices, just like the original @Bofa_Help bot. Be advised that running it will probably get your account suspended every few hours unless you make the messages more diverse.

Well, of course you need a Twitter dev account. To run it, just add a file called that looks like:

module.exports =                                                                                     
  consumer_key: ''                                                                                   
  consumer_secret: ''                                                                                
  access_token: ''                                                                                   
  access_token_secret: ''                                                                            

You can fill in the values from any application in your account, where you will see those fields on the first page. Then run:


That the Twitter API changes a lot. Beware your library selection.

That Sentiment Analysis algorithms are more than 70% accurate, but that humans only agree about 80% of the time -- making them almost as good as humans, though even with the AFINN list, you can tell that tiny messages make it harder.

Oh, yeah, and something something social media customer service.