PageSourceSearch

https://jendela.my/core/assets/f0b9b0d44e/js/chatbot-settings.js?v=1.1

js jendela.my collected 2026-10-01 23:49:36 UTC 9,901 bytes, 255 lines download raw bytes

1'use strict';
2// Chatbot-Settings
3// Set client auth mode - true to enable client auth, false to disable it
4var isClientAuthEnabled = false;
5
6/**
7 * Initializes the SDK and sets a global field with passed name for it the can
8 * be referred later
9 *
10 * @param {string} name Name by which the chat widget should be referred
11 */
12function initSdk(name) {
13    if (!name) {
14        name = 'Bots';          // Set default reference name to 'Bots'
15    }
16    var Bots;
17    // Retry initialization later if WebSDK is not available yet
18    if (!document || !document.body || !WebSDK) {
19		setTimeout(function () {
20		  initSdk(name);
21		}, 500);
22		return;
23	  }
24
25
26    setTimeout(function() {
27        /**
28         * SDK configuration settings
29         * Other than URI, all fields are optional with two exceptions for auth modes
30         * In client auth disabled mode, 'channelId' must be passed, 'userId' is optional
31         * In client auth enabled mode, 'clientAuthEnabled: true' must be passed
32         */
33        var chatWidgetSettings = {
34            URI: 'oda-cc349a5835f648f29beb26102b9523fb-da2.data.digitalassistant.oci.oraclecloud.com',                    // ODA URI, only the hostname part should be passed, without the https://
35            clientAuthEnabled: isClientAuthEnabled,     // Enables client auth enabled mode of connection if set true
36            channelId: 'fda098f6-6196-46f6-968d-74a6a65a3ab5',  //  fda098f6-6196-46f6-968d-74a6a65a3ab5 Channel ID, available in channel settings in ODA UI
37            // userId: '<userID>',                      // User ID, optional field to personalize user experience
38            enableAutocomplete: true,                   // Enables autocomplete suggestions on user input
39			enableAttachment: false,					// Enables attachment
40           // enableBotAudioResponse: true,               // Enables audio utterance of skill responses
41            enableClearMessage: true,                   // Enables display of button to clear conversation
42            enableSpeech: true,                         // Enables voice recognition
43            speechLocale: WebSDK.SPEECH_LOCALE.EN_US,   // Sets locale used to speak to the skill, the SDK supports EN_US, FR_FR, and ES_ES locales for speech
44            showConnectionStatus: true,                 // Displays current connection status on the header
45			//openChatOnLoad: true,
46            color: {
47                branding: '#FFFFFF',
48                text: '#000000'
49            },
50			botButtonIcon: '/wp-content/uploads/2021/06/aida-avatar.png',
51
52			logoIcon: "/wp-content/uploads/2021/06/avatar-logo.png",
53			//botIcon: "/wp-content/uploads/2021/06/aida-avatar.png",
54			//personIcon: "/wp-content/uploads/2021/06/aida-avatar.png",
55
56			clearMessageIcon: '/wp-content/uploads/2021/06/eraser.png',
57            i18n: {                                     // Provide translations for the strings used in the widget
58                en: {                                   // en locale, can be configured for any locale
59                    chatTitle: 'AIDA' ,  // Set title at chat header
60                    requestLocationDeniedPermission: "Your location service is disabled. Kindly turn on your location service.",
61                },
62				ms: {                                   // ms locale, can be configured for any locale
63                    chatTitle: 'AIDA'  ,  // Set title at chat header
64                    requestLocationDeniedPermission: "Fungsi lokasi anda tidak diaktifkan. Sila aktifkan fungsi lokasi anda.",
65                }
66            },
67            timestampMode: 'relative',                  // Sets the timestamp mode, relative to current time or default (absolute)
68			closeIcon: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="512px" id="Layer_1" style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve"><path d="M443.6,387.1L312.4,255.4l131.5-130c5.4-5.4,5.4-14.2,0-19.6l-37.4-37.6c-2.6-2.6-6.1-4-9.8-4c-3.7,0-7.2,1.5-9.8,4  L256,197.8L124.9,68.3c-2.6-2.6-6.1-4-9.8-4c-3.7,0-7.2,1.5-9.8,4L68,105.9c-5.4,5.4-5.4,14.2,0,19.6l131.5,130L68.4,387.1  c-2.6,2.6-4.1,6.1-4.1,9.8c0,3.7,1.4,7.2,4.1,9.8l37.4,37.6c2.7,2.7,6.2,4.1,9.8,4.1c3.5,0,7.1-1.3,9.8-4.1L256,313.1l130.7,131.1  c2.7,2.7,6.2,4.1,9.8,4.1c3.5,0,7.1-1.3,9.8-4.1l37.4-37.6c2.6-2.6,4.1-6.1,4.1-9.8C447.7,393.2,446.2,389.7,443.6,387.1z"/></svg>',
69           // theme: WebSDK.THEME.REDWOOD_DARK            // Redwood dark theme. The default is THEME.DEFAULT, while older theme is available as THEME.CLASSIC
70		   // disablePastActions: "none",  //Enable Listing
71			locale: "ms",
72		   // Language options
73		   multiLangChat: {
74				supportedLangs: [
75					{
76					lang: 'en',
77					label: 'EN'
78					},
79					{
80					lang: 'ms',
81					label: 'BM'
82					}
83				],
84				primary: language
85			},
86			colors : {
87				branding: "#000",
88				botText: "#000",
89				actionsBackground: "#5c5c5c",
90				actionsBackgroundHover: "#000",
91				botMessageBackground: "#f1fafa",
92				userMessageBackgound: "#000"
93			}
94        };
95
96        // Initialize SDK
97        if (isClientAuthEnabled) {
98            Bots = new WebSDK(chatWidgetSettings, generateToken);
99        } else {
100            Bots = new WebSDK(chatWidgetSettings);
101        }
102
103
104
105        // Connect to skill when the widget is expanded for the first time
106        var isFirstConnection = true;
107		var isLanguageHandled = false;
108
109        Bots.on(WebSDK.EVENT.WIDGET_OPENED, function() {
110            if (isFirstConnection) {
111                Bots.connect();
112                isFirstConnection = false;
113
114            }
115        });
116
117        var isHandled = false;
118
119
120        Bots.on('chatlanguagechange', function (language) {
121            console.log('The selected chat language is', language);
122			if(!isLanguageHandled) {
123				Bots.sendMessage("Hi", { hidden: true });
124				isLanguageHandled = true;
125			}
126        });
127
128		Bots.on("click:erase", function () {
129			console.log("Conversation history is erased.");
130			Bots.sendMessage({
131			  postback: {
132				variables: {},
133				"system.botId": "7123DE3F-928F-4E02-9770-36F0AC1B28E9",  //7123DE3F-928F-4E02-9770-36F0AC1B28E9
134		
135				action: "Menu",
136				"system.state": "resetAllParams",
137			  },
138			  type: "postback",
139			});
140		});
141
142		Bots.on(WebSDK.EVENT.READY, function () {
143			 console.log("isHandled", isHandled);
144			 if ( !isHandled && Bots.isConnected() && !Bots.getConversationHistory().messagesCount ) {
145					 isHandled = true;
146			 }
147		});
148
149		Bots.on("message", function (message) {
150			let { source, messagePayload } = message;
151			if (source === "BOT") {
152				let { postback } = messagePayload;
153				if (postback) {
154				let { category } = postback;
155				if (category) {
156					
157					  var newWin = window.open(category.portal_url);
158					  if(!newWin || newWin.closed || typeof newWin.closed=='undefined')
159					  {
160						  alert("Please disable the browser pop-up blocker for information display on a new tab.");
161					  }
162				}
163            }
164        }
165
166    });
167		
168		
169		
170		Bots.connect().then(() => {
171		  Bots.setDelegate({
172			beforeDisplay(message) {
173			  console.log("beforeDisplay", message);
174			  return message;
175			},
176			beforeSend(message) {
177			  console.log("beforeSend", message);
178			  return message;
179			},
180			beforePostbackSend(postback) {
181			  let { messagePayload } = postback;
182			  let { variables, chatbotSearchObject } = messagePayload.postback;
183			  if (chatbotSearchObject) {
184				if (chatbotSearchObject.portal_url)
185				  window.open(chatbotSearchObject.portal_url);
186			  }
187			  return postback;
188			},
189		  });
190		});
191		// Apply padding to all four sides
192		Bots.setMessagePadding('15px');
193		// vertical | horizontal
194		Bots.setMessagePadding('5% 10%');
195		// top | horizontal | bottom
196		Bots.setMessagePadding('15em 20em 20em');
197		// top | right | bottom | left
198		Bots.setMessagePadding('15px 20px 20px 15px');
199
200        // Create global object to refer Bots
201        window[name] = Bots;
202    }, 0);
203}
204
205/**
206 * Function to generate JWT tokens. It returns a Promise to provide tokens.
207 * The function is passed to SDK which uses it to fetch token whenever it needs
208 * to establish connections to chat server
209 *
210 * @returns {Promise} Promise to provide a signed JWT token
211 */
212function generateToken() {
213    return new Promise(function(resolve) {
214        mockApiCall('https://mockurl').then(function(token) {
215            resolve(token);
216        });
217    });
218}
219
220/**
221 * A function mocking an endpoint call to backend to provide authentication token
222 * The recommended behaviour is fetching the token from backend server
223 *
224 * @returns {Promise} Promise to provide a signed JWT token
225 */
226function mockApiCall() {
227    return new Promise(function(resolve) {
228        setTimeout(function() {
229            var now = Math.floor(Date.now() / 1000);
230            var payload = {
231                iat: now,
232                exp: now + 3600,
233                channelId: 'fda098f6-6196-46f6-968d-74a6a65a3ab5',
234                userId: '<userID>'
235            };
236            var SECRET = 'umg4iin1vGqhyfRYTZ7Nu8p8Je44qCYa';
237
238            // An unimplemented function generating signed JWT token with given header, payload, and signature
239            var token = generateJWTToken({ alg: 'HS256', typ: 'JWT' }, payload, SECRET);
240            resolve(token);
241        }, Math.floor(Math.random() * 1000) + 1000);
242    });
243}
244
245/**
246 * Unimplemented function to generate signed JWT token. Should be replaced with
247 * actual method to generate the token on the server.
248 *
249 * @param {object} header
250 * @param {object} payload
251 * @param {string} signature
252 */
253function generateJWTToken(header, payload, signature) {
254    throw new Error('Method not implemented.');
255}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.