Telegraphy is the transmission of symbolic messages - for example, letters - without physically transferring an object. Early forms of telegraphy include smoke signals, the lighting of beacons, and semaphore.
The very first electrical telegraphs were invented in the 1700s, but given scientists’ limited understanding of electricity at that time, they didn’t get very far - it’s hard to get really excited about sending a message from one room to another. However, almost as soon as Alessandro Volta invented the voltaic pile in 1800 (the ancestor of what we call batteries) people started experimenting with longer-distance electrical communication.
One early system involved a set of 26 or so wires, connected to a collection of test tubes full of acid several kilometres away, one for each letter or other symbol they wanted to send. The wires caused electrolysis in the tubes, and the receiver would write down a letter every time one of them started producing hydrogen bubbles.
More practical systems started coming in around the 1830s, often using electromagnetic induction to deflect compass needles in order to point towards letters. In 1837, Samuel Morse created a recording telegraph, embossing dots and dashes onto a piece of paper using a needle, and created the Morse code to go with it.
Over the next couple of decades long-distance telegraph wires were installed across much of Europe and the USA. The first transatlantic cable was laid in 1857. It only worked for a few days, but the principle was sound! After a couple more attempts, a fully operational cable was laid in 1866.
To give some idea of what a difference instantaneous long-distance communication made, in 1860, the Pony Express was announced with great fanfare. It reduced the time it took to send post between New York and California to only ten days! Just fifteen years before, the journey took more like six months. The Pony Express was credited with helping connect California (which had only just joined the union) with the rest of the USA. In 1861, the first telegraphic cable was laid along the same route, and the Pony Express shut down.