async def on_teams_messaging_extension_query(
            self, turn_context: TurnContext, query: MessagingExtensionQuery):
        search_query = str(query.parameters[0].value).strip()
        if search_query == "":
            await turn_context.send_activity(
                MessageFactory.text(
                    "You cannot enter a blank string for the search"))
            return

        search_results = self._get_search_results(search_query)

        attachments = []
        for obj in search_results:
            hero_card = HeroCard(title=obj["name"],
                                 tap=CardAction(type="invoke", value=obj))

            attachment = MessagingExtensionAttachment(
                content_type=CardFactory.content_types.hero_card,
                content=HeroCard(title=obj["name"]),
                preview=CardFactory.hero_card(hero_card),
            )
            attachments.append(attachment)
        return MessagingExtensionResponse(
            compose_extension=MessagingExtensionResult(
                type="result",
                attachment_layout="list",
                attachments=attachments))
Exemplo n.º 2
0
    async def on_teams_messaging_extension_query(
            self, turn_context: TurnContext, query: MessagingExtensionQuery):
        search_query = str(query.parameters[0].value)
        response = requests.get(f"http://registry.npmjs.com/-/v1/search",
                                params={"text": search_query})
        data = response.json()

        attachments = []

        for obj in data["objects"]:
            hero_card = HeroCard(
                title=obj["package"]["name"],
                tap=CardAction(type="invoke", value=obj["package"]),
                preview=[CardImage(url=obj["package"]["links"]["npm"])])

            attachment = MessagingExtensionAttachment(
                content_type=CardFactory.content_types.hero_card,
                content=HeroCard(title=obj["package"]["name"]),
                preview=CardFactory.hero_card(hero_card))
            attachments.append(attachment)
        return MessagingExtensionResponse(
            compose_extension=MessagingExtensionResult(
                type="result",
                attachment_layout="list",
                attachments=attachments))
Exemplo n.º 3
0
    def _create_select_items_result_attachment(
            self, search_query: str) -> MessagingExtensionAttachment:
        card_text = f"You said {search_query}"
        bf_logo = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU"

        buttons = CardAction(
            type="openUrl",
            title="Click for more Information",
            value=
            "https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-overview"
        )

        images = [CardImage(url=bf_logo)]
        buttons = [buttons]

        select_item_tap = CardAction(type="invoke",
                                     value={"query": search_query})

        hero_card = HeroCard(title="You searched for:",
                             text=card_text,
                             images=images,
                             buttons=buttons)

        preview = HeroCard(title=card_text,
                           text=card_text,
                           images=images,
                           tap=select_item_tap)

        return MessagingExtensionAttachment(
            content_type=CardFactory.content_types.hero_card,
            content=hero_card,
            preview=CardFactory.hero_card(preview))
Exemplo n.º 4
0
    def test_conversations_send_to_conversation_with_attachment(self):
        card1 = HeroCard(
            title="A static image",
            text="JPEG image",
            images=[
                CardImage(
                    url="https://docs.com/en-us/bot-framework/media/designing-bots/core/dialogs-screens.png"
                )
            ],
        )

        card2 = HeroCard(
            title="An animation",
            subtitle="GIF image",
            images=[CardImage(url="http://i.giphy.com/Ki55RUbOV5njy.gif")],
        )

        activity = Activity(
            type=ActivityTypes.message,
            channel_id=CHANNEL_ID,
            recipient=ChannelAccount(id=RECIPIENT_ID),
            from_property=ChannelAccount(id=BOT_ID),
            attachment_layout=AttachmentLayoutTypes.list,
            attachments=[
                Attachment(content_type="application/vnd.card.hero", content=card1),
                Attachment(content_type="application/vnd.card.hero", content=card2),
            ],
        )

        connector = ConnectorClient(self.credentials, base_url=SERVICE_URL)
        response = self.loop.run_until_complete(
            connector.conversations.send_to_conversation(CONVERSATION_ID, activity)
        )

        assert response is not None
