【问题标题】:How to make carousel Flex Message in linebot如何在 linebot 中制作轮播 Flex 消息
【发布时间】:2020-05-30 12:59:09
【问题描述】:

我在 linebot 中的 flex 消息有问题,我正在尝试制作多个 Flex 消息,如轮播模板,我按照示例在阅读文档 here 后制作了两个案例。我在第一个案例中成功了,但是案例 2 不起作用。 顺便说一句,我在 Heroku 中部署了应用程序,在案例 2 中我得到了“status=200”,但没有任何响应。 我应该如何解决问题? 下面是我的代码: 案例一:

if event.message.text == 'test1':
     reply_header = {'Content-Type': 'application/json; charset=UTF-8',
                     'Authorization': 'Bearer ' +  'xxx'}
     reply_json = {
         "replyToken": event.reply_token,
         "messages": [
         {
             "type": "flex",
             "altText": "Flex Message",
             "contents": {
                 "type": "bubble",
                 "direction": "ltr",
                 "header": {
                     "type": "box",
                     "layout": "vertical",
                     "contents": [
                         {
                             "type": "text",
                             "text": "Header",
                             "align": "center"
                         }
                     ]
                 },
                 "hero": {
                     "type": "image",
                     "url": "https://developers.line.me/assets/images/services/bot-designer-icon.png",
                     "size": "full",
                     "aspectRatio": "1.51:1",
                     "aspectMode": "fit"
                 },
                 "body": {
                     "type": "box",
                     "layout": "vertical",
                     "contents": [
                         {
                             "type": "text",
                             "text": "Body",
                             "align": "center"
                         }
                     ]
                 },
                 "footer": {
                     "type": "box",
                     "layout": "horizontal",
                     "contents": [
                         {
                             "type": "button",
                             "action": {
                                 "type": "uri",
                                 "label": "Button",
                                 "uri": "https://linecorp.com"
                             }
                         }
                     ]
                 }
             }
         }
         ]
     }
     r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)

案例 2:

if event.message.text == 'test2':
        reply_header = {'Content-Type': 'application/json; charset=UTF-8',
                    'Authorization': 'Bearer ' +  'xxx'}
        reply_json = {
            "replyToken": event.reply_token,            
            "type": "carousel",
            "contents": [
              {
                "type": "bubble",
                "body": {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "First bubble"
                    }
                  ]
                }
              },
              {
                "type": "bubble",
                "body": {
                  "type": "box",
                  "layout": "vertical",
                  "contents": [
                    {
                      "type": "text",
                      "text": "Second bubble"
                    }
                  ]
                }
              }
            ]
        }
        r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)

【问题讨论】:

    标签: python-3.x heroku line-api


    【解决方案1】:

    在 Flex 消息中,altTexttypecontents 属性是必需的。 试试下面。

    {
       "type": "flex",
       "altText": "myCausouelMessage",
       "contents": {
            "type": "carousel",
            "contents": [put_your_carousel_array_json_contents]
        }
    }
    

    【讨论】:

    • flex 接管了常规的“模板”和“列”。谢谢你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2017-09-13
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    相关资源
    最近更新 更多