質問編集履歴
2
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Pythonプログラムについて
|
body
CHANGED
@@ -5,20 +5,7 @@
|
|
5
5
|
プログラムの意味を理解できない箇所があります。
|
6
6
|
プログラムの中身を理解したいので教えていただけると助かります。
|
7
7
|
|
8
|
-
|
8
|
+
|
9
|
-
次の部分の意味を理解できていません。
|
10
|
-
ok_jsonとerror_jsonの部分です。
|
11
|
-
```python
|
12
|
-
signature = event["headers"]["X-Line-Signature"]
|
13
|
-
body = event["body"]
|
14
|
-
ok_json = {"isBase64Encoded": False,
|
15
|
-
"statusCode": 200,
|
16
|
-
"headers": {},
|
17
|
-
"body": ""}
|
18
|
-
error_json = {"isBase64Encoded": False,
|
19
|
-
"statusCode": 403,
|
20
|
-
"headers": {},
|
21
|
-
"body": "Error"}
|
22
9
|
```
|
23
10
|
|
24
11
|
**その2**
|
@@ -28,50 +15,4 @@
|
|
28
15
|
|
29
16
|
**その3**
|
30
17
|
次の部分の意味を理解できていません。
|
31
|
-
この部分の処理について解説していただけると助かります。
|
18
|
+
この部分の処理について解説していただけると助かります。
|
32
|
-
```python
|
33
|
-
try:
|
34
|
-
handler.handle(body, signature)
|
35
|
-
except LineBotApiError as e:
|
36
|
-
logger.error("Got exception from LINE Messaging API: %s\n" % e.message)
|
37
|
-
for m in e.error.details:
|
38
|
-
logger.error(" %s: %s" % (m.property, m.message))
|
39
|
-
return error_json
|
40
|
-
except InvalidSignatureError:
|
41
|
-
return error_json
|
42
|
-
|
43
|
-
return ok_json
|
44
|
-
```
|
45
|
-
|
46
|
-
|
47
|
-
##プログラムコード(全体)
|
48
|
-
```python
|
49
|
-
def lambda_handler(event, context):
|
50
|
-
signature = event["headers"]["X-Line-Signature"]
|
51
|
-
body = event["body"]
|
52
|
-
ok_json = {"isBase64Encoded": False,
|
53
|
-
"statusCode": 200,
|
54
|
-
"headers": {},
|
55
|
-
"body": ""}
|
56
|
-
error_json = {"isBase64Encoded": False,
|
57
|
-
"statusCode": 403,
|
58
|
-
"headers": {},
|
59
|
-
"body": "Error"}
|
60
|
-
|
61
|
-
@handler.add(MessageEvent, message=TextMessage)
|
62
|
-
def message(line_event):
|
63
|
-
text = line_event.message.text
|
64
|
-
#bot動作
|
65
|
-
line_bot_api.reply_message(line_event.reply_token, TextSendMessage(text=text))
|
66
|
-
try:
|
67
|
-
handler.handle(body, signature)
|
68
|
-
except LineBotApiError as e:
|
69
|
-
logger.error("Got exception from LINE Messaging API: %s\n" % e.message)
|
70
|
-
for m in e.error.details:
|
71
|
-
logger.error(" %s: %s" % (m.property, m.message))
|
72
|
-
return error_json
|
73
|
-
except InvalidSignatureError:
|
74
|
-
return error_json
|
75
|
-
|
76
|
-
return ok_json
|
77
|
-
```
|
1
間違えてアップしてしまったので、訂正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,8 @@
|
|
6
6
|
プログラムの中身を理解したいので教えていただけると助かります。
|
7
7
|
|
8
8
|
**その1**
|
9
|
-
次の部分
|
9
|
+
次の部分の意味を理解できていません。
|
10
|
+
ok_jsonとerror_jsonの部分です。
|
10
11
|
```python
|
11
12
|
signature = event["headers"]["X-Line-Signature"]
|
12
13
|
body = event["body"]
|
@@ -20,9 +21,31 @@
|
|
20
21
|
"body": "Error"}
|
21
22
|
```
|
22
23
|
|
24
|
+
**その2**
|
25
|
+
@handler.add(MessageEvent, message=TextMessage)
|
26
|
+
**@**をつけているのは、どういう意味があるのでしょうか?
|
23
27
|
|
28
|
+
|
24
|
-
|
29
|
+
**その3**
|
30
|
+
次の部分の意味を理解できていません。
|
31
|
+
この部分の処理について解説していただけると助かります。
|
25
32
|
```python
|
33
|
+
try:
|
34
|
+
handler.handle(body, signature)
|
35
|
+
except LineBotApiError as e:
|
36
|
+
logger.error("Got exception from LINE Messaging API: %s\n" % e.message)
|
37
|
+
for m in e.error.details:
|
38
|
+
logger.error(" %s: %s" % (m.property, m.message))
|
39
|
+
return error_json
|
40
|
+
except InvalidSignatureError:
|
41
|
+
return error_json
|
42
|
+
|
43
|
+
return ok_json
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
##プログラムコード(全体)
|
48
|
+
```python
|
26
49
|
def lambda_handler(event, context):
|
27
50
|
signature = event["headers"]["X-Line-Signature"]
|
28
51
|
body = event["body"]
|