Как сделать Flex Message карусели в лайн-боте - PullRequest
0 голосов
/ 30 мая 2020

У меня проблема с гибким сообщением в лайн-боте, я пытаюсь создать несколько гибких сообщений, таких как шаблон карусели, я следую примеру и сделал два случая после того, как прочитал документ здесь . И в первом случае мне это удалось, но второй вариант не работает. Кстати, я развертываю приложение в Heroku и в случае 2 получил «status = 200», но ничего не отвечает. Как мне решить проблему? Вот мой код ниже: Случай 1:

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)

1 Ответ

0 голосов
/ 23 июля 2020

В сообщении Flex обязательны атрибуты altText, type и contents. попробуйте ниже.

{
   "type": "flex",
   "altText": "myCausouelMessage",
   "contents": {
        "type": "carousel",
        "contents": [put_your_carousel_array_json_contents]
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...