Trying to send email through chatbot but slots error ocuuring

@nik202
rasa train Traceback (most recent call last): File “c:\users\admin\anaconda3\envs\rasax_test\lib\runpy.py”, line 193, in run_module_as_main “main”, mod_spec) File “c:\users\admin\anaconda3\envs\rasax_test\lib\runpy.py”, line 85, in run_code exec(code, run_globals) File "C:\Users\Admin\anaconda3\envs\rasaX_test\Scripts\rasa.exe_main.py", line 7, in File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa_main.py", line 117, in main cmdline_arguments.func(cmdline_arguments) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\cli\train.py”, line 59, in train_parser.set_defaults(func=lambda args: run_training(args, can_exit=True)) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\cli\train.py”, line 103, in run_training finetuning_epoch_fraction=args.epoch_fraction, File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\api.py”, line 124, in train loop, File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\utils\common.py”, line 296, in run_in_loop result = loop.run_until_complete(f) File “c:\users\admin\anaconda3\envs\rasax_test\lib\asyncio\base_events.py”, line 587, in run_until_complete return future.result() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\model_training.py”, line 100, in train_async domain = await file_importer.get_domain() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\utils\common.py”, line 141, in decorated return await cache.cached_result() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py”, line 449, in get_domain
self.importer.get_domain(), self._get_domain_with_e2e_actions() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py”, line 455, in _get_domain_with_e2e_actions stories = await self.get_stories() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py”, line 491, in get_stories template_variables, use_e2e, exclusion_percentage File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py”, line 400, in get_stories template_variables, use_e2e, exclusion_percentage File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\utils\common.py”, line 141, in decorated return await cache.cached_result() File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py”, line 272, in get_stories stories = await asyncio.gather(*stories) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\rasa.py”, line 55, in get_stories
await self.get_domain(), File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\rasa.py”, line 79, in get_domain
domain = Domain.load(self._domain_path) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 151, in load other = cls.from_path(path) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 161, in from_path domain = cls.from_file(path) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 175, in from_file return cls.from_yaml(rasa.shared.utils.io.read_file(path), path) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 188, in from_yaml return cls.from_dict(data) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 204, in from_dict slots = cls.collect_slots(data.get(KEY_SLOTS, {})) File “c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py”, line 327, in collect_slots
slot_type = slot_dict[slot_name].pop(“type”, None) TypeError: pop() takes at most 1 argument (2 given)

(rasaX_test) C:\Users\Admin\Desktop\rasa_conda>

Hello, please read How to ask a great question.

Pasting error logs without context isn’t of much use (and isn’t great to look at without the proper formatting!).

  • Can you share the code that results in this error?
  • Does the bot work without this piece of code?
  • How does sending an email result in a slot-related error?

Please don’t share console output and code output by copy-pasting or by screenshot. To properly format code, use three backticks (```) before and after the code

```
like so
```

Be careful of the typo here. It’s “message” not “massage”.

And where’s the action used to send emails?

By the way, to format code, use three backticks (```) not three apostrophes (’’’). The backticks are usually found under the Esc key along with ~.

@nik202

action code-

# #for sending an email
#import webbrowser
# class ActionSubmit(Action):
#     def name(self) -> Text:
#         return "action_submit"

#     async def run(self, dispatcher:,tracker: Tracker,domain: "DomainDict") -> List[Dict[Text, Any]]:
#         SendEmail(
#                 tracker.get_slot("email"),
#                 tracker.get_slot("subject"),
#                 tracker.get_slot("message")
#             )
#             dispatcher.utter_message("Thanks for providing the details.We have sent you email at {}".format(tracker.get_slot())) #<--------calling Correctly?
#             return []

# def SendEmail(toaddr,subject,message):
#     fromaddr=   "E-mail address"
#     #instance of mimemultipart
#     msg=MIMEMultipart()
#     #storing the sender msg address
#     msg['From']=fromaddr
#     #storing the receivers email addrss
#     msg['To']=toaddr
#     #store the subject
#     msg['Subject']=subject
#     #strin g to store the body of email
#     body=message
#     #attach the body with the body instance
#     msg.attach(MIMEText(body,'plain'))
#     s=smtplib.SMTP('smtp.gmail.com',587)
#     #start tls for security
#     s.starttls()

#     #Authenticaton
#     try:
#         s.login(fromaddr,"password")
#         #Convert multipart msg into string
#         text=msg.as_string()

#         #sending the mail
#         s.sendmail(fromaddr, toaddr ,text)
#     except:
#         print("An error occurd while sending email.")
#     finally:
#         #terminating the session
#         s.quit()


