def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') if email: client = MailChimpAPI(config.mailchimp_api_key) subscribed = client.subscribe_user(config.mailchimp_list, email) return [SlotSet('subscribed', subscribed)] return []
def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') if email: client = MailChimpAPI(config.mailchimp_api_key) # if the email is already subscribed, this returns False subscribed = client.subscribe_user(config.mailchimp_list, email) return [SlotSet('subscribed', subscribed)] return []
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) return []
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}