예제 #1
0
    def get_layers(self):
        out = [
            l.Text(self.text),
        ]

        if self.add_qr:
            out += [
                l.QuickReply('foo'),
            ]

        return out
예제 #2
0
파일: platform.py 프로젝트: gnicod/bernard
    def get_layers(self) -> List[BaseLayer]:
        """
        Return all layers that can be found in the message.
        """
        out = []
        msg = self._event.get('message', {})

        if 'text' in msg:
            out.append(lyr.RawText(msg['text']))

        for attachment in msg.get('attachments') or []:
            if attachment['type'] == 'image':
                out.append(lyr.Image(UrlMedia(attachment['payload']['url'])))
            elif attachment['type'] == 'audio':
                out.append(lyr.Audio(UrlMedia(attachment['payload']['url'])))
            elif attachment['type'] == 'file':
                out.append(lyr.File(UrlMedia(attachment['payload']['url'])))
            elif attachment['type'] == 'video':
                out.append(lyr.Video(UrlMedia(attachment['payload']['url'])))
            elif attachment['type'] == 'location':
                # noinspection PyArgumentList
                out.append(lyr.Location(lyr.Location.Point(
                    lat=attachment['payload']['coordinates']['lat'],
                    lon=attachment['payload']['coordinates']['long'],
                )))

        if 'quick_reply' in msg:
            out.append(lyr.QuickReply(msg['quick_reply']['payload']))

        if 'postback' in self._event:
            payload = ujson.loads(self._event['postback']['payload'])
            out.append(lyr.Postback(payload))

        if 'link_click' in self._event:
            out.append(lyr.LinkClick(
                self._event['link_click']['url'],
                self._event['link_click']['slug'],
            ))

        if 'close_webview' in self._event:
            out.append(lyr.CloseWebview(
                self._event['close_webview']['slug'],
            ))

        if 'optin' in self._event:
            out.append(lyr.OptIn(self._event['optin']['ref']))

        return out
예제 #3
0
def test_story_hello():
    with patch_conf(settings_file=ENGINE_SETTINGS_FILE):
        _, platform = make_test_fsm()

        platform.handle(l.Text('Hello!'), )
        platform.assert_state(HowAreYou)
        platform.assert_sent(
            stack(l.Text(t.HELLO)),
            stack(
                l.Text(t.HOW_ARE_YOU),
                l.QuickRepliesList([
                    l.QuickRepliesList.TextOption('yes', t.YES, intents.YES),
                    l.QuickRepliesList.TextOption('no', t.NO, intents.NO),
                ])),
        )

        platform.handle(
            l.Text('Yes'),
            l.QuickReply('yes'),
        )
        platform.assert_sent(stack(l.Text(t.GREAT)))
예제 #4
0
 def get_layers(self):
     return [
         l.QuickReply('yes'),
         l.Text('yes'),
     ]