Ejemplo n.º 1
0
 def test_dict(self):
     sc = Card('DEMOTYPE')
     self.assertDictEqual(sc.dict(), {
         'type': 'DEMOTYPE',
         'version': 1,
     })
     sc = Card('DEMOTYPE', title="Title", text="Text", key_a=1)
     self.assertDictEqual(sc.dict(), {
         'type': 'DEMOTYPE',
         'version': 1,
         'data': {'title': 'Title', 'text': 'Text', 'keyA': 1},
     })
Ejemplo n.º 2
0
    def test_with_action(self):
        sc = Card().with_action("Call this number",
                                CardAction.INTERNAL_CALL,
                                number="1234567890")
        self.assertEqual(
            {
                "type": "GENERIC_DEFAULT",
                "version": 1,
                "data": {
                    "action": "internal://deeplink/call/1234567890",
                    "actionText": "Call this number",
                },
            },
            sc.dict(),
        )

        sc = sc.with_action(
            "Open App",
            CardAction.INTERNAL_OPEN_APP,
            aos_package_name="package",
            ios_url_scheme="urlScheme",
            ios_app_store_id="appStoreId",
        )
        self.assertEqual(
            {
                "type": "GENERIC_DEFAULT",
                "version": 1,
                "data": {
                    "action":
                    "internal://deeplink/openapp?aos=package&iosScheme=urlScheme&iosAppStoreId=appStoreId",
                    "actionText": "Open App",
                },
            },
            sc.dict(),
        )

        sc = Card().with_action("Click this URL", "http://example.com")
        self.assertEqual(
            {
                "type": "GENERIC_DEFAULT",
                "version": 1,
                "data": {
                    "action": "http://example.com",
                    "actionText": "Click this URL",
                },
            },
            sc.dict(),
        )
Ejemplo n.º 3
0
 def test_list_sections(self):
     sc = Card(list_sections=[
         card.ListSection(
             "Section Title",
             [card.ListItem("Item 1"),
              card.ListItem("Item 2")])
     ]).dict()
     self.assertEqual(
         {
             "type": "GENERIC_DEFAULT",
             "version": 1,
             "data": {
                 "listSections": [{
                     "title":
                     "Section Title",
                     "items": [{
                         "title": "Item 1"
                     }, {
                         "title": "Item 2"
                     }],
                 }]
             },
         },
         sc,
     )
Ejemplo n.º 4
0
 def setUp(self):
     self.simple_response = Response("abc123", ResponseType.TELL)
     self.ask_response = Response("abc123", ResponseType.ASK)
     c = Card("SIMPLE", title_text="cardtitle", text="cardtext")
     self.card_response = Response(
         "abc123", ResponseType.TELL, card=c, result={"code": 22}
     )
     self.ctx = create_context("TELEKOM_Clock_GetTime")
Ejemplo n.º 5
0
    def setUp(self):
        self.simple_response = Response('abc123')
        self.ask_response = Response('abc123', RESPONSE_TYPE_ASK, ask_for=('location', 'CITY'))
        card = Card('SIMPLE', title='cardtitle', text='cardtext', token_id={'secret': 'token'})
        self.card_response = Response('abc123', RESPONSE_TYPE_TELL, card=card, result={'code': 22})

        session = {'attributes': {"key-1": "value-1",
                                  "key-2": "value-2"}}
        self.ctx = create_context("TELEKOM_Clock_GetTime", session=session)
Ejemplo n.º 6
0
 def test_dict(self):
     sc = Card("DEMOTYPE")
     self.assertDictEqual(sc.dict(), {
         "type": card.GENERIC_DEFAULT,
         "version": 1,
         "data": {}
     })
     sc = Card("DEMOTYPE", title_text="Title", text="Text")
     self.assertDictEqual(
         sc.dict(),
         {
             "type": card.GENERIC_DEFAULT,
             "version": 1,
             "data": {
                 "titleText": "Title",
                 "text": "Text"
             },
         },
     )
Ejemplo n.º 7
0
def format_bot_output(response: List[Dict[Text, Any]]) -> Tuple[Text, Card]:
    """
    Format output from Rasa server:
        - join strings if text
        - send card if image present

    :param response:
    :return:
    """
    speech = ssml.Speech()
    [
        speech.sentence(message['text']) for message in response
        if 'text' in message
    ]

    images = [message['image'] for message in response if 'image' in message]

    return str(speech), Card("GENERIC_DEFAULT",
                             icon_url=images[0]) if images else None
Ejemplo n.º 8
0
    def with_card(
        self,
        card: Card = None,
        title_text: Text = None,
        type_description: Text = None,
        prominent_text: Text = None,
        text: Text = None,
        sub_text: Text = None,
        action: Text = None,
        action_text: Text = None,
        action_prominent_text: Text = None,
        icon_url: Text = None,
        list_sections: List[ListSection] = None,
    ) -> "SkillInvokeResponse":
        """
        Attach Card to a response

        @param card:
        @param title_text:
        @param type_description:
        @param prominent_text:
        @param text:
        @param sub_text:
        @param action:
        @param action_text:
        @param action_prominent_text:
        @param icon_url:
        @param list_sections:
        @return:
        """
        card = card or Card(
            title_text=title_text,
            type_description=type_description,
            prominent_text=prominent_text,
            text=text,
            sub_text=sub_text,
            action=action,
            action_text=action_text,
            action_prominent_text=action_prominent_text,
            icon_url=icon_url,
            list_sections=list_sections,
        )
        return self.copy(update=dict(card=card))
Ejemplo n.º 9
0
 def test_init_no_type(self):
     with self.assertRaises(ValueError):
         Card()
Ejemplo n.º 10
0
 def test_init(self):
     sc = Card('DEMOTYPE', title="Title", text="Text")
     self.assertEqual(sc.data['title'], "Title")
     self.assertEqual(sc.data['text'], "Text")
Ejemplo n.º 11
0
 def test_l10n_message(self):
     d = Card(title_text=i18n.Message(
         "TITLE", param1="param1", param2="param2")).dict()
     self.assertEqual({"titleText": "TITLE"}, d["data"])
Ejemplo n.º 12
0
 def test_init(self):
     sc = Card(type="DEMOTYPE", title_text="Title", text="Text")
     self.assertEqual(sc.title_text, "Title")
     self.assertEqual(sc.text, "Text")
Ejemplo n.º 13
0
 def test_init_default_type(self):
     self.assertEqual(GENERIC_DEFAULT, Card().type_)