Ejemplo n.º 1
0
def test_botframework_channel():
    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
        app_id="MICROSOFT_APP_ID",
        # also from your Bot Framework account
        app_password="******")

    # 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/botframework/").startswith(
            'botframework_webhook.health')
        assert routes_list.get("/webhooks/botframework/webhook").startswith(
            'botframework_webhook.webhook')
    finally:
        s.stop()
Ejemplo n.º 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"))
    elif channel == "botframework":
        input_blueprint = BotFrameworkInput(credentials.get("bf_id"),
                                            credentials.get("bf_secret"))
    else:
        Exception("This script currently only supports the facebook,"
                  " telegram, mattermost and slack connectors.")

    return HttpInputChannel(port, None, input_blueprint)
Ejemplo n.º 3
0
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)))
Ejemplo n.º 4
0
def run_core(core_model_path, nlu_model_path, action_endpoint_url):
    logging.basicConfig(filename=logfile, level=logging.DEBUG)
    nlu_interpreter = RasaNLUInterpreter(nlu_model_path)
    action_endpoint = EndpointConfig(url=action_endpoint_url)
    agent = Agent.load(core_model_path,
                       interpreter=nlu_interpreter,
                       action_endpoint=action_endpoint)
    input_channel = BotFrameworkInput(
        app_id='c79b9ea3-dab6-4089-8179-b323aff4d662',
        app_password='******')
    agent.handle_channels([input_channel], 5005, serve_forever=True)

    print("Your bot is ready to talk! Type your messages here or send 'stop'")
    while True:
        a = input()
        if a == 'stop':
            break
        responses = agent.handle_text(a)
        for response in responses:
            print(response["text"])
    return agent
Ejemplo n.º 5
0
    def continue_predicting():
        """Continue a prediction started with parse.

        Caller should have executed the action returned from the parse
        endpoint. The events returned from that executed action are
        passed to continue which will trigger the next action prediction.

        If continue predicts action listen, the caller should wait for the
        next user message."""
        from rasa_core.run import create_input_channel
        from rasa_core.channels.custom_websocket import CustomInput
        input_component1=CustomInput(None)
        input_component2=CustomInput(None)
        from rasa_core.channels.websocket import WebSocketInputChannel
        global usr_channel
        global ha_channel
        try:
            usr_channel = WebSocketInputChannel(int(env_json["userchannelport"]),None,input_component1,http_ip='0.0.0.0')

            botf_input_channel = BotFrameworkInput(
                  app_id=env_json['teams_app_id'],
                    app_password=env_json['teams_app_password']
                  )
            teams_channel = HttpInputChannel(int(env_json['userchannelport2']),'/webhooks/botframework',botf_input_channel)

        except OSError as e:
            logger.error(str(e))
            return str(e)


        usr_channel.output_channel = input_component1.output_channel
        teams_channel.output_channel = botf_input_channel.output_channel

        op_agent = agent()
        op_agent.handle_custom_processor([usr_channel,teams_channel],usr_channel,processor)

        return "ok"
Ejemplo n.º 6
0
    from rasa_core.policies.keras_policy import KerasPolicy
    from rasa_core.interpreter import RasaNLUInterpreter
    from rasa_core.agent import Agent
    interpreter = RasaNLUInterpreter('sample/models/current/nlu/default/default')
    action_endpoint_conf = utils.read_endpoint_config(os.path.join(current_dir, "sample/core_config.yml"), endpoint_type="action_endpoint")
    agent = Agent.load("sample/models/current/dialogue", interpreter=interpreter, action_endpoint=action_endpoint_conf)
    return agent

def get_action_executor():
    executor = ActionExecutor()
    #executor.register_package('actions')
    print('register actions')
    executor.register_package('actions')

from RasaHost import host
host.set_data_path(os.path.join(current_dir, "sample"))
#host.agent = get_agent()

#train_core()
#train_nlu()


from rasa_core.channels.botframework import BotFrameworkInput
input_channel = BotFrameworkInput(
        app_id="",
        app_password="")
host.channels = [input_channel]
if __name__ == '__main__':    
    host.run()