FB messenger doesn't yet have e2e encryption, so there hasn't yet been any need.
The code is a bit nightmarish, but it's hackable to do whatever you like. Whatsapp will ban you if they detect you using it, so make sure to update the client version numbers etc, and use a burner number for testing if using their live servers.
People already have done that. The most famous example is the yowsup [1] python library. The problem with these client implementations is that WhatsApp is banning any numbers that use them [2]. So most recent attempts to use WhatsApp outside of the official clients revolve around using WhatsApp Web somehow. That appears to work better, but even here if you are using it on a long term basis, WhatsApp might ban you.
Ultimately, WhatsApp is a bad host when it comes to using their service outside of the official app. This is really sad for people like me who don't want to install WhatsApp on their phones because it sends too much of my data to Facebook... probably that's precisely why they are so strict, to get all the data because that's all they get (the service is gratis after all). That and spam.
[1]: https://github.com/tgalal/yowsup [2]: http://google.com/search?q=yowsup+name+ban
but i would not recommend using it
https://github.com/tgalal/yowsup for example