website_livechat_chatbot_flow.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /** @odoo-module */
  2. import tour from "web_tour.tour";
  3. // Due to some issue with assets bundles, the current file can be loaded while
  4. // LivechatButtonView isn't, causing the patch to fail as the original model was
  5. // not registered beforehand. The following import is intended to stop the
  6. // execution of this file if @im_livechat/public_models/livechat_button_view is
  7. // not part of the current assets bundles (as trying to import it will silently
  8. // crash).
  9. import "@im_livechat/public_models/livechat_button_view";
  10. const messagesContain = (text) => `div.o_thread_message_content:contains("${text}")`;
  11. tour.register('website_livechat_chatbot_flow_tour', {
  12. test: true,
  13. }, [{
  14. trigger: messagesContain("Hello! I'm a bot!"),
  15. async run() {
  16. const { messaging } = await odoo.__DEBUG__;
  17. /**
  18. * Make it a bit faster than the default delay (3500ms).
  19. * Also debounce waiting for more user inputs for only 500ms.
  20. */
  21. messaging.publicLivechatGlobal.chatbot.update({ isWebsiteLivechatTourFlow: true });
  22. },
  23. }, {
  24. trigger: messagesContain("I help lost visitors find their way."),
  25. run: () => {} // check second welcome message is posted
  26. }, {
  27. trigger: messagesContain("How can I help you?"),
  28. run: () => {} // check question_selection message is posted
  29. }, {
  30. trigger: '.o_livechat_chatbot_options li:contains("I want to buy the software")',
  31. run: 'click'
  32. }, {
  33. trigger: messagesContain("I want to buy the software"),
  34. run: () => {} // check selected option is posted
  35. }, {
  36. trigger: messagesContain("Can you give us your email please?"),
  37. run: () => {} // check ask email step following selecting option A
  38. }, {
  39. trigger: "input.o_composer_text_field",
  40. run: "text No, you won't get my email!"
  41. }, {
  42. trigger: "input.o_composer_text_field",
  43. run: () => {
  44. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  45. }
  46. }, {
  47. trigger: messagesContain("'No, you won't get my email!' does not look like a valid email. Can you please try again?"),
  48. run: () => {} // check invalid email detected and the bot asks for a retry
  49. }, {
  50. trigger: "input.o_composer_text_field",
  51. run: "text okfine@fakeemail.com"
  52. }, {
  53. trigger: "input.o_composer_text_field",
  54. run: () => {
  55. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  56. }
  57. }, {
  58. trigger: messagesContain("Your email is validated, thank you!"),
  59. run: () => {} // check that this time the email goes through and we proceed to next step
  60. }, {
  61. trigger: messagesContain("Would you mind providing your website address?"),
  62. run: () => {} // should ask for website now
  63. }, {
  64. trigger: "input.o_composer_text_field",
  65. run: "text https://www.fakeaddress.com"
  66. }, {
  67. trigger: "input.o_composer_text_field",
  68. run: () => {
  69. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  70. }
  71. }, {
  72. trigger: messagesContain("Great, do you want to leave any feedback for us to improve?"),
  73. run: () => {} // should ask for feedback now
  74. }, {
  75. trigger: "input.o_composer_text_field",
  76. run: "text Yes, actually, I'm glad you asked!"
  77. }, {
  78. trigger: "input.o_composer_text_field",
  79. run: () => {
  80. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  81. }
  82. }, {
  83. trigger: "input.o_composer_text_field",
  84. run: "text I think it's outrageous that you ask for all my personal information!"
  85. }, {
  86. trigger: "input.o_composer_text_field",
  87. run: () => {
  88. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  89. }
  90. }, {
  91. trigger: "input.o_composer_text_field",
  92. run: "text I will be sure to take this to your manager!"
  93. }, {
  94. trigger: "input.o_composer_text_field",
  95. run: () => {
  96. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  97. }
  98. }, {
  99. trigger: messagesContain("Ok bye!"),
  100. run: () => {} // last step is displayed
  101. }, {
  102. trigger: '.o_livechat_chatbot_restart',
  103. run: 'click'
  104. }, {
  105. trigger: messagesContain("Restarting conversation..."),
  106. run: () => {} // check that conversation is properly restarting
  107. }, {
  108. trigger: messagesContain("Hello! I'm a bot!"),
  109. run: () => {} // check first welcome message is posted
  110. }, {
  111. trigger: messagesContain("I help lost visitors find their way."),
  112. run: () => {} // check second welcome message is posted
  113. }, {
  114. trigger: messagesContain("How can I help you?"),
  115. run: () => {} // check question_selection message is posted
  116. }, {
  117. trigger: '.o_livechat_chatbot_options li:contains("Pricing Question")',
  118. run: 'click'
  119. }, {
  120. trigger: messagesContain("For any pricing question, feel free ton contact us at pricing@mycompany.com"),
  121. run: () => {} // the path should now go towards 'Pricing Question (first part)'
  122. }, {
  123. trigger: messagesContain("We will reach back to you as soon as we can!"),
  124. run: () => {} // the path should now go towards 'Pricing Question (second part)'
  125. }, {
  126. trigger: messagesContain("Would you mind providing your website address?"),
  127. run: () => {} // should ask for website now
  128. }, {
  129. trigger: "input.o_composer_text_field",
  130. run: "text no"
  131. }, {
  132. trigger: "input.o_composer_text_field",
  133. run: () => {
  134. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  135. }
  136. }, {
  137. trigger: messagesContain("Great, do you want to leave any feedback for us to improve?"),
  138. run: () => {} // should ask for feedback now
  139. }, {
  140. trigger: "input.o_composer_text_field",
  141. run: "text no, nothing so say"
  142. }, {
  143. trigger: "input.o_composer_text_field",
  144. run: () => {
  145. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  146. }
  147. }, {
  148. trigger: messagesContain("Ok bye!"),
  149. }, {
  150. // wait for chatbot script to finish.
  151. trigger: '.o_livechat_chatbot_restart',
  152. }
  153. ]);