📜  Carousels rasa webchat - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:35.344000             🧑  作者: Mango

代码示例1
class ActionCarousel(Action):
    def name(self) -> Text:
        return "action_carousels"
    
    def run(self, dispatcher, tracker: Tracker, domain: "DomainDict") -> List[Dict[Text, Any]]:
        message = {
            "type": "template",
            "payload": {
                "template_type": "generic",
                "elements": [
                    {
                        "title": "Carousel 1",
                        "subtitle": "$10",
                        "image_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSqhmyBRCngkU_OKSL6gBQxCSH-cufgmZwb2w&usqp=CAU",
                        "buttons": [ 
                            {
                            "title": "Happy",
                            "payload": "Happy",
                            "type": "postback"
                            },
                            {
                            "title": "sad",
                            "payload": "sad",
                            "type": "postback"
                            }
                        ]
                    },
                    {
                        "title": "Carousel 2",
                        "subtitle": "$12",
                        "image_url": "https://image.freepik.com/free-vector/city-illustration_23-2147514701.jpg",
                        "buttons": [ 
                            {
                            "title": "Click here",
                            "url": "https://image.freepik.com/free-vector/city-illustration_23-2147514701.jpg",
                            "type": "web_url"
                            }
                        ]
                    }
                ]
                }
        }
        dispatcher.utter_message(attachment=message)
        return []