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.81k stars 4.62k forks source link

Buttons in custom action causes channel conversion entering loop #11291

Closed tommasodelorenzo closed 2 years ago

tommasodelorenzo commented 2 years ago

Rasa Open Source version

3.2.1

Rasa SDK version

3.2.0

Python version

3.8

What operating system are you using?

Linux

What happened?

The problem: Uttering buttons with custom action are not shown and the conversation in channels like Telegram and Messenger enters a loop. The agent works just fine both in shell and interactive mode, though. And everything works fine with the channels if I remove the buttons.

Simple working example: I slightly modified the initial project, by making the following modifications:

  1. domain.py:
    # utter_did_that_help:
    # - text: "Did that help you?"
    actions:
    - action_utter_did_that_help
  2. actions.py
    
    from typing import Text, List, Any, Dict

from rasa_sdk import Tracker, FormValidationAction, Action from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.types import DomainDict from rasa_sdk.events import SlotSet, SessionStarted, ActionExecuted, EventType, UserUttered

class AskIfItHelpedAction(Action): def name(self) -> Text: return "action_utter_did_that_help"

def run(
    self, 
    dispatcher: CollectingDispatcher,
    tracker: Tracker, 
    domain: Dict
) -> List[EventType]:

    dispatcher.utter_message(text= "Did that help you?")
    dispatcher.utter_message(buttons = [
        {"title": "yes", 
        "payload": "/affirm"
        },
        {"title": "no", 
        "payload": "/deny"
        }
    ])

    return []
3. added the action_server endpoint and the credentials for Telegram.
As you can see, the only modification done to the "init" project is to utter two buttons through a custom action when "did that help you?" is uttered.

**Deploy:** I am using docker-compose with `rasa/rasa:3.2.1-full` and `rasa/rasa-sdk:3.2.0` + `ngrok` to expose the service.

### Command / Request

_No response_

### Relevant log output

```shell
rasa_action_server                     | 2022-07-01 08:38:40 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
rasa_action_server                     | 2022-07-01 08:38:40 INFO     rasa_sdk.executor  - Registered function for 'action_utter_did_that_help'.
rasa_action_server                     | 2022-07-01 08:38:40 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055
rasa_action_server                     | 2022-07-01 08:39:13 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
rasa_action_server                     | 2022-07-01 08:39:13 INFO     rasa_sdk.executor  - Registered function for 'action_utter_did_that_help'.
rasa_action_server                     | 2022-07-01 08:39:13 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055
rasa_core                              | 2022-07-01 08:51:58 INFO     root  - Starting Rasa server on http://0.0.0.0:5005
rasa_core                              | 2022-07-01 08:52:00 INFO     rasa.core.processor  - Loading model models/20220701-085001-flashed-exercise.tar.gz...
rasa_core                              | 2022-07-01 08:52:15 WARNING  rasa.shared.utils.common  - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future 🔬 Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production.
rasa_core                              | 2022-07-01 08:52:21 INFO     root  - Rasa server is up and running.
rasa_core                              | 2022-07-01 08:52:59 ERROR    rasa.core.channels.telegram  - Exception when trying to handle message.A request to the Telegram API was unsuccessful. Error code: 403. Description: Forbidden: bot was blocked by the user
rasa_core                              | Exception occurred while handling uri: 'http://17b4-87-10-97-110.eu.ngrok.io/webhooks/telegram/webhook'
rasa_core                              | Traceback (most recent call last):
rasa_core                              |   File "handle_request", line 83, in handle_request
rasa_core                              |     )
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/telegram.py", line 259, in message
rasa_core                              |     await on_new_message(
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/channel.py", line 89, in handler
rasa_core                              |     await app.ctx.agent.handle_message(message)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/agent.py", line 420, in handle_message
rasa_core                              |     return await self.processor.handle_message(  # type: ignore[union-attr]
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/processor.py", line 149, in handle_message
rasa_core                              |     await self._run_prediction_loop(message.output_channel, tracker)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/processor.py", line 770, in _run_prediction_loop
rasa_core                              |     should_predict_another_action = await self._run_action(
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/processor.py", line 896, in _run_action
rasa_core                              |     await self.execute_side_effects(events, tracker, output_channel)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/processor.py", line 797, in execute_side_effects
rasa_core                              |     await self._send_bot_messages(events, tracker, output_channel)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/processor.py", line 813, in _send_bot_messages
rasa_core                              |     await output_channel.send_response(tracker.sender_id, e.message())
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/channel.py", line 233, in send_response
rasa_core                              |     await self.send_text_message(recipient_id, message.pop("text"), **message)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/telegram.py", line 41, in send_text_message
rasa_core                              |     self.send_message(recipient_id, message_part)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/telebot/__init__.py", line 1005, in send_message
rasa_core                              |     apihelper.send_message(
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/telebot/apihelper.py", line 267, in send_message
rasa_core                              |     return _make_request(token, method_url, params=payload, method='post')
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/telebot/apihelper.py", line 152, in _make_request
rasa_core                              |     json_result = _check_result(method_name, result)
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/telebot/apihelper.py", line 179, in _check_result
rasa_core                              |     raise ApiTelegramException(method_name, result, result_json)
rasa_core                              | telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 403. Description: Forbidden: bot was blocked by the user
rasa_core                              | Exception occurred while handling uri: 'http://17b4-87-10-97-110.eu.ngrok.io/webhooks/telegram/webhook'
rasa_core                              | Traceback (most recent call last):
rasa_core                              |   File "handle_request", line 83, in handle_request
rasa_core                              |     )
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/telegram.py", line 228, in message
rasa_core                              |     if self._is_user_message(msg):
rasa_core                              |   File "/opt/venv/lib/python3.8/site-packages/rasa/core/channels/telegram.py", line 180, in _is_user_message
rasa_core                              |     return message.text is not None
rasa_core                              | AttributeError: 'NoneType' object has no attribute 'text'
tommasodelorenzo commented 2 years ago

The problem was uttering buttons without "text" field. Solved!