Does your action server logs (the terminal in which you ran rasa run action) prints any error after the action runs?

Also, try to place the definition of the function above the class, not below.

@ChrisRahme its showing the same error output

 slot_type = slot_dict[slot_name].pop("type", None)
TypeError: pop() takes at most 1 argument (2 given)

And This is my action command prompt output it runs without error ;

(rasaX_test) C:\Users\Admin\Desktop\rasa_conda>rasa run actions
2021-09-30 10:26:08 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2021-09-30 10:26:08 INFO     rasa_sdk.executor  - Registered function for 'action_service'.
2021-09-30 10:26:08 INFO     rasa_sdk.executor  - Registered function for 'action_time_show'.
2021-09-30 10:26:08 INFO     rasa_sdk.executor  - Registered function for 'action_video'.
2021-09-30 10:26:08 INFO     rasa_sdk.executor  - Registered function for 'action_submit'.
2021-09-30 10:26:08 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055

@Ncool1165 can you tell what steps are you using and please share the action.py file for the reference.

wanted to send email through chatbot
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
#from email.message import EmailMessage


#for buttons
class Actionservice(Action):
    def name(self) -> Text:
        return "action_service"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
             #new
             buttons=[
                 {"payload":'/docs{"content_type":"docs"}',"title":"Documentation"},
                 {"payload":'/Audio{"content_type":"Audio"}',"title":"Audio call"},
                 #new buttons for h/w,s/w and suggestions
                 {"payload":'/Hardware{"content_type":"Hardware"}',"title":"Hardware Issue"},
                 {"payload":'/software{"content_type":"software"}',"title":"software Issue"},
                 {"payload":'/suggestion{"content_type":"suggestion"}',"title":"suggestion"},

                 #new buttons for H/W issues like -  No power,   Wifi,   Keyboard
                 {"payload":'/Power{"Power_type":"Power"}',"title":"Power"},
                 {"payload":'/WiFi{"WiFi_type":"WiFi"}',"title":"WiFi"},
                 {"payload":'/keybord{"keybord_type":"keybord"}',"title":"keybord"},

             ]
             dispatcher.utter_message(text="What kind of service you want to use..!",buttons=buttons)
             return []

#for time
import datetime as dt
class DateTimeservice(Action):
    def name(self) -> Text:
        return "action_time_show"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
            dispatcher.utter_message(text=f"Its {dt.datetime.now()}")
            return []

#for project information through video
import webbrowser
class ActionVideo(Action):
    def name(self) -> Text:
        return "action_video"

    async def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
            video_url="https://www.youtube.com/watch?v=r1ajepp8sd4"
            dispatcher.utter_message("wait.....playing a video")
            webbrowser.open(video_url)
            return []

#for Power,WiFi,kyeboard
"""class Actionservice(Action):
    def name(self) -> Text:
        return "sub_service"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
             #new
             buttons1=[
                 #new buttons for H/W issues like -  No power,   Wifi,   Keyboard
                 {"payload":'/Power{"content_type":"Power"}',"title":"Power"},
                 {"payload":'/WiFi{"content_type":"WiFi"}',"title":"WiFi"},
                 {"payload":'/keybord{"content_type":"keybord"}',"title":"keybord"},

             ]
             dispatcher.utter_message(text="Which kind of service you want to use..!",buttons=buttons1)
             return []"""


def SendEmail(toaddr,subject,message):
    fromaddr= "emailid"
    #instance of mimemultipart
    msg= MIMEMultipart()
    #storing the sender msg address
    msg['From']= fromaddr
    #storing the receivers email addrss
    msg['To']= toaddr
    #store the subject
    msg['Subject']= subject
    #strin g to store the body of email
    body= message
    #attach the body with the body instance
    msg.attach(MIMEText(body,'plain'))
    server=smtplib.SMTP('smtp.gmail.com',465)
    #start tls for security
    server.starttls()

    #Authenticaton
    try:
        server.login(fromaddr,"password")
        #Convert multipart msg into string
        text=msg.as_string()

        #sending the mail
        server.sendmail(fromaddr,toaddr,text)
    except:
        print("An error occurd while sending email.")
    finally:
        #terminating the session
        server.quit()



#for sending an email
class ActionSubmit(Action):
    def name(self) -> Text:
        return "action_submit"

    def run(self, 
            dispatcher,
            tracker: Tracker,
            domain: DomainDict,
    ) -> List[Dict[Text, Any]]:
        
        SendEmail(
                tracker.get_slot("email"),
                tracker.get_slot("subject"),
                tracker.get_slot("message")
        )
        dispatcher.utter_message("Thanks for providing the details.We have sent you email at {}".format(tracker.get_slot("email")))
        return []



