@@ -7,6 +7,76 @@ class Feedback {
77 this . #state = state ;
88 }
99
10+ /**
11+ * Shows the first available NPS widget that meets the criteria.
12+ * @param {String } [nameIDorTag] - name, id, or tag of the widget to show (optional)
13+ * @param {callback } [callback] - called when the widget is closed (optional)
14+ */
15+ showNPS ( nameIDorTag , callback ) {
16+ L . i ( `showNPS, Will show NPS widget with name, id, or tag: [${ nameIDorTag } ], callback provided: [${ typeof callback === "function" } ]` ) ;
17+ this . #showInternalFeedback( "nps" , nameIDorTag , callback ) ;
18+ }
19+ /**
20+ * Shows the first available Survey widget that meets the criteria.
21+ * @param {String } [nameIDorTag] - name, id, or tag of the widget to show (optional)
22+ * @param {callback } [callback] - called when the widget is closed (optional)
23+ */
24+ showSurvey ( nameIDorTag , callback ) {
25+ L . i ( `showSurvey, Will show Survey widget with name, id, or tag: [${ nameIDorTag } ], callback provided: [${ typeof callback === "function" } ]` ) ;
26+ this . #showInternalFeedback( "survey" , nameIDorTag , callback ) ;
27+ }
28+
29+ /**
30+ * Shows the first available Rating widget that meets the criteria.
31+ * @param {String } [nameIDorTag] - name, id, or tag of the widget to show (optional)
32+ * @param {callback } [callback] - called when the widget is closed (optional)
33+ */
34+ showRating ( nameIDorTag , callback ) {
35+ L . i ( `showRating, Will show Rating widget with name, id, or tag: [${ nameIDorTag } ], callback provided: [${ typeof callback === "function" } ]` ) ;
36+ this . #showInternalFeedback( "rating" , nameIDorTag , callback ) ;
37+ }
38+
39+ #showInternalFeedback( widgetType , nameIDorTag , callback ) {
40+ if ( ! this . #state. isInitialized ) {
41+ L . e ( `showInternalFeedback, 'init' must be called before 'showInternalFeedback'` ) ;
42+ return ;
43+ }
44+ if ( typeof nameIDorTag !== "string" ) {
45+ L . d ( `showInternalFeedback, unsupported data type of nameIDorTag or its not given : [${ typeof nameIDorTag } ]` ) ;
46+ }
47+ this . getAvailableFeedbackWidgets ( ( retrievedWidgets , error ) => {
48+ if ( error ) {
49+ L . e ( `showInternalFeedback, ${ error } ` ) ;
50+ return ;
51+ }
52+ if ( ! retrievedWidgets || retrievedWidgets . length === 0 ) {
53+ L . d ( `showInternalFeedback, no feedback widgets found` ) ;
54+ return ;
55+ }
56+ L . d ( `showInternalFeedback, Found [${ retrievedWidgets . length } ] feedback widgets` ) ;
57+ let widget = retrievedWidgets . find ( w => w . type === widgetType ) ;
58+ try {
59+ if ( nameIDorTag && typeof nameIDorTag === 'string' ) {
60+ const matchedWidget = retrievedWidgets . find ( w =>
61+ w . type === widgetType && ( w . name === nameIDorTag || w . id === nameIDorTag || w . tags . includes ( nameIDorTag ) )
62+ ) ;
63+ if ( matchedWidget ) {
64+ widget = matchedWidget ;
65+ L . v ( `showInternalFeedback, Found ${ widgetType } widget by name, id, or tag: [${ JSON . stringify ( matchedWidget ) } ]` ) ;
66+ }
67+ }
68+ } catch ( error ) {
69+ L . e ( `showInternalFeedback, Error while finding widget: ${ error } ` ) ;
70+ }
71+
72+ if ( ! widget ) {
73+ L . d ( `showInternalFeedback, No ${ widgetType } widget found.` ) ;
74+ return ;
75+ }
76+ this . presentFeedbackWidget ( widget , null , null , callback ) ;
77+ } ) ;
78+ }
79+
1080 /**
1181 * Get a list of available feedback widgets as an array of objects.
1282 * @param {callback } [onFinished] - returns (retrievedWidgets, error). This parameter is optional.
@@ -19,7 +89,7 @@ class Feedback {
1989 return { error : message , data : null } ;
2090 }
2191
22- L . d ( "getAvailableFeedbackWidgets, getAvailableFeedbackWidgets " ) ;
92+ L . d ( "getAvailableFeedbackWidgets, fetching available feedback widgets " ) ;
2393 let result = null ;
2494 let error = null ;
2595 try {
0 commit comments