Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,5 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/
/sabacha/Dispatcher/dispatcher.bot
SharePointSSOComponent/package-lock.json
SharePointSSOComponent/config/serve.json
2 changes: 1 addition & 1 deletion SharePointSSOComponent/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const PVAChatbotDialog: React.FunctionComponent<IChatbotProps> = (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<HTMLDivElement>(null);
const loadingSpinnerRef = useRef<HTMLDivElement>(null);
Expand All @@ -59,15 +64,29 @@ export const PVAChatbotDialog: React.FunctionComponent<IChatbotProps> = (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}`);
Expand Down