RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.92k stars 4.63k forks source link

POST to webhooks/callback/webhook error #5055

Closed MrRace closed 4 years ago

MrRace commented 4 years ago

Rasa version: 1.6.1

Rasa SDK version : 1.6.0

Python version: 3.7.3

Operating system (windows, osx, ...): Centos

Issue: I just test the CallbackInput according to user-guide, after rasa run, my request is:

curl -XPOST "http://localhost:5005/webhooks/callback/webhook" -d '{"sender":"MrRace","message": "Hi there!"}'

the response is:

<h1>Internal Server Error</h1>
    <p>
        The server encountered an internal error and cannot complete
        your request.
    </p>

image

the Server message is below:

[root@localhost test_rasa]# rasa run            
2020-01-10 17:19:52 INFO     root  - Starting Rasa server on http://localhost:5005
2020-01-10 17:19:55 INFO     absl  - Entry Point [tensor2tensor.envs.tic_tac_toe_env:TicTacToeEnv] registered with id [T2TEnv-TicTacToeEnv-v0]
Exception occurred while handling uri: 'http://localhost:5005/webhooks/callback/webhook'
Traceback (most recent call last):
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "uvloop/loop.pyx", line 1974, in create_connection
  File "uvloop/loop.pyx", line 1951, in uvloop.loop.Loop.create_connection
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/sanic/app.py", line 942, in handle_request
    response = await response
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/channels/callback.py", line 77, in webhook
    UserMessage(text, collector, sender_id, input_channel=self.name())
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 83, in handler
    await app.agent.handle_message(*args, **kwargs)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/agent.py", line 486, in handle_message
    return await processor.handle_message(message)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/processor.py", line 103, in handle_message
    await self._predict_and_execute_next_action(message, tracker)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/processor.py", line 467, in _predict_and_execute_next_action
    action, tracker, message.output_channel, self.nlg, policy, confidence
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/processor.py", line 585, in _run_action
    await self._send_bot_messages(events, tracker, output_channel)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/processor.py", line 507, in _send_bot_messages
    await output_channel.send_response(tracker.sender_id, e.message())
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 186, in send_response
    await self.send_text_message(recipient_id, message.pop("text"), **message)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 328, in send_text_message
    await self._persist_message(self._message(recipient_id, text=message_part))
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/core/channels/callback.py", line 34, in _persist_message
    "post", content_type="application/json", json=message
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/rasa/utils/endpoints.py", line 146, in request
    **kwargs,
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/client.py", line 483, in _request
    timeout=real_timeout
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 859, in _create_connection
    req, traces, timeout)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "/home/data1/software/Anaconda3/lib/python3.7/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:5034 ssl:default [Connection refused]

image

Content of configuration file (credentials.yml) :

# This file contains the credentials for the voice & chat platforms
# which your bot is using.
# https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels/

rest:
#  # you don't need to provide anything here - this channel doesn't
#  # require any credentials

callback:
  # URL to which Core will send the bot responses
  url: "http://localhost:5034/bot"

#facebook:
#  verify: "<verify>"
#  secret: "<your secret>"
#  page-access-token: "<your page access token>"

#slack:
#  slack_token: "<your slack token>"
#  slack_channel: "<the slack channel>"

#socketio:
#  user_message_evt: <event name for user message>
#  bot_message_evt: <event name for but messages>
#  session_persistence: <true/false>

#mattermost:
#  url: "https://<mattermost instance>/api/v4"
#  team: "<mattermost team>"
#  user: "<bot username>"
#  pw: "<bot token>"
#  webhook_url: "<callback URL>"

rasa:
  url: "http://localhost:5002/api"

What should I do to get the correct result?

sara-tagger commented 4 years ago

Thanks for raising this issue, @Ghostvv will get back to you about it soon✨

Please also check out the docs and the forum in case your issue was raised there too 🤗
ricwo commented 4 years ago

Hi @MrRace, do you have a server running at http://localhost:5034/bot? Can you curl it to make sure it's reachable?

MrRace commented 4 years ago

Hi @MrRace, do you have a server running at http://localhost:5034/bot? Can you curl it to make sure it's reachable?

Oh,It does not have a server running at http://localhost:5034/bot. How to run the sever http://localhost:5034/bot ? Could you provide a complete example? Thanks a lot!

ricwo commented 4 years ago

The callback channel is designed to be used when running your own webchat, for example on your own website (see https://rasa.com/docs/rasa/user-guide/connectors/your-own-website/#id2). Please check out the docs for an overview of other supported channels: https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels/

If you have any more questions, please ask them in the forum