Esempio n. 1
0
def test_extract_input_channel(test_input, expected):
    from rasa.core.channels.channel import RestInput

    input_channel = RestInput()

    fake_request = MagicMock()
    fake_request.json = test_input

    assert input_channel._extract_input_channel(fake_request) == expected
Esempio n. 2
0
def test_channel_registration_with_absolute_url_prefix_overwrites_route():
    from rasa.core.channels.channel import RestInput
    import rasa.core

    input_channel = RestInput()
    test_route = "/absolute_route"
    input_channel.url_prefix = lambda: test_route

    app = Sanic(__name__)
    ignored_base_route = "/should_be_ignored"
    rasa.core.channels.channel.register(
        [input_channel], app, route="/should_be_ignored"
    )

    # Assure that an absolute url returned by `url_prefix` overwrites route parameter
    # given in `register`.
    routes_list = utils.list_routes(app)
    assert routes_list.get("custom_webhook_RestInput.health").startswith(test_route)
    assert ignored_base_route not in routes_list.get("custom_webhook_RestInput.health")
Esempio n. 3
0
    async def on_message_wrapper(on_new_message, text, queue, sender_id):
        collector = QueueOutputChannel(queue)

        message = UserMessage(text,
                              collector,
                              sender_id,
                              input_channel=RestInput.name())
        await on_new_message(
            message
        )  ## TODO  find details about this functions      # func sends message to core

        await queue.put("DONE")
Esempio n. 4
0
def test_register_channel_without_route():
    """Check we properly connect the input channel blueprint if route is None"""
    from rasa.core.channels.channel import RestInput
    import rasa.core

    input_channel = RestInput()

    app = Sanic(__name__)
    rasa.core.channels.channel.register([input_channel], app, route=None)

    routes_list = utils.list_routes(app)
    assert routes_list.get("custom_webhook_RestInput.receive").startswith("/webhook")
Esempio n. 5
0
def test_channel_inheritance():
    from rasa.core.channels.channel import RestInput
    from rasa.core.channels.rasa_chat import RasaChatInput

    rasa_input = RasaChatInput("https://example.com")

    s = rasa.core.run.configure_app([RestInput(), rasa_input], port=5004)

    routes_list = utils.list_routes(s)
    assert routes_list.get("custom_webhook_RasaChatInput.health").startswith(
        "/webhooks/rasa")
    assert routes_list.get("custom_webhook_RasaChatInput.receive").startswith(
        "/webhooks/rasa/webhook")
Esempio n. 6
0
    async def on_message_wrapper(
        on_new_message: Callable[[UserMessage], Awaitable[None]],
        text: Text,
        queue: Queue,
        sender_id: Text,
    ) -> None:
        collector = QueueOutputChannel(queue)

        message = UserMessage(
            text, collector, sender_id, input_channel=RestInput.name()
        )
        await on_new_message(message)

        await queue.put("DONE")  # pytype: disable=bad-return-type
Esempio n. 7
0
def test_channel_inheritance():
    from rasa.core.channels.channel import RestInput
    from rasa.core.channels.rasa_chat import RasaChatInput
    from rasa.core.agent import Agent
    from rasa.core.interpreter import RegexInterpreter

    # load your trained agent
    agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter())

    rasa_input = RasaChatInput("https://example.com")

    s = agent.handle_channels([RestInput(), rasa_input], 5004)

    routes_list = utils.list_routes(s)
    assert routes_list.get("custom_webhook_RasaChatInput.health").startswith(
        "/webhooks/rasa")
    assert routes_list.get("custom_webhook_RasaChatInput.receive").startswith(
        "/webhooks/rasa/webhook")
Esempio n. 8
0
async def rasa_server_secured(default_agent):
    app = server.create_app(agent=default_agent, auth_token="rasa", jwt_secret="core")
    channel.register([RestInput()], app, "/webhooks/")
    return app
Esempio n. 9
0
async def rasa_nlu_server(nlu_agent):
    app = server.create_app(agent=nlu_agent)
    channel.register([RestInput()], app, "/webhooks/")
    return app
Esempio n. 10
0
 def url_prefix(self):
     return RestInput.name()
Esempio n. 11
0
async def rasa_server_without_api() -> Sanic:
    app = _create_app_without_api()
    channel.register([RestInput()], app, "/webhooks/")
    return app
Esempio n. 12
0
async def rasa_core_server(core_agent: Agent) -> Sanic:
    app = server.create_app(agent=core_agent)
    channel.register([RestInput()], app, "/webhooks/")
    return app
Esempio n. 13
0
 def url_prefix(self) -> Text:
     return RestInput.name()