Mx.Ada是一個理財機器人,主要目的是提供投資教育資源,幫助使用者提升投資知識和技能。以下是Mx.Ada提供的一些主要功能和資源:
from linebot import LineBotApi, WebhookHandler
from linebot.models import TextSendMessage, MessageEvent, TextMessage
from linebot.exceptions import LineBotApiError
line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
handler = WebhookHandler('YOUR_CHANNEL_SECRET')
# 定義處理訊息的函式
def handle_message(event):
user_message = event.message.text
# 判斷使用者輸入的指令
if user_message == '學習文章':
article_url = 'https://your-learning-article-url'
response_message = '請參考這篇投資學習文章:' + article_url
elif user_message == '教學影片':
video_url = 'https://your-tutorial-video-url'
response_message = '請觀看這個投資教學影片:' + video_url
else:
response_message = '抱歉,我不確定你在說什麼。'
# 回應訊息給使用者
try:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=response_message)
)
except LineBotApiError as e:
# 輸出錯誤訊息
print(e)
# 定義處理訊息的入口
@handler.add(MessageEvent, message=TextMessage)
def handle(event):
handle_message(event)
# 告訴 Line Bot 監聽 /callback 的路徑
@app.route("/callback", methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
try:
handler.handle(body, signature)
except LineBotApiError as e:
print(e)
return 'OK'
if __name__ == "__main__":
app.run()