bnbot-widgets
Table of contents
Production usage
Native usage
To use widgets you need to include widgets.bundle.js script from @agiliumlabs/bnbot-widgets/bundle
at the end of body.
Typescript usage
You can import widgets classes from module directly
;;;
NOTE: Typescript widget classes has no styles. You need to import them to your project manually
;
Typings
Module has typescript typings that can be imported in any typescript project
;;;
See all available exported typings in @agiliumlabs/bnbot-widgets/index.d.ts
Mocks
Module has mock instances that can be imported in any project
;;;
See all available exported mocks in @agiliumlabs/bnbot-widgets/index.d.ts
Widget params usage
You have three ways to set widget params
- through data-attributes
- through javascript params
- combined by using both data-attributes and javascript params (javascript params has higher priority and overrides params from data-attributes)
Statistics widget container bellow Feedback widget container bellow Training widget
Statistics widget params
- data-token - current session token
- data-user-id - current user id to match statistics for
- data-host-id - [optional] current host id to match statistics for (return for all hosts if empty)
- data-apartment-id - [optional] current apartment id to match statistics for (return for all apartments if empty)
- data-url-type - [optional] url type for train link (default - relative, available - staging | production)
- data-link-text - [optional] text for train link (default - Train/test bot)
- data-start-time - [optional] start time range to match statistics for (default - 3 month ago)
- data-end-time - [optional] end time range to match statistics for (default - now) NOTE: if you set time range manually - you need to update them on each widget reload. Otherwise you can lost newest (created after your initial time range) statistics info. Default values are dynamical and handle this case
You can use statistics widget with following optional params combinations
- just with user-id
- with user-id and host-id
- with user-id and host-id and apartment-id
Feedback widget params
- data-firebase-token - current token for firebase
- data-user-id - current user id to match statistics for
- data-dialog-id - current dialog id to leave feedback for
Training widget params
- data-token - current authorisation token
- data-host-id - current host id training for
- data-listing-id - current listing id to training for
- data-link-text - [optional] text to replace default train bot link text
- data-url-type - [optional] allowed values are production/staging/relative, default value is relative
Statistics widget dynamic methods
Statistics and feedback widgets are bound together if located on same page. When user add new feedback - statistics will be automatically reload. Technically all statistics widget instances saved in window object and feedback widget call reload method for all saved statistics instances
;
Then all available dynamic methods will be available in variable. Available methods are
- reload - will recreate new statistics widget instance with custom options
- update - will update current statistics widget instance with new options
Feedback UAT tests usage
You can wait figure out current feedback widget state by additional css class on DOM element widget container
- is-widget-loading-in-progress - widget is loading for now (some async actions is running in background)
- is-widget-loading-complete - widget is fully loaded for now (all async actions is complete)
Widgets theme customisation
- All widgets will be added to your page html tag container by tag selector. You need to customise element container by yourself with desired css rules. Widgets wrapper container is fluent and adjust to size of your container. All css rules are defined with single class selector without important flag and can be simply redefined. You can see common class names for widgets theme customisation in bellow sections
Feedback widget customisation sample
.al-feedback-widget
Statistics widget customisation sample
.al-statistics-widget
Training widget customisation sample
.al-training-widget
Development usage
Launch dev server
npm start
Launch unit tests
npm testnpm run twnpm test some-file.servicenpm run tw some-file.component
Check for code style
npm run csnpm run cs:fix
Check for code documentation coverage
npm run doc:createnpm run doc:checknpm run doc:serve
Build all widgets for native usage
npm run build-all:prod
Build just statistics widget for native usage
npm run build-statistics:prod
Build just feedback widget for native usage
npm run build-feedback:prod
When build is complete you will see main.bundle.js and main.bundle.js.gz in dist folder. To use widget you need to include following code to your site
Build whole module (typescript and native usage, styles, mocks and additional info)
npm run compile:prod
When script completed you will see dist folder with compiled module and can publish it to npm
npm publish dist