Rasa Actions to send an email

I need my RASA chatbot to read details from a csv file and send it as an email. I have already written python code for the same. but have no idea how to implement it as a rasa custom action. is it possible to do that ? Can anyone help me

If you’ve already written a Python code to do that, then it’s done :slight_smile:

You just need to create a custom action and put that code in the run() method of the action.

For example:

class ActionSendMail(Action):
    def name(self):
        return 'action_send_mail'

    def run(self, dispatcher, tracker, domain):
        # your code here
        return []

Will it read the csv file if i keep it in the actions folder ?

And also I am getting this error in the training data YamlValidationException: Failed to validate. Please make sure the file is correct and all mandatory parameters are specified. Here are the errors found during validation

Can u help me with this

hey @RiyaMathew-11 , yes it will work. You can write in the action sever or else another scenario (if you have long python code) then you can write your python code inside action folder and in the action server you can import it. In both the cases it will work.

1 Like

hey @RiyaMathew-11 , check your file where the yaml validation errors came up. As RASA is very strict with yaml validation and indentations.

1 Like

What if I have to add an additional argument in the function, like entity ‘name’ I get from the user and search name in the csv file ? I can add it too r8 ?

Yes, you can write whatever Python code you like in the custom actions. Just call your function with whatever arguments you desire from the run() method of a custom action.