如何用 Python 做 telegram bot (機器人)
Step 0, 還不知道 telegram bot, 或 bot 幹嘛用的? 它大概的運作原理?
https://t.me/botfather (跟 botfather 聊聊天, 就知道大概功能)

測試我的 echo bot, 結果如下 (M)ming 是機器人.


Step 1. 申請一個 Telegram API token

Step 2.
git clone https://github.com/mingderwang/echo_bot_in_python.git
cd echo_bot_in_python
pip3 install -r requirements.txt
python3 main.py

記得先改你的 token 

API_TOKEN = 'xxxxxxxxxxxxxxx’

main.py
"""
This is a echo bot.
It echoes any incoming text messages.
"""

import logging

from aiogram import Bot, Dispatcher, executor, types

API_TOKEN = 'xxxxxxxxxxxxxxx'

# Configure logging
logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)


@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    """
    This handler will be called when user sends `/start` or `/help` command
    """
    await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")


@dp.message_handler(regexp='(^cat[s]?$|puss)')
async def cats(message: types.Message):
    with open('data/mat-reding-KeQb_jKAJoQ-unsplash.jpg', 'rb') as photo:
        '''
        # Old fashioned way:
        await bot.send_photo(
            message.chat.id,
            photo,
            caption='Cats are here 😺',
            reply_to_message_id=message.message_id,
        )
        '''

        await message.reply_photo(photo, caption='Cats are here 😺')


@dp.message_handler()
async def echo(message: types.Message):
    # old style:
    # await bot.send_message(message.chat.id, message.text)

    await message.answer(message.text)


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)