But as forenjunkie suggested, perhaps it indeed would be easier to pick some library, make a basic client providing D-Bus interface and no UI, and then proceed with that external UI.
On the other hand, using Gajim would still provide some advantages over the libraries that I've checked so far: those don't provide additional features such as encryption, and Gajim GUI would be used to have at hand for more advanced features than just a chat (i.e., chatting from Emacs, but using service discovery and such from Gajim).
AIUI, currently Gajim allows external programs (including gajim-remote) to send messages, but allowing them to read incoming messages as well would enable use cases like this.