Exemplo n.º 5
0
    def create_wishlist_card(self, books: List):
        card = HeroCard(title="La tua wishlist")
        attachments = []
        attachments.append(CardFactory.hero_card(card))
        text = ""
        flag = False
        for book in books:
            flag = True
            if book.author is not None:
                text += "{} di {}\n\n".format(book.name, book.author)
            else:
                text += "{}\n\n".format(book.name)
            text += "Genere: {}\n".format(book.genre)
            text += "Nome del sito: {} \n".format(book.site)
            if book.price is not None:
                text += "Prezzo: {}€ \n".format(book.price)
            else:
                text += "Prezzo non disponibile.\n"
            text += "Disponibilità: {} \n".format(book.availability)
            text += "Link per l'acquisto: {} \n".format(book.link)
            attachments.append(CardFactory.hero_card(HeroCard(text=text)))
            text = ""

        if flag:
            activity = MessageFactory.carousel(attachments)
            return (activity, True)
        else:
            new_card = HeroCard(
                title="La tua wishlist è vuota",
                subtitle=
                '''Non puoi eseguire nessuna operazione. Puoi cercare un libro ed aggiungerlo. Ti riporto al menù principale. '''
            )
            attachments.append(CardFactory.hero_card(new_card))
            activity = MessageFactory.carousel(attachments)
            return (activity, False)
Exemplo n.º 6
0
    def _create_dummy_search_result_attachment(
            self) -> MessagingExtensionAttachment:
        card_text = "https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-overview"
        bf_logo = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU"

        button = CardAction(
            type="openUrl",
            title="Click for more Information",
            value=
            "https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-overview"
        )

        images = [CardImage(url=bf_logo)]

        buttons = [button]

        hero_card = HeroCard(title="Learn more about Teams:",
                             text=card_text,
                             images=images,
                             buttons=buttons)

        preview = HeroCard(title="Learn more about Teams:",
                           text=card_text,
                           images=images)

        return MessagingExtensionAttachment(
            content_type=CardFactory.content_types.hero_card,
            content=hero_card,
            preview=CardFactory.hero_card(preview))
Exemplo n.º 7
0
    async def __send_docs_card(self, turn_context: TurnContext):
        card = HeroCard(
            title="ADC DOCS!!",
            text="Click to browse the docs",
            images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
            buttons=[
                CardAction(
                    type=ActionTypes.open_url,
                    title="Bot factory share point",
                    text="Browse to explore the sharepoint",
                    display_text="Browse to explore the sharepoint",
                    value=
                    "https://capgemini.sharepoint.com/sites/BOTfactory/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2FBOTfactory%2FShared%20Documents&newTargetListUrl=%2Fsites%2FBOTfactory%2FShared%20Documents&viewpath=%2Fsites%2FBOTfactory%2FShared%20Documents%2FForms%2FAllItems%2Easpx",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Effort Tracker",
                    text="Browse to fill youe daily efforts",
                    display_text="Browse to fill youe daily efforts",
                    value=
                    "https://apps.powerapps.com/play/2ad7c8fa-550e-44c5-af65-d6a29c0bb39e?tenantId=76a2ae5a-9f00-4f6b-95ed-5d33d77c4d61",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Jira",
                    text="Browse to access Jira",
                    display_text="Browse to access Jira",
                    value="http://10.58.144.45/pm/login.jsp",
                ),
            ],
        )

        return await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(card)))
Exemplo n.º 8
0
    async def __send_intro_card(self, turn_context: TurnContext):
        card = HeroCard(
            title=f"안녕하세요 {turn_context.activity.from_property.name} 님",
            text="",
            images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
            buttons=[
                CardAction(
                    type=ActionTypes.open_url,
                    title="Get an overview",
                    text="Get an overview",
                    display_text="Get an overview",
                    value="https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Ask a question",
                    text="Ask a question",
                    display_text="Ask a question",
                    value="https://stackoverflow.com/questions/tagged/botframework",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Learn how to deploy",
                    text="Learn how to deploy",
                    display_text="Learn how to deploy",
                    value="https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0",
                ),
            ],
        )

        return await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(card))
        )
