Wiretapping telegraph lines was a known problem back then. Problem was... it was risky, detectable, and the tap always lead to the tapper. In some instances, all this could be circumvented by simply eavesdropping. If one could hear the telegraph clicking—and knew code—one could jot down the message, just like the telegraph employee.
This is how the problem was solved...