@Ncool1165 check the code again, for ActionSubmit class please and update the above post.

Does this work?

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

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

        SendEmail(
            email,
            tracker.get_slot("subject"),
            tracker.get_slot("message")
        )

        dispatcher.utter_message(f"Thanks for providing the details.We have sent you email at {email}")
        return []

I guess this is right know??

def SendEmail(toaddr,subject,message):

    fromaddr= "*******@gmail"

    #instance of mimemultipart

    msg= MIMEMultipart()

    #storing the sender msg address

    msg['From']= fromaddr

    #storing the receivers email addrss

    msg['To']= toaddr

    #store the subject

    msg['Subject']= subject

    #strin g to store the body of email

    body= message

    #attach the body with the body instance

    msg.attach(MIMEText(body,'plain'))

    server=smtplib.SMTP('smtp.gmail.com',465)

    #start tls for security

    server.starttls()

    #Authenticaton

    try:

        server.login(fromaddr,"password")

        #Convert multipart msg into string

        text=msg.as_string()

        #sending the mail

        server.sendmail(fromaddr,toaddr,text)

    except:

        print("An error occurd while sending email.")

    finally:

        #terminating the session

        server.quit()

#for sending an email

class ActionSubmit(Action):

    def name(self) -> Text:

        return "action_submit"

    def run(self, 

            dispatcher,

            tracker: Tracker,

            domain: DomainDict,

    ) -> List[Dict[Text, Any]]:

        

        SendEmail(

                tracker.get_slot("email"),

                tracker.get_slot("subject"),

                tracker.get_slot("message")

        )

        dispatcher.utter_message("Thanks for providing the details.We have sent you email at {}".format(tracker.get_slot("email")))

        return []

No, its not working sir…same issue there

 File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 204, in from_dict
    slots = cls.collect_slots(data.get(KEY_SLOTS, {}))
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 327, in collect_slots      
    slot_type = slot_dict[slot_name].pop("type", None)
TypeError: pop() takes at most 1 argument (2 given)

Is this the full error? If not, please send it all

this is full error

rasaX_test) C:\Users\Admin\Desktop\rasa_conda>rasa train
Traceback (most recent call last):
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Admin\anaconda3\envs\rasaX_test\Scripts\rasa.exe\__main__.py", line 7, in <module>
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\__main__.py", line 117, in main
    cmdline_arguments.func(cmdline_arguments)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\cli\train.py", line 59, in <lambda>     
    train_parser.set_defaults(func=lambda args: run_training(args, can_exit=True))
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\cli\train.py", line 103, in run_training
    finetuning_epoch_fraction=args.epoch_fraction,
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\api.py", line 124, in train
    loop,
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\utils\common.py", line 296, in run_in_loop     
    result = loop.run_until_complete(f)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\model_training.py", line 100, in train_async   
    domain = await file_importer.get_domain()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\utils\common.py", line 141, in decorated
    return await cache.cached_result()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py", line 449, in get_domain  
    self.importer.get_domain(), self._get_domain_with_e2e_actions()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py", line 455, in _get_domain_with_e2e_actions
    stories = await self.get_stories()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py", line 491, in get_stories 
    template_variables, use_e2e, exclusion_percentage
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py", line 400, in get_stories
    template_variables, use_e2e, exclusion_percentage
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\utils\common.py", line 141, in decorated
    return await cache.cached_result()
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\importer.py", line 272, in get_stories 
    stories = await asyncio.gather(*stories)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\rasa.py", line 55, in get_stories      
    await self.get_domain(),
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\importers\rasa.py", line 79, in get_domain       
    domain = Domain.load(self._domain_path)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 151, in load
    other = cls.from_path(path)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 161, in from_path
    domain = cls.from_file(path)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 175, in from_file
    return cls.from_yaml(rasa.shared.utils.io.read_file(path), path)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 188, in from_yaml
    return cls.from_dict(data)
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 204, in from_dict
    slots = cls.collect_slots(data.get(KEY_SLOTS, {}))
  File "c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\shared\core\domain.py", line 327, in collect_slots      
    slot_type = slot_dict[slot_name].pop("type", None)
TypeError: pop() takes at most 1 argument (2 given)

Can you share your domain file please?


version: '2.0'
config:
  store_entities_as_slots: true
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true
#############################################################  
intents:
- greet:
    use_entities: true
- goodbye:
    use_entities: true
- affirm:
    use_entities: true
- deny:
    use_entities: true
- mood_great:
    use_entities: true
- mood_unhappy:
    use_entities: true
