Untitled
unknown
python
2 years ago
1.9 kB
6
Indexable
@handler.add(PostbackEvent) def handle_message(event): print(event.postback.data) user_id = event.source.user_id data = event.postback.data # 在這裡根據按鈕回傳的資料進行處理 if data == 'positive': # 如果是正面評論,進行相應處理 user_states[user_id]['mode'] = 'positive' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected positive mode.')) elif data == 'negative': # 如果是負面評論,進行相應處理 user_states[user_id]['mode'] = 'negative' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected negative mode.')) elif data == 'happiness': user_states[user_id]['mood'] = 'happiness' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood happiness.')) elif data == 'sadness': user_states[user_id]['mood'] = 'sadness' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood sadness.')) elif data == 'anger': user_states[user_id]['mood'] = 'anger' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood anger.')) elif data == 'fear': user_states[user_id]['mood'] = 'fear' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood fear.')) elif data == 'surprise': user_states[user_id]['mood'] = 'surprise' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood surprise.')) elif data == 'disgust': user_states[user_id]['mood'] = 'disgust' line_bot_api.reply_message(event.reply_token, TextSendMessage(text='You selected mood disgust.')) else: # 其他情況 line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Unknown selection.'))
Editor is loading...
Leave a Comment