Embedding the Web Messaging widget in a native Pega Platform application
Provide another way for customers to interact with your Pega Platform application by embedding the Web Messaging widget in the application's existing harness or a new section. As a result, customers can more efficiently ask for help, find information, or report an issue, by using a Digital Messaging chat window in your application.
When you embed the Web Messaging widget in your application, you use the same JavaScript function that is defined Installation tab of Digital Messaging Manager.
There are two ways to embed the Web Messaging widget in your application.
- Edit a harness and embed the widget:
- Switch to Dev Studio.
- Open the application that contains the harness where you want to add a
Web Messaging widget, and then edit the harness
rule.For more information, see Harnesses.
- In the harness rule, click the Scripts & styles tab.
- in the Scripts section, click Add a row.
- In the new row, in the Name column, enter
webWidgetInstallation, and then click
Edit.
Result: The following figure shows the pyCaseManager7 harness rule with a new JavaScript text file named
webWidgetInstallation
:Harness rule with defined JavaScript text files - Click Create and open.
- In the webWidgetInstallation text file rule, on
the Main tab, in the text area, enter the
JavaScript code from the example below to insert the Web Messaging widget.
For example: Enter the following JavaScript code: (function(){ var script = document.createElement("script"); script.type = "text/javascript"; script.src = "{Insert your installation function here}" script.async = true; var firstScript = document.getElementsByTagName("script")[0]; firstScript.parentNode,insertBefore(script, firstScript); })();
- In the JavaScript code, replace the value for
script.src
with the JavaScript function value in thesrc
attribute obtained from the Installation tab of your Web Messaging channel in Digital Messaging Manager.For example: The following figure shows the Installation tab of Digital Messaging Manager where you obtain the JavaScript function in the
src
attribute to replace in thescript.src
value for the JavaScript code from previous step.The JavaScript function for the Web Messaging widget Result: The following figure shows the webWidgetInstallation text file rule with the JavaScript code needed to embed the Web Messaging widget:
Text file rule with JavaScript code - Click Save.
- In the harness rule, click Save as, and then create a copy of the harness rule in your application ruleset.
- Switch back to App Studio.
- Create a section and embed the widget:
- Switch to Dev Studio.
- In the application where you want to add the Web Messaging widget, create a section rule.For more information, see Creating sections.
For example: Create a new section rule named webWidgetInstall. - In the section rule, click convert to full screen editor, and then in the Confirm section conversion dialog box, click Submit.
- Click the HTML tab.
- Clear the Auto-generated HTML checkbox.
- In the HTML source field, enter a script tag
from the example below to link to the Web Messaging
widget, replacing the
src
attribute value with the JavaScript function obtained from thesrc
attribute value from the Installation tab in Digital Messaging Manager.For example: Enter the following HTML code: <script id="pega-wm-chat" src="https://widget.use1dev.chat.pega.digital/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/widget.js"> </script>
Result: The following figure shows the webWidgetInstallation section rule with a script tag defined that calls the Web Messaging widget from Digital Messaging Manager:
Section rule with HTML source code - Click Save.
- Switch back to App Studio.
For example: The following video demonstrates how to embed the Web Messaging widget in a new section for a native Pega Platform application:
Include the Web Messaging widget in a harness
Include the Web Messaging widget in a section
Previous topic Adjusting the Web Messaging widget appearance Next topic Enabling virus scanning for Web Messaging