Exemplo n.º 9
0
    async def __send_intro_card(self, turn_context: TurnContext):
        card = HeroCard(
            title="Welcome to Universal Rentals!",
            text="""I am Owlbert the chat bot. How may I improve your
                    experience?""",
            images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
            buttons=[
                CardAction(
                    type=ActionTypes.open_url,
                    title="Register",
                    text="Registration button",
                    display_text="Registration button",
                    value=
                    "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Ask a question",
                    text="Ask a question",
                    display_text="Ask a question",
                    value="https://www.google.com",
                ),
            ],
        )

        return await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(card)))
Exemplo n.º 10
0
    async def on_teams_messaging_extension_query(
            self, turn_context: TurnContext, query: MessagingExtensionQuery):
        # These commandIds are defined in the Teams App Manifest.
        if not query.command_id == "searchQuery":
            raise NotImplementedError(f"Invalid CommandId: {query.command_id}")

        card = HeroCard(
            title="This is a Link Unfurling Sample",
            subtitle="It will unfurl links from *.BotFramework.com",
            text=
            "This sample demonstrates how to handle link unfurling in Teams.  Please review the readme for more "
            "information. ",
        )

        return MessagingExtensionResponse(
            compose_extension=MessagingExtensionResult(
                attachment_layout="list",
                type="result",
                attachments=[
                    MessagingExtensionAttachment(
                        content=card,
                        content_type=ContentTypes.hero_card,
                        preview=CardFactory.hero_card(card),
                    )
                ],
            ))
Exemplo n.º 11
0
 def create_welcome_card(self):
     title = "Benvenuto in BotTipBooks"
     subtitle = "Per iniziare ad utilizzare il bot effettuare il login oppure utilizzare il menu"
     image = CardImage(url="https://www.lineaedp.it/files/2017/01/bot.jpg")
     card = HeroCard(title=title, subtitle=subtitle, images=[image])
     activity = MessageFactory.attachment(CardFactory.hero_card(card))
     return activity
    def make_update_hero_card(self, step_context: WaterfallStepContext):
        hero_card = HeroCard(title="Newly updated card.", buttons=[])

        data = step_context.context.activity.value
        data["count"] = data["count"].value + 1
        hero_card.text = f"Update count - {data['count'].value}"

        hero_card.buttons.push(
            CardAction(
                type=ActionTypes.message_back,
                title="Update Card",
                text="UpdateCardAction",
                value=data,
            ))

        return CardFactory.hero_card(hero_card)
Exemplo n.º 13
0
    async def _send_help_message(self, turn_context: TurnContext):
        card = HeroCard(
            title=f"도움말",
            text="봇과의 1:1 대화에서 이미지를 전송하면 공유가능한 링크가 반환됩니다.",
            images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
            buttons=[
                CardAction(
                    type=ActionTypes.post_back,
                    title="/날씨",
                    text="/날씨",
                    display_text="/날씨",
                    value="/날씨",
                ),
                CardAction(
                    type=ActionTypes.post_back,
                    title="/미세먼지",
                    text="/미세먼지",
                    display_text="/미세먼지",
                    value="/미세먼지",
                ),
            ],
        )

        return await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(card)))
