Hi I am facing error when sending the message from slack to rasa via slack bolt. I am using socket mode so using the below code I can able to run the rasa server and when sending Hi Hello through slack then I am getting the correct response as It is having the default action. But when running the custom action It is saying
"
DEBUG:rasa.core.processor:Predicted next action 'action_my_radars' with confidence 1.00.
ERROR:rasa.core.processor:Encountered an exception while running action 'action_my_radars'.Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
Traceback (most recent call last):
File "/Users/shubham_shekhar/miniforge3/envs/rasatest/lib/python3.8/site-packages/rasa/core/processor.py", line 868, in _run_action
events = await action.run(
File "/Users/shubham_shekhar/miniforge3/envs/rasatest/lib/python3.8/site-packages/rasa/core/actions/action.py", line 709, in run
raise RasaException(
rasa.shared.exceptions.RasaException: Failed to execute custom action 'action_my_radars' because no endpoint is configured to run this custom action. Please take a look at the docs and set an endpoint configuration via the --endpoints flag. https://rasa.com/docs/rasa/custom-actions
DEBUG:rasa.core.processor:Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x174451820>]'.
DEBUG:rasa.core.processor:Action 'action_my_radars' ended with events '[]'.
"
import os
# from pprint import pprint
from slack_bolt.async_app import AsyncApp
from slack_bolt.adapter.socket_mode import SocketModeHandler
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
from rasa.core.channels.slack import SlackBot, SlackInput
from rasa.core.channels.channel import UserMessage
from rasa.core.channels import InputChannel
from rasa.core.agent import Agent
from rasa.core.run import create_http_input_channels, configure_app, close_resources
from rasa.core.http_interpreter import RasaNLUHttpInterpreter
from rasa.core import agent, channels, constants
import rasa.core.utils
from typing import Any, List, Optional, Text, Union, Dict
import uuid
from functools import partial
from rasa.core.utils import AvailableEndpoints
from sanic import Sanic
from asyncio import AbstractEventLoop
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger() # get the root logger
async def load_agent_on_start(
model_path: Text,
endpoints: AvailableEndpoints,
remote_storage: Optional[Text],
app: Sanic,
loop: AbstractEventLoop,
) -> Agent:
"""Load an agent.
Used to be scheduled on server start
(hence the `app` and `loop` arguments).
"""
app.agent = await agent.load_agent(
model_path=model_path,
remote_storage=remote_storage,
endpoints=endpoints,
loop=loop,
)
# async slack bolt app
boltapp = AsyncApp(token=os.environ["SLACK_BOT_TOKEN"])
@boltapp.event("message")
async def handle_message_events(body, logger):
# pprint(body)
event = body["event"]
thread_id = event.get("thread_ts", event.get("ts"))
chan = SlackBot(os.environ["SLACK_BOT_TOKEN"], event["channel"], thread_id=thread_id)
msg = UserMessage(
text=event["text"],
output_channel=chan,
sender_id=event["user"],
message_id=body["event_id"]
)
await app.agent.handle_message(msg)
logger.info("Establishing websocket connection with Slack")
sock = AsyncSocketModeHandler(boltapp, os.environ["SLACK_APP_TOKEN"])
await sock.start_async()
logger.info("Rasa server is up and running.")
return app.agent
def serve_application(
model_path: Optional[Text] = None,
channel: Optional[Text] = None,
interface: Optional[Text] = constants.DEFAULT_SERVER_INTERFACE,
port: int = constants.DEFAULT_SERVER_PORT,
credentials: Optional[Text] = None,
cors: Optional[Union[Text, List[Text]]] = None,
auth_token: Optional[Text] = None,
enable_api: bool = True,
response_timeout: int = constants.DEFAULT_RESPONSE_TIMEOUT,
endpoints: Optional[AvailableEndpoints] = None,
remote_storage: Optional[Text] = None,
conversation_id: Optional[Text] = uuid.uuid4().hex,
) -> None:
"""Run the API entrypoint."""
if not channel and not credentials:
channel = "cmdline"
input_channels = create_http_input_channels(channel, credentials)
app = configure_app(
input_channels,
cors,
auth_token,
enable_api,
response_timeout,
port=port,
endpoints=endpoints,
conversation_id=conversation_id,
)
protocol = "http"
logger.info(f"Starting Rasa server on {protocol}://{interface}:{port}")
app.register_listener(
partial(load_agent_on_start, model_path, endpoints, remote_storage),
"before_server_start",
)
app.register_listener(close_resources, "after_server_stop")
number_of_workers = rasa.core.utils.number_of_sanic_workers(
endpoints.lock_store if endpoints else None
)
app.run(
host=interface,
port=port,
workers=number_of_workers,
)
if __name__ == "__main__":
# serve_application(model_path="models/", credentials="credentials.yml")
serve_application(model_path="rasa-server/models/",credentials="rasa-server/credentials.yml", channel="slack")
This is the code I am running that will start the rasa server and using rasa run actions I am running the action server. Then why it is not able to look at the custom action? What should I do so that I can able to communicate the rasa with slack?
Versions: Python=3.8.12 Rasa=3.0.2 rasa-sdk= 3.0.2