コード例 #1
0
def test_twilio_channel():
    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
        account_sid="YOUR_ACCOUNT_SID",
        # also from your twilio account
        auth_token="YOUR_AUTH_TOKEN",
        # a number associated with your twilio account
        twilio_number="YOUR_TWILIO_NUMBER")

    # set serve_forever=True if you want to keep the server running
    s = agent.handle_channels([input_channel], 5004, serve_forever=False)
    # END DOC INCLUDE
    # the above marker marks the end of the code snipped included
    # in the docs
    try:
        assert s.started
        routes_list = utils.list_routes(s.application)
        assert routes_list.get("/webhooks/twilio/").startswith(
            'twilio_webhook.health')
        assert routes_list.get("/webhooks/twilio/webhook").startswith(
            'twilio_webhook.message')
    finally:
        s.stop()
コード例 #2
0
def _create_external_channel(channel, port, credentials_file):
    if credentials_file is None:
        _raise_missing_credentials_exception(channel)

    credentials = read_yaml_file(credentials_file)
    if channel == "facebook":
        input_blueprint = FacebookInput(credentials.get("verify"),
                                        credentials.get("secret"),
                                        credentials.get("page-access-token"))
    elif channel == "slack":
        input_blueprint = SlackInput(credentials.get("slack_token"),
                                     credentials.get("slack_channel"))
    elif channel == "telegram":
        input_blueprint = TelegramInput(credentials.get("access_token"),
                                        credentials.get("verify"),
                                        credentials.get("webhook_url"))
    elif channel == "mattermost":
        input_blueprint = MattermostInput(credentials.get("url"),
                                          credentials.get("team"),
                                          credentials.get("user"),
                                          credentials.get("pw"))
    elif channel == "twilio":
        input_blueprint = TwilioInput(credentials.get("account_sid"),
                                      credentials.get("auth_token"),
                                      credentials.get("twilio_number"))
    else:
        Exception("This script currently only supports the facebook,"
                  " telegram, mattermost and slack connectors.")

    return HttpInputChannel(port, None, input_blueprint)
コード例 #3
0
ファイル: run.py プロジェクト: zoltan-fedor/rasa_core
def _create_single_channel(channel, credentials):
    if channel == "facebook":
        from rasa_core.channels.facebook import FacebookInput

        return FacebookInput(credentials.get("verify"),
                             credentials.get("secret"),
                             credentials.get("page-access-token"))
    elif channel == "slack":
        from rasa_core.channels.slack import SlackInput

        return SlackInput(credentials.get("slack_token"),
                          credentials.get("slack_channel"))
    elif channel == "telegram":
        from rasa_core.channels.telegram import TelegramInput

        return TelegramInput(credentials.get("access_token"),
                             credentials.get("verify"),
                             credentials.get("webhook_url"))
    elif channel == "mattermost":
        from rasa_core.channels.mattermost import MattermostInput

        return MattermostInput(credentials.get("url"), credentials.get("team"),
                               credentials.get("user"), credentials.get("pw"))
    elif channel == "twilio":
        from rasa_core.channels.twilio import TwilioInput

        return TwilioInput(credentials.get("account_sid"),
                           credentials.get("auth_token"),
                           credentials.get("twilio_number"))
    elif channel == "botframework":
        from rasa_core.channels.botframework import BotFrameworkInput
        return BotFrameworkInput(credentials.get("app_id"),
                                 credentials.get("app_password"))
    elif channel == "rocketchat":
        from rasa_core.channels.rocketchat import RocketChatInput
        return RocketChatInput(credentials.get("user"),
                               credentials.get("password"),
                               credentials.get("server_url"))
    elif channel == "rasa":
        from rasa_core.channels.rasa_chat import RasaChatInput

        return RasaChatInput(credentials.get("url"),
                             credentials.get("admin_token"))
    else:
        raise Exception("This script currently only supports the "
                        "{} connectors."
                        "".format(", ".join(BUILTIN_CHANNELS)))
コード例 #4
0
from rasa_core.channels.twilio import TwilioInput
from rasa_core.agent import Agent
from rasa_core.interpreter import RegexInterpreter
from rasa_core.interpreter import RasaNLUInterpreter
import yaml
from rasa_core.utils import EndpointConfig

nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weather_nlu')
action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
agent = Agent.load('./models/dialogue',
                   interpreter=nlu_interpreter,
                   action_endpoint=action_endpoint)

input_channel = TwilioInput(
    # you get this from your twilio account
    account_sid="AC5bb1242b97d3880aadf4b407730cf3eb",
    # also from your twilio account
    auth_token="57278821b1d2e8861a6a9a9c5a3b1d84",
    # a number associated with your twilio account
    twilio_number="+18329090952")

# set serve_forever=True if you want to keep the server running
s = agent.handle_channels([input_channel], 5004, serve_forever=True)