接收 Line Bot 消息
handler
中接收並處理這些事件:
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
# 回應用戶發送的訊息
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=event.message.text))
實現基本自動回覆
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
user_msg = event.message.text
if user_msg == "Hello":
reply = "Hi there!"
else:
reply = "I don't understand."
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=reply))
測試消息接收與發送