You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import bot_app.fulfillment.utility as util
  2. '''
  3. Intent - buying_drink
  4. '''
  5. # 確認訂單
  6. def ordering_summary(fulfillment):
  7. context = util.lookup_context(fulfillment, 'buying_drink_ordering-followup')
  8. params = context.get('parameters')
  9. strResp = '您的訂購資訊如下:\n飲料: ' + params['hot_cold'] + params['drink_item.original'] + '\n數量: ' + str(params['number']) + '\n甜度冰塊: ' + params['ice_level'] + '' + params['sugar_level'] + '\n\n請問是否訂購?'
  10. return util.simple_response(strResp)
  11. # 詢問飲料種類
  12. def ask_category(fulfillment):
  13. params = util.lookup_context(fulfillment, 'buying_drink_dialog_context').get('parameters')
  14. drinks = {'咖啡': ['美式', '拿鐵', '卡布奇諾'], '': ['紅茶', '綠茶', '烏龍茶'], '果汁': ['芒果汁', '檸檬汁', '芭樂汁']}
  15. drink_cate = params.get('drink_category')
  16. hot_cold = params.get('hot_cold')
  17. drink_item = params.get('drink_item')
  18. response_str = '我們有'
  19. if not drink_item == '':
  20. if drink_item in sum([x for x in drinks.values()], []):
  21. return util.simple_response(response_str + drink_item['drink_item'])
  22. else:
  23. return util.simple_response('抱歉!我們沒有' + drink_item['drink_item'])
  24. else:
  25. if not drink_cate == '':
  26. return util.simple_response(response_str + ','.join(drinks.get(drink_cate)))
  27. else:
  28. return util.simple_response(response_str + ','.join(list(drinks.keys())))
  29. return util.simple_response('')
  30. # fulfillment - 訂飲料
  31. def ordering(fulfillment):
  32. params = fulfillment.get('queryResult').get('parameters')
  33. deliver_method = params.get('deliver_method', '')
  34. drink_item = params.get('drink_item.original', '')
  35. ice_level = params.get('ice_level', '')
  36. sugar_level = params.get('sugar_level', '')
  37. number = params.get('number', '')
  38. if deliver_method == '外送':
  39. jsonRep = {
  40. 'followupEventInput': {
  41. 'name': 'events_deliver_info',
  42. 'languageCode': 'zh-TW',
  43. 'parameters': {}
  44. }
  45. }
  46. else:
  47. jsonRep = {
  48. 'followupEventInput': {
  49. 'name': 'events_order_confirm',
  50. 'languageCode': 'zh-TW',
  51. 'parameters': {}
  52. }
  53. }
  54. return util.simple_response(fulfillmentObj=jsonRep)
  55. # strResp = '您的訂購資訊如下:\n飲料: ' + drink_item + '\n數量: ' + str(number) + '\n甜度冰塊: ' + ice_level + '' + sugar_level + '\n\n請問是否訂購?'
  56. #
  57. # return sample_response(strResp)
  58. # 確認地址
  59. def ordering_delivery_info(fulfillment):
  60. print(fulfillment)
  61. return util.simple_response(fulfillmentObj={
  62. 'followupEventInput': {
  63. 'name': 'events_order_confirm',
  64. 'languageCode': 'zh-TW',
  65. 'parameters': {}
  66. }
  67. })
  68. def init_app(app):
  69. pass