Skip to content

Commit

Permalink
deprecate 'handle_channels'
Browse files Browse the repository at this point in the history
  • Loading branch information
wochinge committed Jun 20, 2019
1 parent e27d778 commit 29cc01d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 79 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Added

Changed
-------
- deprecate ``rasa.core.agent.handle_channels()`. Please use ``rasa.run(...)``
or ``rasa.core.run.configure_app`` instead.

Removed
-------
Expand Down
7 changes: 7 additions & 0 deletions rasa/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
90 changes: 12 additions & 78 deletions tests/core/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 29cc01d

Please sign in to comment.