Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text('Play?'),
            tll.InlineKeyboard([[
                tll.InlineKeyboardCallbackButton(
                    text=t.LETS_PLAY,
                    payload={'action': 'play'},
                )
            ]]),
            lyr.Image(UrlMedia('https://domain/image.jpg'))
            # tll.AnswerInlineQuery(
            #     results=[1, 2, 3],
            #     cache_time=0,
            #     is_personal=True,
            # )
        )
Exemplo n.º 3
0
    def get_layers(self) -> List[BaseLayer]:
        out = []

        if 'message' in self._update:
            msg = self._update.get('message', {})

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

                for entity in (msg.get('entities') or []):
                    o = entity['offset']
                    l = entity['length']
                    entity_text = text[o:o + l]

                    if entity['type'] == 'bot_command':
                        out.append(BotCommand(entity_text))

            if 'reply_to_message' in msg:
                sub_msg = TelegramMessage(
                    {'message': msg['reply_to_message']},
                    self._telegram,
                )
                out.append(lyr.Message(sub_msg))

            if 'photo' in msg:
                media = Photo(msg['photo'])
                out.append(lyr.Image(media))

        if 'callback_query' in self._update:
            payload = self._update['callback_query']['data']
            out.append(lyr.Postback(ujson.loads(payload)))
            out.append(InlineMessage())

            sub_msg = TelegramMessage(
                self._update['callback_query'],
                self._telegram,
            )
            out.append(lyr.Message(sub_msg))

        if 'inline_query' in self._update:
            out.append(InlineQuery(self._update['inline_query']))

        return out