前提・実現したいこと
LINEbotに複数のメッセージを返信させること。PythonとFlaskを使用。
公式ドキュメントは次の通り。
messagesにArray of とあるので、array型に入れてみたが、ダメだった。
タプル型でもダメだった
#Send reply message
Sends a reply message in response to an event from a user, group, or room.
To send reply messages, you must have a reply token which is included in a webhook event object.
Webhooks are used to notify you when an event occurs. For events that you can respond to, a reply token is issued for replying to messages.
Because the reply token becomes invalid after a certain period of time, responses should be sent as soon as a message is received. Reply tokens can only be used once.
#HTTP request
POST https://api.line.me/v2/bot/message/reply
#Request headers
Content-Type
application/json
Authorization
Bearer {channel access token}
#Request body
###replyToken
String Required
Reply token received via webhook
###messages
Array of message objects Required
Messages to send
Max: 5
###notificationDisabled
Boolean Optional
true: The user doesn't receive a push notification when the message is sent.
false: The user receives a push notification when the message is sent (unless they have disabled push notifications in LINE and/or their device).
Default: false
#Response
Returns status code 200 and an empty JSON object.
発生している問題・エラーメッセージ
LINEbotからの返答がない
該当のソースコード
Python3
1rom flask import Flask, request, abort 2import os 3 4from linebot import ( 5 LineBotApi, WebhookHandler 6) 7from linebot.exceptions import ( 8 InvalidSignatureError 9) 10from linebot.models import ( 11 MessageEvent, TextMessage, TextSendMessage, 12) 13 14app = Flask(__name__) 15 16# オリジナルの処理 17# line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN') 18# handler = WebhookHandler('YOUR_CHANNEL_SECRET') 19 20#環境変数取得 21YOUR_CHANNEL_ACCESS_TOKEN = 'PxQ8K7uaYUpJHNRK5PpnKIfeK5oZIAwJBMlgnKfQaRKax6oPNCHdnGo1jw71Lqan4ar7XAzQ3BWIS6POKWF23ZIhr/WjOkjV0VeozwlDmYI7ixJ3rsQG7Er2UUwKTOK1jgOfRFahTD8sKZoh/ncQagdB04t89/1O/w1cDnyilFU=' 22YOUR_CHANNEL_SECRET = 'e306c77e21315b35232da87cbefc45ad' 23 24line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN) 25handler = WebhookHandler(YOUR_CHANNEL_SECRET) 26 27@app.route("/callback", methods=['POST']) 28# the region of Flask. 29def callback(): 30 # get X-Line-Signature header value 31 signature = request.headers['X-Line-Signature'] 32 33 # get request body as text 34 body = request.get_data(as_text=True) 35 app.logger.info("Request body: " + body) 36 37 # handle webhook body 38 try: 39 handler.handle(body, signature) 40 except InvalidSignatureError: 41 abort(400) 42 43 return 'OK' 44 45# when a message comes from a user 46@handler.add(MessageEvent, message=TextMessage) 47def handle_message(event): 48 line_bot_api.reply_message( 49 event.reply_token, 50 TextSendMessage(text=#ここの形が分からない) 51 ) 52 53 54if __name__ == "__main__": 55 #app.run() 56 port = int(os.getenv("PORT")) 57 app.run(host="0.0.0.0",port=port)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。