Exemplo n.º 14
0
    async def __send_intro_card(self, turn_context: TurnContext):
        card = HeroCard(
            title="ADC INTRODUCTION",
            text="BOT IS THE NEW FUTURE",
            images=[CardImage(url="https://aka.ms/bf-welcome-card-image")],
            buttons=[
                CardAction(
                    type=ActionTypes.open_url,
                    title="ADC",
                    text="Ask a question",
                    display_text="Ask a question",
                    value="http://cisadc.capgemini.com/",
                ),
                CardAction(
                    type=ActionTypes.open_url,
                    title="Bot Catalog",
                    text="Browse to view bot catalog",
                    display_text="Get an overview",
                    value="http://cisadc.capgemini.com/bots_catalog/",
                )
            ],
        )

        return await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(card)))
    def test_should_render_choices_as_hero_card(self):
        expected = Activity(
            type=ActivityTypes.message,
            input_hint=InputHints.expecting_input,
            attachment_layout=AttachmentLayoutTypes.list,
            attachments=[
                Attachment(
                    content=HeroCard(
                        text="select from:",
                        buttons=[
                            CardAction(type=ActionTypes.im_back,
                                       value="red",
                                       title="red"),
                            CardAction(type=ActionTypes.im_back,
                                       value="green",
                                       title="green"),
                            CardAction(type=ActionTypes.im_back,
                                       value="blue",
                                       title="blue"),
                        ],
                    ),
                    content_type="application/vnd.microsoft.card.hero",
                )
            ],
        )

        activity = ChoiceFactory.hero_card(ChoiceFactoryTest.color_choices,
                                           "select from:")

        self.assertEqual(expected, activity)
 def test_ShouldIncludeChoiceActionsInHeroCards(self):
     expected = Activity(
         type=ActivityTypes.message,
         input_hint=InputHints.expecting_input,
         attachment_layout=AttachmentLayoutTypes.list,
         attachments=[
             Attachment(
                 content=HeroCard(
                     text="select from:",
                     buttons=[
                         CardAction(
                             type=ActionTypes.im_back,
                             value="ImBack Value",
                             title="ImBack Action",
                         ),
                         CardAction(
                             type=ActionTypes.message_back,
                             value="MessageBack Value",
                             title="MessageBack Action",
                         ),
                         CardAction(
                             type=ActionTypes.post_back,
                             value="PostBack Value",
                             title="PostBack Action",
                         ),
                     ],
                 ),
                 content_type="application/vnd.microsoft.card.hero",
             )
         ],
     )
     activity = ChoiceFactory.hero_card(
         ChoiceFactoryTest.choices_with_actions, "select from:")
     self.assertEqual(expected, activity)
Exemplo n.º 17
0
    async def on_teams_messaging_extension_query(self, turn_context: TurnContext, query: MessagingExtensionQuery):
        if query.command_id == "searchQuery":
            card = HeroCard(
                title="This is a Link Unfurling Sample",
                subtitle="It will unfurl links from *.botframework.com",
                text="This sample demonstrates how to handle link unfurling in Teams. Please review the readme for more information."
            )
            attachment = Attachment(
                                content_type=CardFactory.content_types.hero_card,
                                content=card
                            )
            msg_ext_atc = MessagingExtensionAttachment(
                            content=card,
                            content_type=CardFactory.content_types.hero_card,
                            preview=attachment
                        )
            msg_ext_res = MessagingExtensionResult(
                    attachment_layout="list",
                    type="result",
                    attachments=[msg_ext_atc]
                )
            response = MessagingExtensionResponse(
                compose_extension=msg_ext_res
            )

            return response
        
        raise NotImplementedError(f"Invalid command: {query.command_id}")
Exemplo n.º 18
0
    async def _display_options(self, turn_context: TurnContext):
        """
        Create a HeroCard with options for the user to interact with the bot.
        :param turn_context:
        :return:
        """

        # Note that some channels require different values to be used in order to get buttons to display text.
        # In this code the emulator is accounted for with the 'title' parameter, but in other channels you may
        # need to provide a value for other parameters like 'text' or 'displayText'.
        card = HeroCard(
            text="You can upload an image or select one of the following choices",
            buttons=[
                CardAction(
                    type=ActionTypes.im_back, title="1. Inline Attachment", value="1"
                ),
                CardAction(
                    type=ActionTypes.im_back, title="2. Internet Attachment", value="2"
                ),
                CardAction(
                    type=ActionTypes.im_back, title="3. Uploaded Attachment", value="3"
                ),
            ],
        )

        reply = MessageFactory.attachment(CardFactory.hero_card(card))
        await turn_context.send_activity(reply)
