質問編集履歴

1

更新しました。

2020/09/12 14:35

投稿

raspypy
raspypy

スコア247

test CHANGED
@@ -1 +1 @@
1
- Python LINE Messaging API
1
+ Python LINE
test CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- Line BOTプログラムを作成しています。
6
-
7
- 「おうむ返し」動作まで確認することができましたが、次のプログラムのコードを実行するとエラーが出てしまいます。
5
+ 次のプログラムのコードを実行するとエラーが出てしまいます。
8
6
 
9
7
 
10
8
 
@@ -48,168 +46,6 @@
48
46
 
49
47
  ```python
50
48
 
51
- import os
52
-
53
- import sys
54
-
55
- from linebot import (
56
-
57
- LineBotApi, WebhookHandler
58
-
59
- )
60
-
61
- from linebot.models import (
62
-
63
- MessageEvent, TextMessage, TextSendMessage,
64
-
65
- )
66
-
67
- from linebot.exceptions import (
68
-
69
- LineBotApiError, InvalidSignatureError
70
-
71
- )
72
-
73
-
74
-
75
- from linebot.models import (
76
-
77
- MessageEvent, TextMessage, TextSendMessage,
78
-
79
- SourceUser, SourceGroup, SourceRoom,
80
-
81
- TemplateSendMessage, ConfirmTemplate, MessageTemplateAction,
82
-
83
- ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URITemplateAction,
84
-
85
- PostbackTemplateAction, DatetimePickerTemplateAction,
86
-
87
- CarouselTemplate, CarouselColumn, PostbackEvent,
88
-
89
- StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage,
90
-
91
- ImageMessage, VideoMessage, AudioMessage, FileMessage,
92
-
93
- UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent
94
-
95
- )
96
-
97
-
98
-
99
- import logging
100
-
101
-
102
-
103
- logger = logging.getLogger()
104
-
105
- logger.setLevel(logging.ERROR)
106
-
107
-
108
-
109
- line_bot_api = LineBotApi('hogehogehoge')
110
-
111
- handler = WebhookHandler('hogesecret')
112
-
113
-
114
-
115
-
116
-
117
- def lambda_handler(event, context):
118
-
119
- signature = event["headers"]["X-Line-Signature"]
120
-
121
- body = event["body"]
122
-
123
- ok_json = {"isBase64Encoded": False,
124
-
125
- "statusCode": 200,
126
-
127
- "headers": {},
128
-
129
- "body": ""}
130
-
131
- error_json = {"isBase64Encoded": False,
132
-
133
- "statusCode": 403,
134
-
135
- "headers": {},
136
-
137
- "body": "Error"}
138
-
139
-
140
-
141
- @handler.add(MessageEvent, message=TextMessage)
142
-
143
- def message(line_event):
144
-
145
- text = line_event.message.text
146
-
147
- #botは停止中 (bot動作は確認済)
148
-
149
- #line_bot_api.reply_message(line_event.reply_token, TextSendMessage(text=text))
150
-
151
- if text == 'password':
152
-
153
- buttons_template = ButtonsTemplate(
154
-
155
- title='Title', text='選択してください。', actions=[
156
-
157
- PostbackTemplateAction(label='A', data='AAA'),
158
-
159
- PostbackTemplateAction(label='B', data='BBB'),
160
-
161
- PostbackTemplateAction(label='C', data='CCC'),
162
-
163
- PostbackTemplateAction(label='D', data='DDD'),
164
-
165
- ])
166
-
167
- template_message = TemplateSendMessage(
168
-
169
- alt_text='Buttons alt text', template=buttons_template)
170
-
171
- line_bot_api.reply_message(event.reply_token, template_message)
172
-
173
- else:
174
-
175
- line_bot_api.reply_message(
176
-
177
- event.reply_token, TextSendMessage(text='正しいパスワードを入力して下さい。'))
178
-
179
-
180
-
181
- @handler.add(PostbackEvent)
182
-
183
- def handle_postback(event):
184
-
185
- if event.postback.data == 'AAA':
186
-
187
- line_bot_api.reply_message(
188
-
189
- event.reply_token, TextSendMessage(text='AAA'))
190
-
191
- elif event.postback.data == 'BBB':
192
-
193
- line_bot_api.reply_message(
194
-
195
- event.reply_token, TextSendMessage(text='BBB'))
196
-
197
- elif event.postback.data == 'CCC':
198
-
199
- line_bot_api.reply_message(
200
-
201
- event.reply_token, TextSendMessage(text='CCC'))
202
-
203
- elif event.postback.data == 'DDD':
204
-
205
- line_bot_api.reply_message(
206
-
207
- event.reply_token, TextSendMessage(text='DDD'))
208
-
209
-
210
-
211
- try:
212
-
213
49
  handler.handle(body, signature)
214
50
 
215
51
  except LineBotApiError as e: