In this example the Python library for Telegram is called telepot. You would need to install this on your Pico W, and it would need to work in MicroPython (which has the same syntax as Python 3, but not all features are available as this is built specifically for microcontrollers like the RP2040 and others). If you simply changed the word "telepot" to "telegram" in Thonny, then there is no such class or module that matches.
I used the Awesome MicroPython list to check for a Telegram library for MicroPython and there are at least two of them - search for "Telegram" here
https://awesome-micropython.com/
You'll need to install the library to your Pico W in the lib/ directory and then import it. I expect that it will have different features to the telepot library, so you'll probably need to update the other code.