class App(AppBase):
pattern = re.compile(r'^phone\s+',re.IGNORECASE)
def start (self):
"""Configure your app in the start phase."""
pass
def _parse_message(self, message):
parts = message.text.split()[1:] # exclude the keyword (e.g., "phone")
#print parts;
index = ''
fname=''
lname=''
phonenumber=''
if parts.__len__()==4:
index=parts[0]
fname=parts[1]
lname=parts[2]
phonenumber=parts[3]
return index, fname, lname, phonenumber
def handle(self,message):
response =message.text.lower()
#keyword is valid
if response.startswith('phone'):
index, fname, lname, phonenumber = self._parse_message(message)
AddressBook(
index,
fname,
lname,
phonenumber,
datecreated=datetime.datetime.today()).save()
message.respond("Thank you %s,you are registered!")
else:
message.respond("Wrong message format!")
def cleanup (self, message):
"""Perform any clean up after all handlers have run in the
cleanup phase."""
pass
def outgoing (self, message):
"""Handle outgoing message notifications."""
pass
def stop (self):
"""Perform global app cleanup when the application is stopped."""
pass