質問編集履歴
4
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,6 +80,12 @@
|
|
80
80
|
|
81
81
|
```python
|
82
82
|
|
83
|
+
#!/usr/local/bin/python3.4
|
84
|
+
|
85
|
+
print("Content-type: text/plain\n")
|
86
|
+
|
87
|
+
|
88
|
+
|
83
89
|
# -*- coding: utf-8 -*-
|
84
90
|
|
85
91
|
|
3
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -69,3 +69,237 @@
|
|
69
69
|
|
70
70
|
|
71
71
|
よろしくお願いします。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
追記:
|
78
|
+
|
79
|
+
一部省略しながらですがコードを載せます。
|
80
|
+
|
81
|
+
```python
|
82
|
+
|
83
|
+
# -*- coding: utf-8 -*-
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
88
|
+
|
89
|
+
# not use this file except in compliance with the License. You may obtain
|
90
|
+
|
91
|
+
# a copy of the License at
|
92
|
+
|
93
|
+
#
|
94
|
+
|
95
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
96
|
+
|
97
|
+
#
|
98
|
+
|
99
|
+
# Unless required by applicable law or agreed to in writing, software
|
100
|
+
|
101
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
102
|
+
|
103
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
104
|
+
|
105
|
+
# License for the specific language governing permissions and limitations
|
106
|
+
|
107
|
+
# under the License.
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
from __future__ import unicode_literals
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
import errno
|
116
|
+
|
117
|
+
import os
|
118
|
+
|
119
|
+
import sys
|
120
|
+
|
121
|
+
import tempfile
|
122
|
+
|
123
|
+
import requests
|
124
|
+
|
125
|
+
import random
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
from argparse import ArgumentParser
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
from flask import Flask, request, abort
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
from linebot import (
|
138
|
+
|
139
|
+
LineBotApi, WebhookHandler
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
from linebot.exceptions import (
|
144
|
+
|
145
|
+
InvalidSignatureError
|
146
|
+
|
147
|
+
)
|
148
|
+
|
149
|
+
from linebot.models import (
|
150
|
+
|
151
|
+
MessageEvent, TextMessage, TextSendMessage,
|
152
|
+
|
153
|
+
SourceUser, SourceGroup, SourceRoom,
|
154
|
+
|
155
|
+
TemplateSendMessage, ConfirmTemplate, MessageTemplateAction,
|
156
|
+
|
157
|
+
ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URITemplateAction,
|
158
|
+
|
159
|
+
PostbackTemplateAction, DatetimePickerTemplateAction,
|
160
|
+
|
161
|
+
CarouselTemplate, CarouselColumn, PostbackEvent,
|
162
|
+
|
163
|
+
StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage,
|
164
|
+
|
165
|
+
ImageMessage, VideoMessage, AudioMessage, FileMessage,
|
166
|
+
|
167
|
+
UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent,
|
168
|
+
|
169
|
+
ImageSendMessage
|
170
|
+
|
171
|
+
)
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
import (省略)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
app = Flask(__name__)
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
# get channel_secret and channel_access_token from your environment variable
|
184
|
+
|
185
|
+
channel_secret = os.getenv('LINE_CHANNEL_SECRET', '(省略)')
|
186
|
+
|
187
|
+
channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', '(省略)')
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
line_bot_api = LineBotApi(channel_access_token)
|
192
|
+
|
193
|
+
handler = WebhookHandler(channel_secret)
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
static_tmp_path = os.path.join(os.path.dirname(__file__), 'static', 'tmp')
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
godparent = godparent.godparent()
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
# function for create tmp dir for download content
|
206
|
+
|
207
|
+
def make_static_tmp_dir():
|
208
|
+
|
209
|
+
try:
|
210
|
+
|
211
|
+
os.makedirs(static_tmp_path)
|
212
|
+
|
213
|
+
except OSError as exc:
|
214
|
+
|
215
|
+
if exc.errno == errno.EEXIST and os.path.isdir(static_tmp_path):
|
216
|
+
|
217
|
+
pass
|
218
|
+
|
219
|
+
else:
|
220
|
+
|
221
|
+
raise
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
@app.route("/callback", methods=['POST'])
|
226
|
+
|
227
|
+
def callback():
|
228
|
+
|
229
|
+
# get X-Line-Signature header value
|
230
|
+
|
231
|
+
signature = request.headers['X-Line-Signature']
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
# get request body as text
|
236
|
+
|
237
|
+
body = request.get_data(as_text=True)
|
238
|
+
|
239
|
+
app.logger.info("Request body: " + body)
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
# handle webhook body
|
244
|
+
|
245
|
+
try:
|
246
|
+
|
247
|
+
handler.handle(body, signature)
|
248
|
+
|
249
|
+
except InvalidSignatureError:
|
250
|
+
|
251
|
+
abort(400)
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
return 'OK'
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
@handler.add(MessageEvent, message=TextMessage)
|
260
|
+
|
261
|
+
def handle_text_message(event):
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
response_message = (省略).update(event.message.text)
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
line_bot_api.reply_message(
|
270
|
+
|
271
|
+
event.reply_token, TextSendMessage(response_message))
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
return 0
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
if __name__ == "__main__":
|
280
|
+
|
281
|
+
arg_parser = ArgumentParser(
|
282
|
+
|
283
|
+
usage='Usage: python ' + __file__ + ' [--port <port>] [--help]'
|
284
|
+
|
285
|
+
)
|
286
|
+
|
287
|
+
arg_parser.add_argument('-p', '--port', type=int, default=443, help='port')
|
288
|
+
|
289
|
+
arg_parser.add_argument('-d', '--debug', default=False, help='debug')
|
290
|
+
|
291
|
+
options = arg_parser.parse_args()
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
# create tmp dir for download content
|
296
|
+
|
297
|
+
make_static_tmp_dir()
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
app.run(debug=options.debug, port=options.port)
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,11 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
+
試しましたが、全て
|
64
|
+
|
63
|
-
|
65
|
+
"Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)"
|
66
|
+
|
67
|
+
と表示されます。
|
64
68
|
|
65
69
|
|
66
70
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,11 +60,7 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
試しましたが、全て
|
64
|
-
|
65
|
-
Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)
|
63
|
+
試しましたが、全て"Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)"と表示されます。
|
66
|
-
|
67
|
-
と表示されます。
|
68
64
|
|
69
65
|
|
70
66
|
|