Exemple #1
0
 async def send_messages(self, receiver: ViberUser, messages: Iterable[BotMessage]):
     activate(receiver.language)
     for bot_message in messages:
         await self.post_data(
             self.SEND_MESSAGE,
             to_viber_message(bot_message, receiver)
         )
Exemple #2
0
    async def send_messages(self, messages: list, callback_message_id: int):
        activate(self.user.language)
        converted_messages = tuple(to_telegram_message(x, self.chat_id) for x in messages)

        if callback_message_id is not None and not messages[0].is_tg_text_buttons:
            converted_messages[0].update({
                'method': TelegramMethod.EDIT_TEXT,
                'message_id': callback_message_id,
            })

        just_sent_messages = []
        for msg in converted_messages:
            response_data = await self.post_data(msg)
            if response_data is not None and 'result' in response_data and 'message_id' in response_data['result']:
                just_sent_messages.append(response_data['result']['message_id'])

        await self.remove_previous_messages(dont_touch=(callback_message_id, ))
        await self.save_current_messages(just_sent_messages)
        async def inner():
            activate('be')
            encoded = json.dumps(
                {'text': lazy_string},
                cls=LazyAwareJsonEncoder,
            )
            assert json.loads(encoded) == {
                'text': 'Шмат тэстаў не бывае',
            }

            activate('ru')
            encoded = json.dumps(
                {'text': lazy_string},
                cls=LazyAwareJsonEncoder,
            )
            assert json.loads(encoded) == {
                'text': 'Сие есть сущая тестовая строка',
            }
Exemple #4
0
    async def webhook(cls, request):
        remote_update = await cls.get_remote_update(request)
        request['user'] = cls.get_or_create_user(remote_update)
        activate(request['user'].
                 language if request['user'] is not None else LANGUAGE)

        if remote_update.is_system_update():
            return await cls.handle_system_message(remote_update)

        if request['user'] is None:
            raise ValueError("User can't be None.")

        state = cls.get_state(request['user'])
        common_message = cls.get_input_message(remote_update)

        bot_messages = await cls.consume(request['user'], state,
                                         common_message)

        await cls.send_the_answer(request, remote_update, bot_messages)

        return cls.get_response(remote_update)
        async def inner():
            activate('ru')
            assert str(lazy_text) == 'Сие есть сущая тестовая строка'

            activate('be')
            assert str(lazy_text) == 'Шмат тэстаў не бывае'
 async def inner():
     activate('be')
     assert _('Test message') == 'Шмат тэстаў не бывае'
 async def inner():
     activate('ru')
     assert _('Test message') == 'Сие есть сущая тестовая строка'