Getting error in executing custom actions

Hi, I am facing an issue while executing rasa x command.

These all are my current versions python=3.6 tensorflow==2.3.0 SQLAlchemy==1.3.22

My bot is not responding and doesn’t following the exact flow most of the time. Also slots are not getting clear each time. Action server is running always.

Please help me to resolve this issue.

Check the action logs for more details (the terminal where you ran rasa run actions), the error is probably in your Python code.

Bot is responding few times actually. But, most of the time its not responding. Also, when its not working i will keep chatting (Since I know the flow). Then i will get the final response or if I am trying to enter the data into database it will insert. But, the bot will not send any response in return. here is my issue starting, when i typing new user, it should ask me the user details. instead I am getting other responses

Also when i am asking the details from database, its not responding.

Check the Action Server logs for any errors instead of the Rasa X logs

Use a print() statement inside the action, with the same content as utter_message() - if you see the message in the action logs but not Rasa X, it’s an error from Rasa X

I added print() to action.py

and my action logs look like I didn’t see any messages in rasa x logs

If you read the error, you can see your Python code is the problem.

tracker.latest_message['text'] does not include a : and therefore it does not split.

Thanks, that issue is solved. Again I am facing the same old issue.

The error is written clearly again :slight_smile: Please try to read the error as they are helpful most of time, and you won’t have to wait for someone to answer.

The error states "pymysql.err.IntegrityError: (1048, "Column 'password' cannot be null")" (first image), and in your SQL statement (last image), we can see that you are indeed trying to insert None in all columns.

In the future, instead of screenshots, please paste your code enclosed with three backticks to properly format it and for the people to be able to copy-paste.

```
like this
```

Finally, the issues you’re getting are not with Rasa, but with Python. I suggest posting the error and code on Stack Overflow since it’s more appropriate.

Actually, bot is not responding, that’s why i am not able to insert the details

The bot is not responding because you have an error in the first place

Please show your code, I’ll try to help

Please delete your message and paste it with my suggestion above, the code is unreadable as you sent it.

Also please only include the relevant action.

This is my database.py

import sqlalchemy
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy import create_engine
#from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy import engine
from sqlalchemy.engine.interfaces import CreateEnginePlugin
from sqlalchemy.orm import create_session, sessionmaker
from sqlalchemy.sql.schema import Table
from sqlalchemy.sql.sqltypes import SmallInteger, VARCHAR
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

class user(Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key= True)
    realm = Column(String(512))
    username = Column(String(512))
    password = Column(String(512))
    email = Column(String(512))
    emailVerified = Column(SmallInteger)
    verificationToken = Column(String(512)) 
    userLanguage = Column(String(512))
    

    def __repr__(self):
        return "<testuserbot(id= '%d', realm= '%s', username='%s', password = '%s', email='%s', emailVerified= '%d', verificationToken = '%s', userLanguage='%s')>" % (
                                self.id, self.realm, self.username, self.password, self.email, self.emailVerified, self.verificationToken, self.userLanguage)

def UpdateUserDetails( username,email, userLanguage, password):
    #engine = create_engine("mysql+pymysql://finuser:Stablehacks123@35.193.164.234:3306/finance")
    engine = create_engine("mysql+pymysql://finuser@devtrustd:Stablehacks123@devtrustd.mysql.database.azure.com/finance")
    metadata = MetaData()
    Session = sessionmaker(bind=engine)
    Session = sessionmaker()
    Session.configure(bind=engine)
    session = Session()
    update_user = user ( username=username,  email = email, userLanguage = userLanguage, password = password )
    session.add(update_user)
    session.commit()

action.py

from typing import Any, Text, Dict, List, Union

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
#from rasa_sdk.forms import FormAction
from rasa_sdk.events import SlotSet, EventType
from rasa_sdk.types import DomainDict
from database import UpdateUserDetails
class ValidateUserDetailsForm(Action):
    def name(self) -> Text:
        return "user_details_form"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        required_slots = ["username", "email", "userLanguage", "password"]

        for slot_name in required_slots:
            if tracker.slots.get(slot_name) is None:
                # The slot is not yet filled, request user to fill this slot next
                return [SlotSet("requested_slot", slot_name)]

        # All slots filled 
        return [SlotSet("requested_slot", None)]
        
