def test_slack_channel(): 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", # this is the `bot_user_o_auth_access_token` slack_channel="YOUR_SLACK_CHANNEL" # the name of your channel to which the bot posts (optional) ) # 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/slack/").startswith( 'slack_webhook.health') assert routes_list.get("/webhooks/slack/webhook").startswith( 'slack_webhook.webhook') finally: s.stop()
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)
def run_restaurant_bot(serve_forever=True): interpreter = RasaNLUInterpreter('./models/nlu/default/restaurantnlu') agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint='./endpoints.yml') #agent = Agent.load('./models/dialogue', interpreter = interpreter) input_channel = SlackInput( 'SLACK_BOT_API_HERE') #your bot user authentication token agent.handle_channels([input_channel], 5004, serve_forever=True) return agent
def run_core(core_model_path, nlu_model_path, action_endpoint_url, slack_token): 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 = SlackInput(slack_token) agent.handle_channels([input_channel], 5002, serve_forever=True) return agent
def test_is_slack_message_true(): from rasa_core.channels.slack import SlackInput event = {'type': 'message', 'channel': 'C2147483705', 'user': '******', 'text': 'Hello world', 'ts': '1355517523'} payload = json.dumps({'event': event}) slack_message = json.loads(payload) assert SlackInput._is_user_message(slack_message) is True
def test_is_slack_message_true(): from rasa_core.channels.slack import SlackInput import json event = {} event['type'] = 'message' event['channel'] = 'C2147483705' event['user'] = '******' event['text'] = 'Hello world' event['ts'] = '1355517523' payload = json.dumps({'event': event}) slack_message = json.loads(payload) assert SlackInput._is_user_message(slack_message) is True
def agnt(st): nlu_interpreter = RasaNLUInterpreter('/app/models/rasa_nlu/current/nlu') core='/app/models/rasa_core' action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load(path=core, interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput(st) agent.handle_channels([input_channel], 5005, serve_forever=True)
def run_slack_bot(): print("Loading agent...") # load your trained agent agent = run_bot() print("Agent loaded.") input_channel = SlackInput( slack_token=os. environ['SLACK_TOKEN'], # this is the `bot_user_o_auth_access_token` ) print("Starting server on port 5004") agent.handle_channel(HttpInputChannel(5004, "/app", input_channel))
def run(serve_forever=True): #path to your NLU model interpreter = RasaNLUInterpreter("models/current/nlu") # path to your dialogues models agent = Agent.load("models/current/dialogue", interpreter=interpreter) #http api endpoint for responses #input_channel = SimpleWebBot() input_channel = \ SlackInput(slack_token='xoxb-525465834114-525382855891-SYt6HyWl7IfVyhtX19z6jJec' , slack_channel='@devops') # this is the `bot_user_o_auth_access_token` if serve_forever: agent.handle_channel(HttpInputChannel(5004, "/chat", input_channel)) return agent
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)))
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")) else: Exception("This script currently only supports the facebook " "and slack connectors.") return HttpInputChannel(port, None, input_blueprint)
def agnt(st): nlu_interpreter = RasaNLUInterpreter('/app/models/rasa_nlu/current/nlu') core = '/app/models/rasa_core' action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") #db= MongoTrackerStore(domain="/app/config/domain.yml",host='mongodb://localhost:27017', db='rasa', username="******", # password="******",collection="conversations",event_broker=None) #agent = Agent.load(path=core, interpreter = nlu_interpreter, action_endpoint = action_endpoint,tracker_store=db) agent = Agent.load(path=core, interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput(st) agent.handle_channels([input_channel], 5005, serve_forever=True)
def run_core(core_model_path, nlu_model_path, action_endpoint_url, slack_token): 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 = SlackInput(slack_token) agent.handle_channels([input_channel], 5004, 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
def runSlack(serve_forever=True): from rasa_core.channels import HttpInputChannel from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RegexInterpreter # load your trained agent interpreter = RasaNLUInterpreter( "models/nlu/default/model_20180529-103257") agent = Agent.load("models/dialogue", interpreter=interpreter) input_channel = SlackInput( slack_token= "xoxb-371047401462-369661464209-wcn44I8JzTIfJVwE6soZp6XH", # this is the `bot_user_o_auth_access_token` #slack_channel = "@Bot-test" # the name of your channel to which the bot posts (optional) ) print(HttpInputChannel(5004, "/app", input_channel)) agent.handle_channel(HttpInputChannel(5002, "/app", input_channel))
def test_slack_message_sanitization(): from rasa_core.channels.slack import SlackInput test_uid = 17213535 target_message_1 = 'You can sit here if you want' target_message_2 = 'Hey, you can sit here if you want !' target_message_3 = 'Hey, you can sit here if you want!' uid_token = '<@{}>'.format(test_uid) raw_messages = [ test.format(uid=uid_token) for test in [ 'You can sit here {uid} if you want{uid}', '{uid} You can sit here if you want{uid} ', '{uid}You can sit here if you want {uid}', # those last cases may be disputable # as we're virtually altering the entered text, # but this seem to be the correct course of action # (to be decided) 'You can sit here{uid}if you want', 'Hey {uid}, you can sit here if you want{uid}!', 'Hey{uid} , you can sit here if you want {uid}!' ] ] target_messages = [ target_message_1, target_message_1, target_message_1, target_message_1, target_message_2, target_message_3 ] sanitized_messages = [ SlackInput._sanitize_user_message(message, [test_uid]) for message in raw_messages ] # no message that is wrongly sanitized please assert len([ sanitized for sanitized, target in zip(sanitized_messages, target_messages) if sanitized != target ]) == 0
from rasa_core.channels.slack import SlackInput from rasa_core.channels import OutputChannel from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig import warnings nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/current') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput('slack token' #the bot user authentication token ) agent.handle_channels([input_channel], 5004, serve_forever=True)
def test_is_slack_message_none(): from rasa_core.channels.slack import SlackInput payload = {} slack_message = json.loads(json.dumps(payload)) assert SlackInput._is_user_message(slack_message) is None
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/nlu_model') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput('SECRET' #your bot user authentication token ) agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/chatter') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-663607438790-661481015920-Ur9kiXgDWzlIgVRDGrEfXHQL' #your bot user authentication token ) agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/current/nlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/current/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-341418647238-558540305505-TT99gmPfs9ncVZyllmiVmCYr') agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.interpreter import RasaNLUInterpreter from rasa_slack_connector import SlackInput nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu') agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter) input_channel = SlackInput('xoxp-#######', #app verification token '', # bot verification token '', # slack verification token True) agent.handle_channel(HttpInputChannel(5004, '/', input_channel)) ''' from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput('xoxb-' # bot user authentication token ) agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig #nlu_interpreter =RasaNLUInterpreter('.\\models\\current\\\\nlu_tf\\default\\seminarnlu') #train rasa_nlu #action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") #agent = Agent.load('.\\models\\current\\dialogue\\embedding5', interpreter = nlu_interpreter,action_endpoint = action_endpoint) #train rasa_core nlu_interpreter = RasaNLUInterpreter( './models/current/nlu_tf_oov/seminarnlu') #train rasa_nlu action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/newModel2', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( #'xoxp-464508724117-465710727574-540189494177-4f95904a55f64408089532920b798a80', 'xoxb-464508724117-540995397493-gmwJLQZBEkAcUvpSIJF5fV4J') #'zj2xHJiOZ7OXbMhJZL5ijoHV', #True) agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/current') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-682385421668-686711517732-GTou2OfY9OLAFOI0Rk8RQ95y' #your bot user authentication token ) agent.handle_channels([input_channel], 5004, serve_forever=True)
def test_slack_init_two_parameters(): from rasa_core.channels.slack import SlackInput ch = SlackInput("xoxb-test", "test") assert ch.slack_token == "xoxb-test" assert ch.slack_channel == "test"
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/travelnlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput('xoxb-551852374470-567879210517-sgpPTQKPlU7b2WmFdYy17ZAW') agent.handle_channels([input_channel], 5004, serve_forever=True)
def test_slack_init_one_parameter(): from rasa_core.channels.slack import SlackInput ch = SlackInput("xoxb-test") assert ch.slack_token == "xoxb-test" assert ch.slack_channel is None
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu') action_endpoint = EndpointConfig(url="http://0.0.0.0:5055/webhook") agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput(slack_token='Ih15YSaH6n4I9Cs9R7GHHvln') agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.utils import EndpointConfig import os interpreter = RasaNLUInterpreter("./models/nlu/default/horoscopebot") model_path = "./models/dialogue" action_endpoint = EndpointConfig(url="https://horoscopebot007-actions.herokuapp.com/webhook") agent = Agent.load(model_path,interpreter=interpreter,action_endpoint=action_endpoint) input_channel= SlackInput( slack_token = "", slack_channel="") s = agent.handle_channels([input_channel],int(os.environ.get('PORT',5004)),serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/current/nlu') action_endpoint = EndpointConfig( url="http://localhost:5005/webhooks/slack/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-626938457776-620596434449-iaW4Ef00VtIM5oYEl7BWiHmK' #your bot user authentication token ) agent.handle_channels([input_channel], 5005, serve_forever=True)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu_tf/default/service_nlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-446873191671-445226503153-NDkcQJudWyXwTrxiLn1WT4dj' ) #your bot user authentication token agent.handle_channels([input_channel], 5004, serve_forever=True)