畑乃おいも / Hatano Oimo
182 字
1 分鐘
Line Bot 機器人 一次呼叫兩個模板
介紹
如果打”你好”需要一次呼叫兩個模板,在設計上可以設計成一個是給內容、一個給評分是滿好用的方法。
程式碼
使用 Flask 在 @app.route(“/callback”, methods=[‘POST’]) 下面寫一個函式,並 return(返回內容)
def myok(): carousel_template_message = FlexSendMessage( alt_text='porn template', contents={ "type": "carousel", "contents": [ { "type": "bubble", "body": { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "hello, world" } ] } } ] } )
aaccc = FlexSendMessage( alt_text='porn template', contents={ "type": "carousel", "contents": [ { "type": "bubble", "body": { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "hello, world" } ] } } ] } ) return [carousel_template_message, aaccc]訊息回應
在@handler.add(MessageEvent, message=TextMessage)底下寫一個判斷回應
call 上面寫好的函式 myok()
if event.message.text == "兩個物件": a = myok() line_bot_api.reply_message(event.reply_token, a)Line Bot 機器人 一次呼叫兩個模板
https://aishuafei.com/posts/line-bot-機器人-一次呼叫兩個模板/