Exemple #1
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)))
Exemple #2
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)))
Exemple #3
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)))
 async def select_third(self, step_context: WaterfallStepContext) -> DialogTurnResult:
     result = step_context.result
     selected = step_context.values["selected"]
     categories = step_context.values["categories"]
     
     for i,c in enumerate(categories):
         if result.lower()==c.name.lower():
             selected.append(c)
             del categories[i]
             step_context.values["selected"] = selected
             step_context.values["categories"] = categories
             break
             
     card=self.create_card(step_context)
     
     message_text = ("Hai selezionato correttamente la categoria {}".format(result))
     message = MessageFactory.text(message_text, message_text, InputHints.ignoring_input)
     await step_context.context.send_activity(message)
     return await step_context.prompt(
         TextPrompt.__name__,
         PromptOptions(
             prompt = MessageFactory.attachment(card),
             retry_prompt= MessageFactory.text("Inserisci una categoria valida.")
         )
     )           
    async def handle_special_activity(self,
                                      step_context: WaterfallStepContext):
        if step_context.context.activity.text is None:
            await step_context.context.send_activity(
                MessageFactory.text(
                    f"I received an activity with this data in the value field {step_context.context.activity.value}"
                ))
        else:
            if "update" in step_context.context.activity.text.lower():
                if step_context.context.activity.reply_to_id is None:
                    await step_context.context.send_activity(
                        MessageFactory.text(
                            f"Update activity is not supported in the "
                            f"{step_context.context.activity.channel_id} channel"
                        ))
                else:
                    hero_card = self.make_update_hero_card(step_context)

                    activity = MessageFactory.attachment(hero_card)
                    activity.id = step_context.context.activity.reply_to_id

                    await step_context.context.update_activity(activity)

            else:
                await step_context.context.send_activity(
                    MessageFactory.text(
                        f"I received an activity with this data in the text field {step_context.context.activity.text} "
                        f"and this data in the value field {step_context.context.activity.value}"
                    ))
 async def _send_adaptive_card(self, turn_context: TurnContext,
                               card_type: int):
     card = None
     if card_type == 1:
         card_path = card_path = os.path.join(os.getcwd(),
                                              "cards\\bot_action.json")
         with open(card_path, "rb") as in_file:
             card_data = json.load(in_file)
             card = CardFactory.adaptive_card(card_data)
     elif card_type == 2:
         card_path = card_path = os.path.join(os.getcwd(),
                                              "cards\\task_module.json")
         with open(card_path, "rb") as in_file:
             card_data = json.load(in_file)
             card = CardFactory.adaptive_card(card_data)
     elif card_type == 3:
         card_path = card_path = os.path.join(os.getcwd(),
                                              "cards\\submit_action.json")
         with open(card_path, "rb") as in_file:
             card_data = json.load(in_file)
             card = CardFactory.adaptive_card(card_data)
     else:
         raise Exception("Invalid card type. Must be 1, 2 or 3.")
     reply_activity = MessageFactory.attachment(card)
     await turn_context.send_activity(reply_activity)
