diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 177704358e11..1961f268c6a0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,8 @@ Added Changed ------- +- deprecate ``rasa.core.agent.handle_channels()`. Please use ``rasa.run(...)`` + or ``rasa.core.run.configure_app`` instead. Removed ------- diff --git a/rasa/core/agent.py b/rasa/core/agent.py index 6795c5ac82c4..98e7efedbca7 100644 --- a/rasa/core/agent.py +++ b/rasa/core/agent.py @@ -676,6 +676,13 @@ def handle_channels( from rasa.core import run + logger.warning( + "DEPRECATION warning: Using `handle_channels` is deprecated. " + "Please use `rasa.run(...)` or see " + "`rasa.core.run.configure_app(...)` if you want to implement " + "this on a more detailed level." + ) + app = run.configure_app(channels, cors, None, enable_api=False, route=route) app.agent = self diff --git a/rasa/core/processor.py b/rasa/core/processor.py index eb6ae178bd28..a4b48ae87b3c 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -452,7 +452,6 @@ async def _run_action( events = [] self._log_action_on_tracker(tracker, action.name(), events, policy, confidence) - if action.name() != ACTION_LISTEN_NAME and not action.name().startswith( UTTER_PREFIX ): diff --git a/tests/core/test_channels.py b/tests/core/test_channels.py index 3c9a0d6cfe71..c75df5162ab6 100644 --- a/tests/core/test_channels.py +++ b/tests/core/test_channels.py @@ -4,10 +4,10 @@ import pytest import responses -import sanic from aioresponses import aioresponses from sanic import Sanic +import rasa.core.run from rasa.core import utils from rasa.core.channels.channel import UserMessage from rasa.core.channels.telegram import TelegramOutput @@ -121,15 +121,9 @@ async def test_console_input(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_facebook_channel(): # START DOC INCLUDE from rasa.core.channels.facebook import FacebookInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = FacebookInput( fb_verify="YOUR_FB_VERIFY", @@ -139,7 +133,7 @@ def test_facebook_channel(): # token for the page you subscribed to ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -152,15 +146,9 @@ def test_facebook_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_webexteams_channel(): # START DOC INCLUDE from rasa.core.channels.webexteams import WebexTeamsInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = WebexTeamsInput( access_token="YOUR_ACCESS_TOKEN", @@ -169,7 +157,7 @@ def test_webexteams_channel(): # the name of your channel to which the bot posts (optional) ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -183,15 +171,9 @@ def test_webexteams_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_slack_channel(): # START DOC INCLUDE from rasa.core.channels.slack import SlackInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = SlackInput( slack_token="YOUR_SLACK_TOKEN", @@ -200,7 +182,7 @@ def test_slack_channel(): # the name of your channel to which the bot posts (optional) ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -212,15 +194,9 @@ def test_slack_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_mattermost_channel(): # START DOC INCLUDE from rasa.core.channels.mattermost import MattermostInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = MattermostInput( # this is the url of the api for your mattermost instance @@ -234,7 +210,7 @@ def test_mattermost_channel(): # the password of your bot user that will post messages ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -248,15 +224,9 @@ def test_mattermost_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_botframework_channel(): # START DOC INCLUDE from rasa.core.channels.botframework import BotFrameworkInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = BotFrameworkInput( # you get this from your Bot Framework account @@ -265,7 +235,7 @@ def test_botframework_channel(): app_password="MICROSOFT_APP_PASSWORD", ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -279,15 +249,9 @@ def test_botframework_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_rocketchat_channel(): # START DOC INCLUDE from rasa.core.channels.rocketchat import RocketChatInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = RocketChatInput( # your bots rocket chat user name @@ -298,7 +262,7 @@ def test_rocketchat_channel(): server_url="https://demo.rocket.chat", ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -315,15 +279,9 @@ def test_rocketchat_channel(): @pytest.mark.filterwarnings("ignore:unclosed file.*:ResourceWarning") # telegram channel will try to set a webhook, so we need to mock the api @patch.object(TelegramOutput, "setWebhook", noop) -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_telegram_channel(): # START DOC INCLUDE from rasa.core.channels.telegram import TelegramInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = TelegramInput( # you get this when setting up a bot @@ -334,7 +292,7 @@ def test_telegram_channel(): webhook_url="YOUR_WEBHOOK_URL", ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -353,15 +311,9 @@ async def test_handling_of_integer_user_id(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_twilio_channel(): # START DOC INCLUDE from rasa.core.channels.twilio import TwilioInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = TwilioInput( # you get this from your twilio account @@ -372,7 +324,7 @@ def test_twilio_channel(): twilio_number="YOUR_TWILIO_NUMBER", ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -384,22 +336,16 @@ def test_twilio_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_callback_channel(): # START DOC INCLUDE from rasa.core.channels.callback import CallbackInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = CallbackInput( # URL Core will call to send the bot responses endpoint=EndpointConfig("http://localhost:5004") ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -411,15 +357,9 @@ def test_callback_channel(): # USED FOR DOCS - don't rename without changing in the docs -@patch.object(sanic.Sanic, "run", fake_sanic_run) def test_socketio_channel(): # START DOC INCLUDE from rasa.core.channels.socketio import SocketIOInput - from rasa.core.agent import Agent - from rasa.core.interpreter import RegexInterpreter - - # load your trained agent - agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = SocketIOInput( # event name for messages sent from the user @@ -430,7 +370,7 @@ def test_socketio_channel(): namespace=None, ) - s = agent.handle_channels([input_channel], 5004) + s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs @@ -756,19 +696,13 @@ async def test_slackbot_send_text(): @pytest.mark.filterwarnings("ignore:unclosed.*:ResourceWarning") -@patch.object(sanic.Sanic, "run", fake_sanic_run) 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) + 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(