This repository has been archived by the owner on Nov 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
93 lines (73 loc) · 2.44 KB
/
app.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# coding: utf-8
from __future__ import unicode_literals
from __future__ import print_function
from chalicelib import (
app, line_bot_api, handler
)
from chalicelib import postback_events, text_message_events, aws_utils
from linebot.models import (
MessageEvent, JoinEvent, PostbackEvent, BeaconEvent,
TextMessage, TextSendMessage, ImageMessage
)
@app.route('/')
def index():
return 'pong'
@app.route("/callback", methods=['POST'])
def callback():
request = app.current_request
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
print('signature: ', signature)
# get request body as text
body = request.raw_body.decode('utf-8')
print('body: ', body)
handler.handle(body, signature)
return 'OK'
# ====================================
# Join
# ====================================
@handler.add(JoinEvent)
def handle_join(event):
msg = 'Joined this {}!\nみなさん、よろしくお願いします :)'.format(event.source.type)
line_bot_api.reply_message(event.reply_token, TextSendMessage(msg))
# ====================================
# Postback
# ====================================
@handler.add(PostbackEvent)
def handle_postback(event):
if event.postback.data == 'leave':
postback_events.postback_leave(event)
# ====================================
# Beacon
# ====================================
@handler.add(BeaconEvent)
def handle_beacon(event):
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text='Got beacon event. hwid=' + event.beacon.hwid))
# ====================================
# Message Event, TextMessage
# ====================================
plugins = [
text_message_events.greet,
text_message_events.weather,
text_message_events.choice,
text_message_events.shuffle,
text_message_events.omikuji,
text_message_events.today_news,
text_message_events.echo,
text_message_events.sudden_death,
text_message_events.wikipedia,
]
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
for plugin in plugins:
plugin(event)
# ====================================
# Message Event, ImageMessage
# ====================================
@handler.add(MessageEvent, message=ImageMessage)
def handle_content_message(event):
message_content = line_bot_api.get_message_content(event.message.id)
image_url = aws_utils.upload_to_s3(message_content)
print(image_url)