diff --git a/.gitignore b/.gitignore index eccf4924..27059e02 100644 --- a/.gitignore +++ b/.gitignore @@ -329,3 +329,5 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ /sabacha/Dispatcher/dispatcher.bot +SharePointSSOComponent/package-lock.json +SharePointSSOComponent/config/serve.json diff --git a/SharePointSSOComponent/README.md b/SharePointSSOComponent/README.md index 4e20566c..d2a8d1a2 100644 --- a/SharePointSSOComponent/README.md +++ b/SharePointSSOComponent/README.md @@ -1,6 +1,6 @@ # SharePoint SSO Component -This code sample that demonstrates how to create a SharePoint SPFx component which is a wrapper for a copilot, created with Microsoft Copilot Studio. The SPFx component included in the sample supports SSO, providing seamless user authentication for users interacting with the copilot. +This code sample demonstrates how to create a SharePoint SPFx component which is a wrapper for a copilot, created with Microsoft Copilot Studio. The SPFx component included in the sample supports SSO, providing seamless authentication for users interacting with the copilot. ## Getting Started diff --git a/SharePointSSOComponent/src/extensions/pvaSso/components/ChatBot.tsx b/SharePointSSOComponent/src/extensions/pvaSso/components/ChatBot.tsx index 38ae6a5b..a79d4070 100644 --- a/SharePointSSOComponent/src/extensions/pvaSso/components/ChatBot.tsx +++ b/SharePointSSOComponent/src/extensions/pvaSso/components/ChatBot.tsx @@ -33,6 +33,11 @@ export const PVAChatbotDialog: React.FunctionComponent = (props) // Your bot's token endpoint const botURL = props.botURL; + // constructing URL using regional settings + const environmentEndPoint = botURL.slice(0,botURL.indexOf('/powervirtualagents')); + const apiVersion = botURL.slice(botURL.indexOf('api-version')).split('=')[1]; + const regionalChannelSettingsURL = `${environmentEndPoint}/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`; + // Using refs instead of IDs to get the webchat and loading spinner elements const webChatRef = useRef(null); const loadingSpinnerRef = useRef(null); @@ -59,15 +64,29 @@ export const PVAChatbotDialog: React.FunctionComponent = (props) const token = responseToken?.accessToken || null; - // Create DirectLine object - const response = await fetch(botURL); + // Get the regional channel URL + let regionalChannelURL; + + const regionalResponse = await fetch(regionalChannelSettingsURL); + if(regionalResponse.ok){ + const data = await regionalResponse.json(); + regionalChannelURL = data.channelUrlsById.directline; + } + else { + console.error(`HTTP error! Status: ${regionalResponse.status}`); + } + + // Create DirectLine object let directline: any; + const response = await fetch(botURL); + if (response.ok) { const conversationInfo = await response.json(); directline = ReactWebChat.createDirectLine({ token: conversationInfo.token, + domain: regionalChannelURL + 'v3/directline', }); } else { console.error(`HTTP error! Status: ${response.status}`);