Exemple #7
0
    async def summary_step(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:
        if step_context.result:
            # Get the current profile object from user state.  Changes to it
            # will saved during Bot.on_turn.
            user_profile = await self.user_profile_accessor.get(
                step_context.context, UserProfile)

            user_profile.transport = step_context.values["transport"]
            user_profile.name = step_context.values["name"]
            user_profile.age = step_context.values["age"]
            user_profile.picture = step_context.values["picture"]

            msg = f"I have your mode of transport as {user_profile.transport} and your name as {user_profile.name}."
            if user_profile.age != -1:
                msg += f" And age as {user_profile.age}."

            await step_context.context.send_activity(MessageFactory.text(msg))

            if user_profile.picture:
                await step_context.context.send_activity(
                    MessageFactory.attachment(user_profile.picture,
                                              "This is your profile picture."))
            else:
                await step_context.context.send_activity(
                    "A profile picture was saved but could not be displayed here."
                )
        else:
            await step_context.context.send_activity(
                MessageFactory.text("Thanks. Your profile will not be kept."))

        # WaterfallStep always finishes with the end of the Waterfall or with another
        # dialog, here it is the end.
        return await step_context.end_dialog()
Exemple #8
0
    async def _send_adaptive_card(self, turn_context: TurnContext, card_type: str):
        card = None
        card_path = ""
        if card_type == "botaction":
            if PLATFORM == WINDOWS:
                card_path = os.path.join(os.getcwd(), "cards\\bot_action.json")  
            else:
                card_path = os.path.join(os.getcwd(), "cards/bot_action.json") 
            with open(card_path, "rb") as in_file:
                card_data = json.load(in_file)
                card = CardFactory.adaptive_card(card_data)
        elif card_type == "taskmodule":
            if PLATFORM == WINDOWS:
                card_path = os.path.join(os.getcwd(), "cards\\task_module.json")  
            else:
                card_path = os.path.join(os.getcwd(), "cards/task_module.json") 

            with open(card_path, "rb") as in_file:
                card_data = json.load(in_file)
                card = CardFactory.adaptive_card(card_data)
        elif card_type == "submit":
            if PLATFORM == WINDOWS:
                card_path = os.path.join(os.getcwd(), "cards\\submit_action.json")  
            else:
                card_path = os.path.join(os.getcwd(), "cards/submit_action.json") 

            with open(card_path, "rb") as in_file:
                card_data = json.load(in_file)
                card = CardFactory.adaptive_card(card_data)
        else:
            raise Exception("Invalid card type. Must be botaction, taskmodule, submit, or hero.")
        reply_activity = MessageFactory.attachment(card)
        await turn_context.send_activity(reply_activity)
Exemple #9
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)
Exemple #10
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)
Exemple #11
0
async def send_execsum(req: Request) -> Response:
    try:
        credentials = MicrosoftAppCredentials(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
        client = ConnectorClient(credentials, 'https://smba.trafficmanager.net/fr/')
        teams_client = TeamsConnectorClient(credentials, 'https://smba.trafficmanager.net/fr/')
        teams_channels = teams_client.teams.get_teams_channels('19:[email protected]')
        general_channel = next(channel for channel in teams_channels.conversations if channel.name is None)
        conversation_parameters = ConversationParameters(
            is_group=True,
            channel_data={"channel": {"id": general_channel.id}},
            activity=MessageFactory.attachment(
                CardFactory.adaptive_card({
                    "type": "AdaptiveCard",
                    "version": "1.0",
                    "body": [
                        {
                            "type": "TextBlock",
                            "text": "[email protected] sent an execsum",
                        },
                    ],
                    "actions": [
                        {
                            "type": "Action.OpenUrl",
                            "title": "View execsum",
                            "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
                        }
                    ]
                })
            ),
        )
        client.conversations.create_conversation(conversation_parameters)
        return Response(status=HTTPStatus.OK)
    except Exception:
        traceback.print_exc()
 def test_should_return_attachment_with_text_and_speak(self):
     activity = MessageFactory.attachment(Attachment(content_type="none"),
                                          "test1", "test2")
     assert_message(activity)
     assert_attachments(activity, 1, ["none"])
     assert activity.text == "test1", "invalid text field."
     assert activity.speak == "test2", "invalid speak field."
    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)
 def test_should_return_attachment_with_text_and_speak(self):
     activity = MessageFactory.attachment(Attachment(content_type='none'),
                                          'test1', 'test2')
     assert_message(activity)
     assert_attachments(activity, 1, ['none'])
     assert activity.text == 'test1', 'invalid text field.'
     assert activity.speak == 'test2', 'invalid speak field.'
    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)
Exemple #16
0
    async def act_step(self,
                       step_context: WaterfallStepContext) -> DialogTurnResult:

        details = step_context.context.activity.text

        score_dict = pointExtract(details)
        #price = {'low':1,'high':20000}
        recommend_id, recommend_result = adjust(score_dict)
        print('推荐id为:')
        print(str(recommend_id + 1))
        welcome_card = self.create_adaptive_card_attachment(recommend_id)
        response = MessageFactory.attachment(welcome_card)
        await step_context.context.send_activity(response)

        message_text = str(recommend_result)
        prompt_message = MessageFactory.text(message_text, message_text,
                                             InputHints.ignoring_input)
        await step_context.context.send_activity(prompt_message)

        #return await step_context.end_dialog()
        msg_txt = (f"您对这个推荐结果满意吗?")

        message = MessageFactory.text(msg_txt, msg_txt,
                                      InputHints.expecting_input)
        return await step_context.prompt(TextPrompt.__name__,
                                         PromptOptions(prompt=message))
Exemple #17
0
    async def __mobile_billPaymentConfirmation_card(self,
                                                    turn_context: TurnContext):
        text = turn_context.activity.text

        return await turn_context.send_activity(
            MessageFactory.attachment(
                CardFactory.thumbnail_card(billPaymentConfirmation_card)))
Exemple #18
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)))
 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
 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))
     )
Exemple #21
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))
        )
 async def _send_hero_card(self, turn_context: TurnContext):
     card_path = os.path.join(os.getcwd(), "cards\\hero_card.json")
     with open(card_path, "rb") as in_file:
         card_data = json.load(in_file)
     await turn_context.send_activity(
         MessageFactory.attachment(
             Attachment(content_type=CardFactory.content_types.hero_card,
                        content=card_data)))