class ActionSubmit(Action):
    def name(self) -> Text:
        return "action_submit"

    def run(
        self,
        dispatcher,
        tracker:Tracker,
        domain: "DomainDict",
    ) -> List[Dict[Text, Any]]:
        dispatcher.utter_message(response="utter_thankyou_details", username = tracker.get_slot("username"), email = tracker.get_slot("email"), userLanguage = tracker.get_slot("userLanguage"), password = tracker.get_slot("password"))
        UpdateUserDetails(tracker.get_slot("username"),tracker.get_slot("email"), tracker.get_slot("userLanguage"), tracker.get_slot("password"))
        dispatcher.utter_message("Thank You for your valuable time and information. Info has been saved in our records.")
        dispatcher.utter_message(template = "utter_ask_type_program_info")
        return []
1 Like

Thanks for formatting :slight_smile:

Okay so what’s happening is that all your tracker.get_slots are returning None, which means the slots were not filled in the first place.

How are you filling them? Are you using a Form as you should?

yes, here is my domain.yml

version: '2.0'
config:
  store_entities_as_slots: true
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true
intents:
- tell_new_user:
    use_entities: true
- know_about_multi_bot:
    use_entities: true
- tell_name:
    use_entities:
    - username
- tell_email:
    use_entities:
    - email
- tell_language:
    use_entities:
    - userLanguage
- tell_password:
    use_entities:
    - password
- thank_you:
    use_entities: true
- affirm_user_details:
    use_entities: true
entities:
- username
- email
- userLanguage
- password
- userId
slots:
  userId:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: false
    influence_conversation: true
  username:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: false
    influence_conversation: true
  email:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: false
    influence_conversation: true
  userLanguage:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: false
    influence_conversation: true
  password:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: false
    influence_conversation: true
responses:
utter_ask_username:
  - text: What is your name?
  utter_ask_email:
  - text: what is your email address?
  utter_ask_userLanguage:
  - text: What is your preferred language? English or French?
  utter_confirm_details:
  - text: Please confirm whether details provided are correct?, yes or no?
  utter_thankyou_details:
  - text: |-
      Thank You for providing the details.
       username : {username}
       email : {email}
       userLanguage : {userLanguage}
       password : {password}
  utter_new_exhist_user:
  - text: Do you want to register or continue?
  utter_ask_password:
  - text: Please provide password.
  utter_ask_user_details:
  - text: Well, I need some information of yours before proceeding, is that ok?.
actions:
- utter_ask_user_details
- utter_new_exhist_user
- utter_thankyou_details
- utter_confirm_details
- utter_ask_userLanguage
- utter_ask_email
- utter_ask_password
- utter_ask_username
- action_submit
forms:
  user_details_form:
    required_slots:
      email:
      - entity: email
        type: from_text
      password:
      - entity: password
        type: from_text
      userLanguage:
      - entity: userLanguage
        type: from_text
      username:
      - entity: username
        type: from_text
e2e_actions: []

Can you show me the full conversation on Rasa X?

Please also include the sidebar on the right which shows the story and the slots.

yes,

the bot will stop responding like this

You’re not settings the slots :sweat_smile:

You did not provide username, email, userLanguage, password anywhere.

bot is not giving me the provision to enter it. sometimes it is working smoothly.

since i know the flow i am entering the email. and as the next step bot is asking me for the password,

once i entered it bot is again stopped.

You should make sure that the slots are set before executing the action anyway:

class ActionSubmit(Action):
    def name(self):
        return "action_submit"

    def run(self, dispatcher, tracker, domain):
        username = tracker.get_slot("username")
        email = tracker.get_slot("email")
        userLanguage = tracker.get_slot("userLanguage")
        password = tracker.get_slot("password")

        if not (username and email and userLanguage  and password):
            dispatcher.utter_message("Please enter your information")
            return []

        dispatcher.utter_message(response="utter_thankyou_details", username = username, email = email, userLanguage = userLanguage, password = password)
        UpdateUserDetails(username, email, userLanguage, password)
        dispatcher.utter_message("Thank You for your valuable time and information. Info has been saved in our records.")
        dispatcher.utter_message(template = "utter_ask_type_program_info")
        return []