Exemplo n.º 19
0
    def get_suggestions_card(suggestions: List[str], card_title: str,
                             card_no_match: str) -> Activity:
        """
        Get active learning suggestions card.
        """

        if not suggestions:
            raise TypeError("suggestions list is required")

        if not card_title:
            raise TypeError("card_title is required")

        if not card_no_match:
            raise TypeError("card_no_match is required")

        # Add all suggestions
        button_list = [
            CardAction(value=suggestion, type="imBack", title=suggestion)
            for suggestion in suggestions
        ]

        # Add No match text
        button_list.append(
            CardAction(value=card_no_match, type="imBack",
                       title=card_no_match))

        attachment = CardFactory.hero_card(HeroCard(buttons=button_list))

        return Activity(type=ActivityTypes.message,
                        text=card_title,
                        attachments=[attachment])
    async def _update_card_activity(self, turn_context: TurnContext):
        data = turn_context.activity.value
        data["count"] += 1

        card = CardFactory.hero_card(
            HeroCard(
                title="Welcome Card",
                text=f"Updated count - {data['count']}",
                buttons=[
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Update Card",
                        value=data,
                        text="UpdateCardAction",
                    ),
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Message all members",
                        text="MessageAllMembers",
                    ),
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Delete card",
                        text="Delete",
                    ),
                ],
            ))

        updated_activity = MessageFactory.attachment(card)
        updated_activity.id = turn_context.activity.reply_to_id
        await turn_context.update_activity(updated_activity)
Exemplo n.º 21
0
    def get_qna_prompts_card(result: QueryResult,
                             card_no_match_text: str) -> Activity:
        """
        Get active learning suggestions card.
        """

        if not result:
            raise TypeError("result is required")

        if not card_no_match_text:
            raise TypeError("card_no_match_text is required")

        # Add all prompts
        button_list = [
            CardAction(
                value=prompt.display_text,
                type="imBack",
                title=prompt.display_text,
            ) for prompt in result.context.prompts
        ]

        attachment = CardFactory.hero_card(HeroCard(buttons=button_list))

        return Activity(type=ActivityTypes.message,
                        text=result.answer,
                        attachments=[attachment])
Exemplo n.º 22
0
    async def _on_facebook_quick_reply(self, turn_context: TurnContext,
                                       facebook_quick_reply: dict):
        # TODO: Your quick reply event handling logic here...

        if turn_context.activity.text == FACEBOOK_PAGEID_OPTION:
            reply = MessageFactory.text(
                f"This message comes from the following Facebook Page: {turn_context.activity.recipient.id}"
            )
            await turn_context.send_activity(reply)
            await self._show_choices(turn_context)
        elif turn_context.activity.text == POSTBACK_OPTION:
            card = HeroCard(
                text=
                "Is 42 the answer to the ultimate question of Life, the Universe, and Everything?",
                buttons=[
                    CardAction(title="Yes",
                               type=ActionTypes.post_back,
                               value="Yes"),
                    CardAction(title="No",
                               type=ActionTypes.post_back,
                               value="No"),
                ],
            )
            reply = MessageFactory.attachment(CardFactory.hero_card(card))
            await turn_context.send_activity(reply)
        else:
            print(facebook_quick_reply)
            await turn_context.send_activity("Quick Reply")
            await self._show_choices(turn_context)
Exemplo n.º 23
0
 async def _send_welcome_card(self, turn_context: TurnContext, buttons):
     card = HeroCard(
         title="Talk to the hand", text="Or click the buttons.", buttons=buttons
     )
     await turn_context.send_activity(
         MessageFactory.attachment(CardFactory.hero_card(card))
     )
Exemplo n.º 24
0
    async def _update_card_activity(self, turn_context: TurnContext):
        data = turn_context.activity.value
        data["count"] += 1

        card = CardFactory.hero_card(
            HeroCard(
                title="Bem-vindo",
                text=f"Você foi cumprimentado {data['count']} vezes...",
                buttons=[
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Update Card",
                        value=data,
                        text="UpdateCardAction",
                    ),
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Envia para todos",
                        value=data,
                        text="MessageAllMembers",
                    ),
                    CardAction(
                        type=ActionTypes.message_back,
                        title="Retira o que disse",
                        text="Delete",
                    ),
                ],
            ))

        updated_activity = MessageFactory.attachment(card)
        updated_activity.id = turn_context.activity.reply_to_id
        await turn_context.update_activity(updated_activity)
