def run( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[EventType]: """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_message(template="utter_confirmationemail") else: dispatcher.utter_message(template="utter_already_subscribed") return []
def validate_email( self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> Dict[Text, Any]: if MailChimpAPI.is_valid_email(value): return {"email": value} else: dispatcher.utter_message(template="utter_no_email") return {"email": None}
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, # check if mailchimp will accept it as a valid email if MailChimpAPI.is_valid_email(value): # validate slot return {"email": value} else: dispatcher.utter_message(template="utter_no_email") return {"email": None} else: # no entity was picked up, we want to ask again dispatcher.utter_message(template="utter_no_email") return {"email": None}