前提・実現したいこと
pythonで相手側のテキスト入力に反応してバブルメッセージを送るBOTを作ろうとしています
"た"のテキストメッセージに反応したいのですができません
発生している問題・エラーメッセージ
error=Error.new_from_json_dict(response.json)
該当のソースコード
from flask import Flask, request, abort
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import (MessageEvent, TextMessage, TextSendMessage, FlexSendMessage)
import os
import json
b = {
"type": "bubble",
"direction": "ltr",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "下から選んでね",
"weight": "bold",
"size": "lg",
"align": "center",
"gravity": "center",
"position": "absolute",
"contents": []
}
]
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "message",
"label": "米・雑穀・シリアル",
"text": "米・雑穀・シリアル"
}
},
{
"type": "separator"
},
{
"type": "button",
"action": {
"type": "message",
"label": "麺類",
"text": "麺類"
}
},
{
"type": "separator"
},
{
"type": "button",
"action": {
"type": "message",
"label": "野菜",
"text": "野菜"
}
},
{
"type": "separator"
},
{
"type": "button",
"action": {
"type": "message",
"label": "肉・肉加工品",
"text": "肉・肉加工品"
}
}
]
},
"styles": {
"header": {
"backgroundColor": "#EAB1B1FF",
"separator": True
},
"body": {
"backgroundColor": "#EAB1B1FF"
}
}
}
bubble = FlexSendMessage.new_from_json_dict(b)
YOUR_CHANNEL_ACCESS_TOKEN = ""
YOUR_CHANNEL_SECRET = ""
app = Flask(name)
line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(YOUR_CHANNEL_SECRET)
@app.route("/")
def test():
return "正常に稼働しています"
@app.route("/callback", methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
try:
handler.handle(body, signature)
except InvalidSignatureError:
print("Invalid signature. Please check your channel access token/channel secret.")
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
if 'た' in event.message.text:
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage(contents=bubble))
if name == "main":
app.run()
補足情報(FW/ツールのバージョンなど)
python3.8.2
windows10
あなたの回答
tips
プレビュー