When Microsoft first launched its AI chatbot Tay it had no idea that it was heading for a PR nightmare.