前提・実現したいこと
LinebotでFlexmessageを使いたいのですが、SDKを参考にしてコードを書いてもうまくいきません。
まず、下の書き方は合っていますか?合っているのであれば、ただ単にFlexmessageを書くところにミスがあるだけ?
発生している問題・エラーメッセージ
Herokuでデブロイしても動かないです
該当のソースコード
from flask import Flask, request, abort from linebot import ( LineBotApi, WebhookHandler ) from linebot.exceptions import ( InvalidSignatureError ) from linebot.models import * import os app = Flask(__name__) #環境変数取得 YOUR_CHANNEL_ACCESS_TOKEN = os.environ["YOUR_CHANNEL_ACCESS_TOKEN"] YOUR_CHANNEL_SECRET = os.environ["YOUR_CHANNEL_SECRET"] line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN) handler = WebhookHandler(YOUR_CHANNEL_SECRET) @app.route("/callback", methods=['POST']) def callback(): # get X-Line-Signature header value signature = request.headers['X-Line-Signature'] # get request body as text body = request.get_data(as_text=True) app.logger.info("Request body: " + body) # handle webhook body try: handler.handle(body, signature) except InvalidSignatureError: abort(400) return 'OK' @handler.add(MessageEvent, message=TextMessage) def handle_message(event): text = event.message.text bubble = BubbleContainer( type = "bubble", direction='ltr', body=BoxComponent( type = "box", layout='vertical', contents=[ # title TextComponent(type = " text",text='Brown Cafe', weight='bold', size='xl') # review # info ] ), footer=BoxComponent( type = "box", layout='vertical', spacing='sm', contents=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction TextComponent(type = "text" ,text="kokoko") # separator SeparatorComponent() # websiteAction ] ) ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) if __name__ == "__main__": # app.run() port = int(os.getenv("PORT", 5000)) app.run(host="0.0.0.0", port=port)
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー