Skip to content

Instantly share code, notes, and snippets.

@zaoldyeck
Last active June 21, 2018 14:42
Show Gist options
  • Save zaoldyeck/732aa347d3e2dc2fa747f3a1da57c846 to your computer and use it in GitHub Desktop.
Save zaoldyeck/732aa347d3e2dc2fa747f3a1da57c846 to your computer and use it in GitHub Desktop.
+from telegram import ReplyKeyboardMarkup
+from telegram.ext import Dispatcher, CommandHandler, MessageHandler, Filters
+
+welcome_message = '親愛的主人,您可以問我\n' \
+ '天氣,例如:「高雄天氣如何」\n' \
+ '百科,例如:「川普是誰」\n' \
+ '新聞,例如:「今日新聞」\n' \
+ '音樂,例如:「我想聽周杰倫的等你下課」\n' \
+ '日曆,例如:「現在時間」\n' \
+ '詩詞,例如:「我想聽水調歌頭這首詩」\n' \
+ '笑話,例如:「講個笑話」\n' \
+ '故事,例如:「說個故事」\n' \
+ '股票,例如:「台積電的股價」\n' \
+ '食譜,例如:「蛋炒飯怎麼做」\n' \
+ '聊天,例如:「你好嗎」'
+reply_keyboard_markup = ReplyKeyboardMarkup([['高雄天氣如何'],
+ ['川普是誰'],
+ ['今日新聞'],
+ ['我想聽周杰倫的等你下課'],
+ ['現在時間'],
+ ['我想聽水調歌頭這首詩'],
+ ['講個笑話'],
+ ['說個故事'],
+ ['台積電的股價'],
+ ['蛋炒飯怎麼做'],
+ ['你好嗎']])
+def start_handler(bot, update):
+ """Send a message when the command /start is issued."""
+ update.message.reply_text(welcome_message, reply_markup=reply_keyboard_markup)
+
+
+def help_handler(bot, update):
+ """Send a message when the command /help is issued."""
+ update.message.reply_text(welcome_message, reply_markup=reply_keyboard_markup)
+
+
+def error_handler(bot, update, error):
+ """Log Errors caused by Updates."""
+ logger.error('Update "%s" caused error "%s"', update, error)
+ update.message.reply_text('對不起主人,我需要多一點時間來處理 Q_Q')
+dispatcher.add_handler(CommandHandler('start', start_handler))
+dispatcher.add_handler(CommandHandler('help', help_handler))
+dispatcher.add_error_handler(error_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment