iT邦幫忙

2021 iThome 鐵人賽

DAY 19
1
永豐金融APIs

理財達人Mx. Ada系列 第 19

[第19天]理財達人Mx. Ada-Telegram Bot

前言

本文說明使用Python建立Telegram Bot 。

註冊 telegram帳號

找 @BotFather 申請一個 Bot

https://ithelp.ithome.com.tw/upload/images/20211003/20107143KIKKgme6Sq.png

  1. /newbot
  2. 輸入名稱:Mx_AdaBot
  3. 輸入 username:Mx_Ada_Bot
  4. 記下 token
    https://ithelp.ithome.com.tw/upload/images/20211003/20107143IwDrBfLZKS.png

安裝python-telegram-bot

pip install python-telegram-bot --upgrade

程式實作

from telegram.ext import Updater, CommandHandler

def start(bot, update) -> None:
    update.message.reply_text('Hello World, Bot Start')

def main() -> None:
	# 創建一個Updater,並填入所申請之API TOKEN
	updater = Updater("YOUR API TOKEN")
	# 讓dispatcher註冊一個 handlers
	updater.dispatcher.add_handler(CommandHandler("start", start))
	# 啟始Bot
	updater.start_polling()
    # 按Ctrl + C進行終止Bot 
	updater.idle()

if __name__ == '__main__':
    main()

小結

利用python-telegram-bot模組,進行建立一個Telegram Bot。


上一篇
[第18天]理財達人Mx. Ada-證券扣款帳戶銀行餘額資訊
下一篇
[第20天]理財達人Mx. Ada-Telegram Bot-echo測試
系列文
理財達人Mx. Ada30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言