Exemplo n.º 25
0
def create_hero_card() -> Attachment:
    card = HeroCard(title='',
                    images=[CardImage(url='https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg')],
                    buttons=[CardAction(type=ActionTypes.open_url,
                                        title='Get Started',
                                        value='https://docs.microsoft.com/en-us/azure/bot-service/')],
                    )
    return CardFactory.hero_card(card)
Exemplo n.º 26
0
    def hero_card(choices: List[Choice],
                  text: str = None,
                  speak: str = None) -> Activity:
        attachment = CardFactory.hero_card(
            HeroCard(text=text,
                     buttons=ChoiceFactory._extract_actions(choices)))

        # Return activity with choices as HeroCard with buttons
        return MessageFactory.attachment(attachment, None, speak,
                                         InputHints.expecting_input)
Exemplo n.º 27
0
    def create_card(books, categoria):
        card = HeroCard(
            title="Ecco i miei suggerimenti per te per la categoria: {}".
            format(categoria))
        attachments = []
        attachments.append(CardFactory.hero_card(card))
        text = ""
        for book in books:
            text += "Titolo: {}\n".format(book.name)
            text += "Nome del sito: Amazon\n"
            if book.price is not None:
                text += "Prezzo: {}€ \n".format(book.price)
            else:
                text += "Prezzo non disponibile.\n"
            text += "Link per l'acquisto: {} \n".format(book.link)
            attachments.append(CardFactory.hero_card(HeroCard(text=text)))
            text = ""

        activity = MessageFactory.carousel(attachments)
        return activity
    async def on_teams_team_renamed_activity(  # pylint: disable=unused-argument
            self, team_info: TeamInfo, turn_context: TurnContext):
        if not turn_context:
            raise Exception("turn_context cannot be null")

        if not team_info:
            raise Exception("team_info cannot be null")

        hero_card = HeroCard(text=f"{team_info.name} is the Team name")
        await turn_context.send_activity(
            MessageFactory.attachment(CardFactory.hero_card(hero_card)))
    async def share_message_command(
            self, turn_context: TurnContext, action: MessagingExtensionAction
    ) -> MessagingExtensionActionResponse:
        # The user has chosen to share a message by choosing the 'Share Message' context menu command.

        # TODO: .user is None
        title = "Shared Message"  # f'{action.message_payload.from_property.user.display_name} orignally sent this message:'
        text = action.message_payload.body.content
        card = HeroCard(title=title, text=text)

        if not action.message_payload.attachments is None:
            # This sample does not add the MessagePayload Attachments.  This is left as an
            #  exercise for the user.
            card.subtitle = (
                f"({len(action.message_payload.attachments)} Attachments not included)"
            )

        # This Messaging Extension example allows the user to check a box to include an image with the
        # shared message.  This demonstrates sending custom parameters along with the message payload.
        include_image = action.data["includeImage"]
        if include_image == "true":
            image = CardImage(
                url=
                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU"
            )
            card.images = [image]

        cardAttachment = CardFactory.hero_card(card)
        attachment = MessagingExtensionAttachment(
            content=card,
            content_type=CardFactory.content_types.hero_card,
            preview=cardAttachment,
        )
        attachments = [attachment]

        extension_result = MessagingExtensionResult(attachment_layout="list",
                                                    type="result",
                                                    attachments=attachments)
        return MessagingExtensionActionResponse(
            compose_extension=extension_result)
Exemplo n.º 30
0
    def create_hero_card(self):

        memes_list = [
            'https://images3.memedroid.com/images/UPLOADED826/5e6ea59356326.jpeg',
            'https://i.pinimg.com/originals/8c/04/87/8c04877aad35b1b0dad8376f7899d878.png',
            'https://starecat.com/content/wp-content/uploads/im-no-expert-on-covid-19-but-this-is-the-cure-literally-band.jpg',
            'https://images3.memedroid.com/images/UPLOADED86/5e2cc3aeec5c0.jpeg',
        ]

        card = HeroCard(title="",
                        images=[CardImage(url=random.choice(memes_list))])

        return CardFactory.hero_card(card)