示例#1
0
    def process(self, handler_input):
        sess_attrs = handler_input.attributes_manager.session_attributes
        Constants.ACCESS_TOKEN = handler_input.request_envelope.session.user.access_token
        locale = handler_input.request_envelope.request.locale

        if Constants.i18n is None or handler_input.request_envelope.session.new:
            set_language_model(locale, non_verbose_mode=False)

        if not sess_attrs.get("ACCOUNT") and Constants.ACCESS_TOKEN:
            service = DailyTelegramsService()

            try:
                account = service.get_daily_telegrams_account()
                sess_attrs["ACCOUNT"] = {
                    "ID": account.id,
                    "PHONE_NUMBER": account.phone_number,
                    "AUTHORIZED": account.is_authorized,
                    "SETTINGS_ID": account.settings_id
                }

                if account.settings_id:
                    settings = service.get_settings(account.settings_id)
                    set_language_model(locale, settings.non_verbose_mode)

            except BackendException as http_error_code:
                sess_attrs["HTTP_ERROR_CODE"] = http_error_code.args[0]
示例#2
0
    def handle(self, handler_input):
        sess_attrs = handler_input.attributes_manager.session_attributes
        i18n = Constants.i18n
        current_intent = handler_input.request_envelope.request.intent
        settings_id = sess_attrs.get('ACCOUNT').get('SETTINGS_ID')
        daily_telegram_service = DailyTelegramsService()

        if settings_id is None:
            settings_id = daily_telegram_service.create_settings()
            sess_attrs['ACCOUNT']['SETTINGS_ID'] = settings_id

        for slot_name, current_slot in current_intent.slots.items():
            if slot_name == 'enable_or_disable_non_verbose_mode':
                if current_slot.value is None:
                    speech_text = i18n.SETTINGS_OPENED
                    slot_to_elicit = 'enable_or_disable_non_verbose_mode'
                    elicit_directive = ElicitSlotDirective(
                        current_intent, slot_to_elicit)
                    handler_input.response_builder.add_directive(
                        elicit_directive)
                else:
                    # If another configuration will be added I have to move the logic here
                    if current_slot.resolutions.resolutions_per_authority[
                            0].status.code == StatusCode.ER_SUCCESS_MATCH:
                        val = current_slot.resolutions.resolutions_per_authority[
                            0].values[0].value
                        if val.name.lower() in ['enable', 'einschalten']:
                            non_verbose_mode = True
                            speech_text = i18n.NON_VERBOSE_CHOICE.format(
                                i18n.ENABLE)
                        else:
                            non_verbose_mode = False
                            speech_text = i18n.NON_VERBOSE_CHOICE.format(
                                i18n.DISABLE)

                        settings = Settings(settings_id, non_verbose_mode)
                        settings = daily_telegram_service.update_settings(
                            settings)

                        locale = handler_input.request_envelope.request.locale
                        set_language_model(locale, settings.non_verbose_mode)
                    else:
                        # User did not say 'enable' or 'disable'
                        non_verbose_mode = False
                        speech_text = i18n.HINT_DISABLE_ENABLE

                    speech_text += ' ' + i18n.LEAVING_SETTINGS_MODE
                    speech_text += ' ' + i18n.get_random_anyting_else_without_ack(
                    )

        handler_input.response_builder \
            .speak(speech_text).set_should_end_session(False).ask(i18n.FALLBACK)
        return handler_input.response_builder.response
    def german_speed_dial(self):
        set_language_model('de-DE', True)
        i18n = Constants.i18n
        handler = sb.lambda_handler()

        german_speed_dial["context"]["System"]["user"][
            "accessToken"] = VALID_TOKEN
        german_speed_dial["session"]["user"]["accessToken"] = VALID_TOKEN
        event = handler(german_speed_dial, None)
        ssml = event.get('response').get('outputSpeech').get('ssml')
        self.assertTrue(ssml[19:-8] in i18n.MESSAGE.format('Lorenz'))

        set_language_model('en-US', True)
示例#4
0
import unittest
from src.skill.utils.utils import set_language_model
from src.tests.tokens import VALID_TOKEN, INVALID_TOKEN
from src.skill.utils.constants import Constants
from src.tests.launch_intent.launch_intent_test import LaunchIntentTest
from src.tests.message_intent.message_intent_test import MessageIntentTest
from src.tests.reply_intent.reply_intent_test import ReplyIntentTest
from src.tests.send_intent.send_intent_test import SendIntentTest
from src.tests.yes_no_intent.yes_no_intent_test import YesNoIntentTest
from src.tests.settings_intent.settings_test import SettingsIntentTest

if __name__ == "__main__":
    set_language_model('en-US', True)
    Constants.ACCESS_TOKEN = VALID_TOKEN
    suite = unittest.TestSuite()

    suite.addTest(LaunchIntentTest("test_authorized_launch_request"))
    suite.addTest(LaunchIntentTest("test_account_not_linked_launch_request"))
    suite.addTest(
        LaunchIntentTest("test_account_not_authorized_launch_request"))

    suite.addTest(MessageIntentTest("test_open_message_intent"))
    suite.addTest(MessageIntentTest("test_multiple_telegrams"))

    suite.addTest(ReplyIntentTest("reply_or_next_telegram"))
    suite.addTest(ReplyIntentTest("reply_on_last"))
    suite.addTest(ReplyIntentTest("no_telethon_ids"))

    # TODO: Add test: One-shot start_send_intent
    suite.addTest(SendIntentTest("start_send_intent"))
    suite.addTest(SendIntentTest("ask_for_message"))