Peileppe

Agent-Bob

Mar 5th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. #   Dictionnary based Eliza type program
  4. #   that will emulate a call-centre agent named Bob
  5. #   http://www.peileppe.com
  6. #   ======================================================================
  7. #   Monday 03 March 2014 [11:30]
  8. #  
  9.  
  10. dict1= {
  11.     " hello " : ['What seems to be the problem, sir?','How may I help, sir', 'How are you, sir?'],
  12.     " bye ":['Thanks for calling call-centre Grinder support','Thanks for calling the help-line','Thanks for your call, sir'],
  13.     " how ":['good question','I don\'t know, I will have to transfer this to the customer service department','Well, it\'s out of support as far as I\'m concerned'],
  14.     " why ":['This issue has been resolved with the latest version','mmh, I don\'t know, I will have to transfer this to the customer service department','We will investigate'],
  15.     " who ":['why do you want to know?','the name should be on the receipt','the name might be at the end of the invoice'],
  16.     " where ":['I\'m sure you can find this information in the user manual','I don\'t know where exactly I\'m checking the FAQ','I might need to escalate this to the other team'],
  17.     " when ":['our lines open at 7am and end at 7pm 7 days a week','We also work week-end','There is an early shift, and a late shift'],
  18.     " name ":['Sir, we are not supposed to give you our full name','My name is Bob','Bob is my name'],
  19.     " thank":['don\'t mention it','You\'re welcome','at your service, Sir'],
  20.     " manager ":['My manager is not at his desk, right now - do you want me to arrange a call back?','My manager can take the call, please hold-on','Please, hold-on, Sir'],
  21.     " could ":['is it true?','I don\'t know if that\'s possible','challenging'],
  22.     " can ": ['is it really true?','If that\'s possible, of course','Really?'],
  23.     " issue ":['I will need your serial number','I need to fill your caller ID','When was your last call?'],
  24.     " problem ":['This is a common issue','Does it occurs after an update?','Is it a problem that re-appear from time to time?'],
  25.     " must ":['I\'m not sure of that','why?','Any other options?'],
  26.     " grinder ":['This is the Call-centre support center','That\'s us here in the Call-centre','Call-Centre Grinder, yes Sir!'],
  27.     "_nokey_":['Can you rephrase that, please?','why would you say that?','usually, that is considered out of support']
  28.     }
  29.  
  30.  
  31. print ("Hi, my name is Bob how may I help you?!")
  32. loop1=True
  33. previous_input='empty'
  34. answer_loop=0
  35. while loop1:
  36.     input=raw_input("Caller: ")
  37.     input=" "+input.replace("\"","")+" "
  38.     while input.count("  ") >0:
  39.         input=input.replace("  "," ")
  40.     input=input.lower()
  41.     if input.count("bye") or input.count("quit") or input.count("exit") > 0 :
  42.         print "Okay, talk to you later ..."
  43.         loop1=False
  44.         break
  45.     elif input==previous_input:
  46.         print "You already said that"
  47.     else:
  48.         keyword="_nokey_"
  49.         for k in dict1:
  50.             if k in input:
  51.                 keyword=k
  52.                 break
  53.         print "Bob: "+dict1[keyword][answer_loop]
  54.         answer_loop+=1
  55.         if answer_loop > 2:
  56.             answer_loop=0
  57.     previous_input=input
Advertisement
Add Comment
Please, Sign In to add comment