-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (37 loc) · 1.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Import Packages
from config import *
from output.menu import make_menu
from linebot.models import (
MessageEvent, TextSendMessage,
TextMessage, StickerSendMessage, LocationMessage
)
@handler.add(MessageEvent, message=TextMessage)
def echo_text(event):
'''
Reply the text message.
'''
received_message = event.message.text
try:
if received_message in location_dict.keys():
loc = location_dict[received_message]
sent_message = TextSendMessage(text=make_menu(loc))
else:
sent_message = StickerSendMessage(package_id='6359', sticker_id='11069851')
except Exception as e:
sent_message = TextSendMessage(text=str(e))
line_bot_api.reply_message(event.reply_token, sent_message)
@handler.add(MessageEvent, message=LocationMessage)
def echo_location(event):
'''
Reply the location message.
'''
received_location = [event.message.longitude, event.message.latitude]
try:
sent_message = TextSendMessage(text=make_menu(received_location))
except Exception as e:
sent_message = TextSendMessage(text=str(e))
line_bot_api.reply_message(event.reply_token, sent_message)
# Main
if __name__ == "__main__":
port = int(os.getenv('PORT', 5000))
app.run(host='0.0.0.0', port=port)