Exemple #23
0
 async def on_members_added_activity(self,
                                     members_added: List[ChannelAccount],
                                     turn_context: TurnContext):
     for member_added in turn_context.activity.members_added:
         if member_added.id != turn_context.activity.recipient.id:
             activity: Activity = MessageFactory.attachment(
                 CardFactory.adaptive_card(WELCOME_CARD))
             await turn_context.send_activity(activity)
 def test_should_return_attachment_with_text_speak_and_input_hint(self):
     activity = MessageFactory.attachment(Attachment(content_type='none'),
                                          'test1', 'test2',
                                          InputHints.ignoring_input)
     assert_message(activity)
     assert_attachments(activity, 1, ['none'])
     assert activity.text == 'test1', 'invalid text field.'
     assert activity.speak == 'test2', 'invalid speak field.'
     assert activity.input_hint == InputHints.ignoring_input, 'invalid input_hint field.'
Exemple #25
0
 async def on_members_added_activity(
     self, members_added: List[ChannelAccount], turn_context: TurnContext
 ):
     for member in members_added:
         if member.id != turn_context.activity.recipient.id:
             welcome_card = self.create_adaptive_card_attachment()
             response = MessageFactory.attachment(welcome_card)
             await turn_context.send_activity(response)
             text = welcome()
             await turn_context.send_activity("Bienvenu(e) chez "+text)
    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)
Exemple #27
0
 async def on_members_added_activity(self,
                                     members_added: List[ChannelAccount],
                                     turn_context: TurnContext):
     for member in members_added:
         # Greet anyone that was not the target (recipient) of this message.
         # To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
         if member.id != turn_context.activity.recipient.id:
             welcome_card = self.create_adaptive_card_attachment()
             response = MessageFactory.attachment(welcome_card)
             await turn_context.send_activity(response)
 def test_should_return_attachment_with_text_speak_and_input_hint(self):
     activity = MessageFactory.attachment(Attachment(content_type="none"),
                                          "test1", "test2",
                                          InputHints.ignoring_input)
     assert_message(activity)
     assert_attachments(activity, 1, ["none"])
     assert activity.text == "test1", "invalid text field."
     assert activity.speak == "test2", "invalid speak field."
     assert (activity.input_hint == InputHints.ignoring_input
             ), "invalid input_hint field."
    async def Completed(self, waterfall_step: WaterfallStepContext):
        second_click_name = waterfall_step._turn_context.activity.text

        waterfall_step.values["second_click"] = second_click_name
        waterfall_step.values[
            "second_clicktime"] = waterfall_step._turn_context.activity.timestamp.strftime(
                "%d-%b-%Y (%H:%M:%S.%f)")

        first_click = waterfall_step.values["first_click"]
        second_click = waterfall_step.values["second_click"]
        first_clicktime = waterfall_step.values["first_clicktime"]
        second_clicktime = waterfall_step.values["second_clicktime"]
        dif = datetime.strptime(second_clicktime,
                                "%d-%b-%Y (%H:%M:%S.%f)") - datetime.strptime(
                                    first_clicktime, "%d-%b-%Y (%H:%M:%S.%f)")
        current_time = datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)")
        name = waterfall_step.values["username"]
        user = name + "_" + current_time

        # Store into CosmosDB
        storeitem = await self.cosmodb.read([user])
        if user not in storeitem:
            usermode = UserProfile()
        else:
            usermode = storeitem[user]
        usermode.name = waterfall_step.values["username"]
        usermode.first = first_click
        usermode.second = second_click
        usermode.firsttime = first_clicktime
        usermode.secondtime = second_clicktime
        usermode.clickdiff = int(dif.total_seconds())
        collectionStore = {user: usermode}
        await self.cosmodb.write(collectionStore)

        if int(dif.total_seconds()) < 10:
            reply = MessageFactory.attachment(
                self.create_animation_card_breathe())
            return await waterfall_step.context.send_activity(reply)
        else:
            reply = MessageFactory.attachment(
                self.create_animation_card_hanginthere())
            return await waterfall_step.context.send_activity(reply)
            return await waterfall_step.end_dialog()
 async def loop_step(
         self, step_context: WaterfallStepContext) -> DialogTurnResult:
     selected = step_context.result
     done = selected == self.DONE_OPTION
     if done:
         return await step_context.end_dialog(selected)
     if selected in self.sub_action_options:
         card = self._create_adaptive_card_attachment(selected)
         response = MessageFactory.attachment(card)
         await step_context.context.send_activity(response)
     return await step_context.replace_dialog(self.__class__.__name__)