如何在React native中根据类型在Gifted Chat中显示卡片转盘?

98 阅读1分钟

**如何迭代所有这些对象并获得所有?**它从Rasa bot获得响应。我想在React Native中使用Gifted Chat获取所有的对象并显示在卡片旋转轴上。我参考了这个developers.facebook.com/docs/messen…,但没有得到如何声明类型并从响应中获得所有对象,并在Gifted Chat的卡片传送带上显示。请帮助我解决这个问题。

Array [
          Object {
            "attachment": Object {
              "payload": Object {
                "elements": Array [
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/getEnergy",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/cycle.jpg",
                    "subtitle": "Boost Your Mood: These activities are designed to release happy hormones and leave you with an overall feeling of positivity. Doing them regularly will help you cultivate resilience and a general, positive outlook.",
                    "title": "Get Energy",
                  },
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/improveSelfEsteem",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/mountain.jpg",
                    "subtitle": "Build Strength: This meditation exercise is a powerful practice in mindfulness that helps us cultivate inner strength. Regular practice enables one to be strong in the face of chaos, change, or uncertainty.",
                    "title": "Improve Self-esteem",
                  },
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/forBreakups",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/feather.jpg",
                    "subtitle": "Find Closure: Work on getting closure through the simple method of writing down what you have never expressed or can't say to the ones you've lost.",
                    "title": "For Breakups",
                  },
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/forDeepSleep",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/sleep.jpg",
                    "subtitle": "Unable To Switch Off: This guided meditation will aid you in letting go of everyday thoughts, helping you switch off, relax and drift into a peaceful sleep.",
                    "title": "For Deep Sleep",
                  },
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/sleepStories",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/book.jpg",
                    "subtitle": "Sleep Story - The Mystical Fog",
                    "title": "Sleep Stories",
                  },
                  Object {
                    "buttons": Array [
                      Object {
                        "payload": "/sleepSounds",
                        "title": "Start",
                        "type": "postback",
                      },
                    ],
                    "image_url": "asset/images/book.jpg",
                    "subtitle": "Sleep Sound - Rain By The Porch",
                    "title": "Sleep Sounds",
                  },
                ],
                "template_type": "generic",
              },
              "type": "template",
            },
            "recipient_id": "UserId1",
          },
        ]