- bot_challenge:
    use_entities: true
- age:
    use_entities: true
- docs:
    use_entities: true
- Audio:
    use_entities: true
- help:
    use_entities: true
- ask:
    use_entities: true
- city:
    use_entities: true
- Hardware:
    use_entities: true
- software:
    use_entities: true
- suggestion:
    use_entities: true
- give_time:
    use_entities: true
- play_video:
    use_entities: true
- Power:
    use_entities: true
- WiFi:
    use_entities: true
- keybord:
    use_entities: true

#############################################################  
entities:
- content_type
- Power_type
- WiFi_type
- keybord_type
- email_type
# - email
# - subject
# - message
slots:
    email:
    -   type: text
    subject:
    -   type: text
    message:
    -   type: text
    content_type:
        type: rasa.shared.core.slots.TextSlot
        initial_value: null
        auto_fill: true
        influence_conversation: true
responses:
  utter_greet:
  - text: Hey! How are you?how may assist you?
  - buttons:
    - payload: /Hardware
      title: Hardware Issue
    - payload: /software
      title: software Issue
    - payload: /suggestion
      title: suggestion
    text: please select,which Problem are you facing
  utter_cheer_up:
  - image: https://i.imgur.com/nGF1K8f.jpg
    text: 'Here is something to cheer you up:'
  utter_did_that_help:
  - text: Did that help you?
  utter_happy:
  - text: Great, carry on!
  utter_goodbye:
  - text: Bye
  utter_iamabot:
  - text: I am a bot, an AIprogram to help You.
  utter_age:
  - text: I am created by human,they did't told me
  utter_docs:
  - text: Here is the [documentation link](https://rasa.com/docs/rasa/) for you to learn everything
  utter_Audio:
  - text: '1234567890'
  utter_help:
  - text: what kind of help you need
  utter_ask:
  - text: do You want anything else
  utter_city:
  - text: What are you actully looking for in this city
  utter_Hardware:
  - buttons:
    - payload: /Power
      title: Power
    - payload: /WiFi
      title: WiFi
    - payload: /keybord
      title: keybord
    text: please select,which Problem are you facing
  utter_software:
  - text: 1)please see the Computer permissions for that software 2)re-install that software 3)If no issue solved contact to support team (type-Audio)
  utter_suggestion:
  - text: please enter your suggestions to send to gmail
  utter_Power:
  - text: 1)Check Adapter2)Change Power Scoket3)Check Battery
  utter_WiFi:
  - text: 1)Check Wifi Button on kyboard2)Check Wifi Driver
  utter_keybord:
  - text: 1)Check ON/OFF Buttons,Keys are active or not.2)Type "contact" to get support team number.
  utter_ask_email:
  - text: Please provide an Email id whom you want to email.
  utter_ask_subject:
  - text: Please provide subject for your email.
  utter_ask_message:
  - text: Please provide message for your email.

#############################################################  
actions:
- action_service
- action_time_show
- action_video
- action_submit

#############################################################  

forms: #{}
 - email_form:
    - email:
        - type: from_text
    - subject:
        - type: from_text
    - message:
        - type: from_text
    
#############################################################  
e2e_actions: []

Some indentations and formats (positions of -) are not correct.

Try changing slots and forms to these please:

slots:
  email:
    type: text
  subject:
    type: text
  message:
    type: text
  content_type:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
forms:
  email_form:
    required_slots:
      email:
      - type: from_text
      subject:
      - type: from_text
      message:
      - type: from_text

You can use this as reference.

Thank you its solved but new error occur
2021-09-30 19:24:04 INFO     rasa.model  - Data (core-config) for Core model section changed.
2021-09-30 19:24:04 INFO     rasa.model  - Data (nlu-config) for NLU model section changed.
2021-09-30 19:24:04 INFO     rasa.model  - Data (nlg) for NLG responses section changed.
Training NLU model...
c:\users\admin\anaconda3\envs\rasax_test\lib\site-packages\rasa\utils\train_utils.py:646: UserWarning: constrain_similarities is set to `False`. It is recommended to set it to `True` when using cross-entropy loss. It will be set to `True` by default, Rasa 
Open Source 3.0.0 onwards.
  category=UserWarning,
InvalidConfigException: The pipeline configuration contains more than one tokenizer, which is not possible at this time. You can only use one tokenizer. The pipeline contains the following tokenizers: ['WhitespaceTokenizer', 'WhitespaceTokenizer', 'WhitespaceTokenizer'].

Great, please mark the solution and post the new error in a new thread :slight_smile: I’ll join you there if I can help

Yes,sure thank You so much…for this… :wink:

1 Like