Thank you for your information. So is there any way to send a default mail to senders
please guide me
actions.py import logging from datetime import datetime from typing import Text, Dict, Any, List import json
from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.forms import FormAction from rasa_sdk.events import SlotSet, UserUtteranceReverted, ConversationPaused
import requests class ActionStoreEmail(Action): “”“Stores the email in a slot”""
def name(self):
return "action_store_email"
def run(self, dispatcher, tracker, domain):
email = next(tracker.get_latest_entity_values('email'), None)
# if no email entity was recognised, prompt the user to enter a valid
# email and go back a turn in the conversation to ensure future
# predictions aren't affected
if not email:
email = tracker.latest_message.get('text')
dispatcher.utter_message("We need your email, "
"please enter a valid one.")
return [UserUtteranceReverted()]
return [SlotSet('email', email)]
class sendmail(FormAction): def name(self): return “action_sendmail”
@staticmethod
def required_slots(tracker):
return ["email"]
def slot_mappings(self):
return {
"email": [
self.from_entity(entity="email"),
self.from_text(intent="enter_data"),
]
}
def validate_email(self, value, dispatcher, tracker, domain):
"""Check to see if an email entity was actually picked up by duckling."""
if any(tracker.get_latest_entity_values("email")):
# entity was picked up, validate slot
return {"email": value}
else:
# no entity was picked up, we want to ask again
dispatcher.utter_template("utter_no_email", tracker)
return {"email": None}
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
"""Once we have an email, attempt to add it to the database"""
email = tracker.get_slot("email")
client = MailChimpAPI(config.mailchimp_api_key)
# if the email is already subscribed, this returns False
added_to_list = client.subscribe_user(config.mailchimp_list, email)
# utter submit template
if added_to_list:
dispatcher.utter_template("utter_confirmationemail", tracker)
else:
dispatcher.utter_template("utter_already_subscribed", tracker)
def run(self, dispatcher, tracker,domain):
import requests
from email.message import EmailMessage
From= tracker.get_slot("From")
To= tracker.get_slot("email")
User= tracker.get_slot("name")
msg= EmailMessage()
msg['Subject']= ("Thank You For Your visit ")
msg[To]= 'receving_email_address'
msg.set_content("Hi,/n I am Alisa from ")
response = unirest.post("https://OutlookMailstefan-skliarovV1.p.rapidapi.com/sendMessage",
headers={
"X-RapidAPI-Host": "OutlookMailstefan-skliarovV1.p.rapidapi.com",
"X-RapidAPI-Key": "4f0e828645msh38bfffaf5438379p18ee2bjsn93ce93b0cd4f",
"Content-Type": "application/x-www-form-urlencoded"
} )
return []
i have written code like above , but the problem here is now bot prediction was wrong.